Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query constraints using ordered dimensions #1549

Merged
merged 4 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
wip
  • Loading branch information
rfecher committed May 1, 2019
commit 587eaade59970b23961ef2b9834160f74776da1b
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,27 @@ public static class OrderedConstraints implements Constraints {

public OrderedConstraints() {}

public OrderedConstraints(final Range<Double> rangePerDimension) {
this(new Range[] {rangePerDimension}, null);
}

public OrderedConstraints(final Range<Double>[] rangesPerDimension) {
this(rangesPerDimension, null);
}

public OrderedConstraints(final Range<Double>[] rangesPerDimension, final String indexName) {
this.rangesPerDimension = rangesPerDimension;
this.indexName = indexName;
}

@Override
public byte[] toBinary() {
final byte[] indexNameBinary = StringUtils.stringToBinary(indexName);

final byte[] indexNameBinary;
if (indexName != null) {
indexNameBinary = StringUtils.stringToBinary(indexName);
} else {
indexNameBinary = new byte[0];
}
final ByteBuffer buf =
ByteBuffer.allocate(
VarintUtils.unsignedIntByteLength(rangesPerDimension.length)
Expand All @@ -58,17 +70,21 @@ public void fromBinary(final byte[] bytes) {
for (int i = 0; i < rangesPerDimension.length; i++) {
rangesPerDimension[i] = Range.between(buf.getDouble(), buf.getDouble());
}
buf.get(indexNameBinary);
indexName = StringUtils.stringFromBinary(indexNameBinary);
if (indexNameBinary.length > 0) {
buf.get(indexNameBinary);
indexName = StringUtils.stringFromBinary(indexNameBinary);
} else {
indexName = null;
}
}

@Override
public List<MultiDimensionalNumericData> getIndexConstraints(final Index index) {
if (indexName.equals(index.getName())
if (((indexName == null) || indexName.equals(index.getName()))
&& (index.getIndexStrategy().getOrderedDimensionDefinitions().length == rangesPerDimension.length)) {
return Collections.singletonList(getIndexConstraints());
}
return Collections.EMPTY_LIST;
return Collections.emptyList();
}

protected MultiDimensionalNumericData getIndexConstraints() {
Expand All @@ -80,12 +96,16 @@ protected MultiDimensionalNumericData getIndexConstraints() {

@Override
public List<QueryFilter> createFilters(final Index index, final BasicQuery parentQuery) {
return Collections.singletonList(
final QueryFilter filter =
parentQuery.createQueryFilter(
getIndexConstraints(),
index.getIndexModel().getDimensions(),
new NumericDimensionField[0],
index));
index);
if (filter != null) {
return Collections.singletonList(filter);
}
return Collections.emptyList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package org.locationtech.geowave.core.store.query.constraints;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.Range;
import org.locationtech.geowave.core.index.dimension.BasicDimensionDefinition;
import org.locationtech.geowave.core.index.sfc.data.MultiDimensionalNumericData;
import org.locationtech.geowave.core.index.sfc.data.NumericRange;
import org.locationtech.geowave.core.store.api.Index;
import org.locationtech.geowave.core.store.dimension.NumericDimensionField;
import org.locationtech.geowave.core.store.query.filter.QueryFilter;

public class SimpleNumericQuery extends BasicQueryByClass {
public class SimpleNumericQuery extends BasicOrderedConstraintQuery {
public SimpleNumericQuery(final Range<Double> range) {
super(createNumericConstraints(range));
super(new OrderedConstraints(range));
}

public SimpleNumericQuery() {
Expand All @@ -29,13 +25,4 @@ protected QueryFilter createQueryFilter(
// index, we don't need fine-grained filtering for simple numeric queries
return null;
}

private static ConstraintsByClass createNumericConstraints(final Range<Double> range) {
final List<ConstraintSet> constraints = new ArrayList<>();
constraints.add(
new ConstraintSet(
BasicDimensionDefinition.class,
new ConstraintData(new NumericRange(range.getMinimum(), range.getMaximum()), false)));
return new ConstraintsByClass(constraints);
}
}