use of com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithChild in project fdb-record-layer by FoundationDB.
the class GeophileIndexMaintainer method getSpatialFunction.
// If the bottom-right child is GeophileSpatialFunctionKeyExpression, return it. Else error.
@Nonnull
static GeophileSpatialFunctionKeyExpression getSpatialFunction(@Nonnull Index index) {
KeyExpression rootKey = index.getRootExpression();
if (rootKey instanceof KeyWithValueExpression) {
rootKey = ((KeyWithValueExpression) rootKey).getKeyExpression();
}
final List<KeyExpression> components = rootKey.normalizeKeyForPositions();
final KeyExpression rightComponent = components.get(components.size() - 1);
KeyExpression bottomComponent = rightComponent;
while (true) {
if (bottomComponent instanceof GeophileSpatialFunctionKeyExpression) {
return (GeophileSpatialFunctionKeyExpression) bottomComponent;
}
if (bottomComponent instanceof KeyExpressionWithChild) {
bottomComponent = ((KeyExpressionWithChild) bottomComponent).getChild();
continue;
}
throw new KeyExpression.InvalidExpressionException(String.format("need spatial key expression for %s index", index.getType()), LogMessageKeys.INDEX_NAME, index.getName(), LogMessageKeys.INDEX_KEY, index.getRootExpression());
}
}
Aggregations