use of org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldConstraints in project geowave by locationtech.
the class FilterConstraints method getIndexData.
/**
* Get the multi-dimensional index data from these constraints.
*
* @return the multi-dimensional index data
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<MultiDimensionalIndexData<V>> getIndexData() {
if (cachedIndexData == null) {
if ((adapter == null) || (index == null) || (indexMapping == null)) {
return Lists.newArrayList();
}
if (index instanceof CustomIndex) {
final TextIndexStrategy indexStrategy = (TextIndexStrategy) ((CustomIndex) index).getCustomIndexStrategy();
if (!(indexStrategy.getEntryConverter() instanceof AdapterFieldTextIndexEntryConverter)) {
throw new RuntimeException("Unable to determine adapter field used by text index.");
}
final String fieldName = ((AdapterFieldTextIndexEntryConverter) indexStrategy.getEntryConverter()).getFieldName();
final IndexFieldConstraints<?> fieldConstraint = fieldConstraints.get(fieldName);
final List<DimensionConstraints<String>> dimensionConstraints = Lists.newArrayList();
if (fieldConstraint == null) {
dimensionConstraints.add(DimensionConstraints.of(Lists.newArrayList(FilterRange.of((String) null, (String) null, true, true, true))));
} else if (fieldConstraint instanceof TextFieldConstraints) {
final DimensionConstraints<String> dimensionConstraint = ((TextFieldConstraints) fieldConstraint).getDimensionRanges(0);
if (dimensionConstraint == null) {
dimensionConstraints.add(DimensionConstraints.of(Lists.newArrayList(FilterRange.of((String) null, (String) null, true, true, true))));
} else {
dimensionConstraints.add(dimensionConstraint);
}
} else {
throw new RuntimeException("Non-text field constraints cannot be used for a text index.");
}
cachedIndexData = (List) TextFieldConstraints.toIndexData(dimensionConstraints);
} else {
// Right now all index strategies that aren't custom are numeric
final CommonIndexModel indexModel = index.getIndexModel();
final int numStrategyDimensions = index.getIndexStrategy().getOrderedDimensionDefinitions().length;
final List<DimensionConstraints<Double>> dimensionConstraints = Lists.newArrayListWithCapacity(numStrategyDimensions);
final Map<String, Integer> indexFieldDimensions = Maps.newHashMap();
final NumericDimensionField<?>[] dimensions = indexModel.getDimensions();
int dimensionIndex = 0;
for (final NumericDimensionField<?> indexField : dimensions) {
if (dimensionIndex >= numStrategyDimensions) {
// Only build constraints for dimensions used by the index strategy.
break;
}
dimensionIndex++;
final String indexFieldName = indexField.getFieldName();
if (!indexFieldDimensions.containsKey(indexFieldName)) {
indexFieldDimensions.put(indexFieldName, 0);
}
final int indexFieldDimension = indexFieldDimensions.get(indexFieldName);
final IndexFieldMapper<?, ?> mapper = indexMapping.getMapperForIndexField(indexFieldName);
final String[] adapterFields = mapper.getIndexOrderedAdapterFields();
IndexFieldConstraints<?> fieldConstraint = null;
if (adapterFields.length > 1 && isSingleDimension(indexFieldName, dimensions)) {
// constraints
for (int i = 0; i < adapterFields.length; i++) {
final IndexFieldConstraints<?> constraint = fieldConstraints.get(adapterFields[i]);
if (fieldConstraint == null) {
fieldConstraint = constraint;
} else {
fieldConstraint.and((IndexFieldConstraints) constraint);
}
}
} else {
fieldConstraint = fieldConstraints.get(adapterFields[indexFieldDimension % adapterFields.length]);
}
if (fieldConstraint == null) {
dimensionConstraints.add(DimensionConstraints.of(Lists.newArrayList(FilterRange.of((Double) null, (Double) null, true, true, true))));
} else if (fieldConstraint instanceof NumericFieldConstraints) {
final DimensionConstraints<Double> dimensionConstraint = ((NumericFieldConstraints) fieldConstraint).getDimensionRanges(indexFieldDimension % fieldConstraint.getDimensionCount());
if (dimensionConstraint == null) {
dimensionConstraints.add(DimensionConstraints.of(Lists.newArrayList(FilterRange.of((Double) null, (Double) null, true, true, true))));
} else {
dimensionConstraints.add(dimensionConstraint);
}
indexFieldDimensions.put(indexFieldName, indexFieldDimension + 1);
} else {
throw new RuntimeException("Non-numeric field constraints cannot be used for a numeric index.");
}
}
cachedIndexData = (List) NumericFieldConstraints.toIndexData(dimensionConstraints);
}
}
return cachedIndexData;
}
Aggregations