Search in sources :

Example 1 with KeyExpressionWithChild

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());
    }
}
Also used : KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) KeyExpressionWithChild(com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithChild) KeyWithValueExpression(com.apple.foundationdb.record.metadata.expressions.KeyWithValueExpression) Nonnull(javax.annotation.Nonnull)

Aggregations

KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)1 KeyExpressionWithChild (com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithChild)1 KeyWithValueExpression (com.apple.foundationdb.record.metadata.expressions.KeyWithValueExpression)1 Nonnull (javax.annotation.Nonnull)1