diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/Bindings.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/Bindings.java index 1731f43eb8..9897d9a326 100644 --- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/Bindings.java +++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/Bindings.java @@ -70,11 +70,27 @@ public String bindingName(@Nonnull String suffix) { return value + suffix; } - public String identifier(@Nonnull String bindingName) { + public String typedIdentifier(@Nonnull final String bindingName) { Verify.verify(bindingName.startsWith(value)); return bindingName.substring(value.length()); } + public static String identifier(@Nonnull final String bindingName) { + Internal internalType = resolveType(bindingName); + Verify.verify(internalType != null); + return bindingName.substring(internalType.value.length()); + } + + @Nullable + private static Internal resolveType(@Nonnull String name) { + for (Internal internal: Internal.values()) { + if (name.startsWith(internal.value)) { + return internal; + } + } + return null; + } + @Nonnull @SuppressWarnings("unused") public PBindingKind toProto(@Nonnull final PlanSerializationContext serializationContext) { diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/expressions/Comparisons.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/expressions/Comparisons.java index 947a6520db..0205282a7f 100644 --- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/expressions/Comparisons.java +++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/expressions/Comparisons.java @@ -1161,7 +1161,7 @@ public boolean isCorrelatedTo(@Nonnull final CorrelationIdentifier alias) { if (!isCorrelation()) { return false; } - return Bindings.Internal.CORRELATION.identifier(getParameter()).equals(alias.getId()); + return Bindings.Internal.CORRELATION.typedIdentifier(getParameter()).equals(alias.getId()); } @Nullable @@ -1182,7 +1182,7 @@ public Object getComparand(@Nullable FDBRecordStoreBase store, @Nullable Eval public Comparison translateCorrelations(@Nonnull final TranslationMap translationMap) { if (isCorrelation()) { final var aliasMap = translationMap.getAliasMapMaybe().orElseThrow(() -> new RecordCoreException("must have aliasMap")); - final var alias = CorrelationIdentifier.of(Bindings.Internal.CORRELATION.identifier(parameter)); + final var alias = CorrelationIdentifier.of(Bindings.Internal.CORRELATION.typedIdentifier(parameter)); final var translatedAlias = aliasMap.getTargetOrDefault(alias, alias); return new ParameterComparison(type, Bindings.Internal.CORRELATION.bindingName(translatedAlias.getId()), @@ -1269,7 +1269,7 @@ public CorrelationIdentifier getAlias() { if (!isCorrelation()) { throw new IllegalStateException("caller should check for type of binding before calling this method"); } - return CorrelationIdentifier.of(Bindings.Internal.CORRELATION.identifier(parameter)); + return CorrelationIdentifier.of(Bindings.Internal.CORRELATION.typedIdentifier(parameter)); } @Override @@ -1278,7 +1278,7 @@ public CorrelationIdentifier getAlias() { public boolean equals(Object o) { final AliasMap aliasMap; if (isCorrelation()) { - final var alias = CorrelationIdentifier.of(Bindings.Internal.CORRELATION.identifier(parameter)); + final var alias = CorrelationIdentifier.of(Bindings.Internal.CORRELATION.typedIdentifier(parameter)); aliasMap = AliasMap.identitiesFor(ImmutableSet.of(alias)); } else { aliasMap = AliasMap.emptyMap(); diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/CascadesCostModel.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/CascadesCostModel.java index 64d28a78da..576dbbcaf1 100644 --- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/CascadesCostModel.java +++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/CascadesCostModel.java @@ -368,14 +368,14 @@ private OptionalInt compareInOperator(@Nonnull final RelationalExpression leftEx if (leftExpression instanceof RecordQueryInJoinPlan) { final var inJoinPlan = (RecordQueryInJoinPlan)leftExpression; final var inSource = inJoinPlan.getInSource(); - if (!scanComparisonsCorrelatedTo.contains(CorrelationIdentifier.of(CORRELATION.identifier(inSource.getBindingName())))) { + if (!scanComparisonsCorrelatedTo.contains(CorrelationIdentifier.of(CORRELATION.typedIdentifier(inSource.getBindingName())))) { return OptionalInt.of(1); } } else if (leftExpression instanceof RecordQueryInUnionPlan) { final var inUnionPlan = (RecordQueryInUnionPlan)leftExpression; if (inUnionPlan.getInSources() .stream() - .noneMatch(inValuesSource -> scanComparisonsCorrelatedTo.contains(CorrelationIdentifier.of(CORRELATION.identifier(inValuesSource.getBindingName()))))) { + .noneMatch(inValuesSource -> scanComparisonsCorrelatedTo.contains(CorrelationIdentifier.of(CORRELATION.typedIdentifier(inValuesSource.getBindingName()))))) { return OptionalInt.of(1); } } diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/properties/OrderingProperty.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/properties/OrderingProperty.java index 2106ed7ce4..153316af50 100644 --- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/properties/OrderingProperty.java +++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/properties/OrderingProperty.java @@ -530,7 +530,7 @@ public Ordering visitInUnionOnValuesPlan(@Nonnull final RecordQueryInUnionOnValu final var sourceAliases = inUnionOnValuePlan.getInSources() .stream() - .map(inSource -> CorrelationIdentifier.of(CORRELATION.identifier(inSource.getBindingName()))) + .map(inSource -> CorrelationIdentifier.of(CORRELATION.typedIdentifier(inSource.getBindingName()))) .collect(ImmutableSet.toImmutableSet()); for (final var entry : equalityBoundValueMap.entries()) { diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInJoinPlan.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInJoinPlan.java index dfaa9c7242..55402fdc09 100644 --- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInJoinPlan.java +++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInJoinPlan.java @@ -100,7 +100,7 @@ public InSource getInSource() { @Nonnull public CorrelationIdentifier getInAlias() { - return CorrelationIdentifier.of(internal.identifier(inSource.getBindingName())); + return CorrelationIdentifier.of(internal.typedIdentifier(inSource.getBindingName())); } @Nonnull diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInUnionPlan.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInUnionPlan.java index 99cbfdad8a..80198b8e1e 100644 --- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInUnionPlan.java +++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryInUnionPlan.java @@ -134,7 +134,7 @@ public List getInSources() { @Nonnull public CorrelationIdentifier getInAlias(@Nonnull final InSource inSource) { - return CorrelationIdentifier.of(internal.identifier(inSource.getBindingName())); + return CorrelationIdentifier.of(internal.typedIdentifier(inSource.getBindingName())); } @SuppressWarnings("resource") @@ -205,7 +205,7 @@ public Set getCorrelatedTo() { final var inAliases = getInSources() .stream() - .map(inSource -> CorrelationIdentifier.of(Bindings.Internal.CORRELATION.identifier(inSource.getBindingName()))) + .map(inSource -> CorrelationIdentifier.of(Bindings.Internal.identifier(inSource.getBindingName()))) .collect(ImmutableSet.toImmutableSet()); inner.getCorrelatedTo() .stream()