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 plan with IN as Union fails to display plan graph in CloudKit console #2660

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()),
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public List<? extends InSource> 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")
Expand Down Expand Up @@ -205,7 +205,7 @@ public Set<CorrelationIdentifier> 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())))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only this one is using the new identifier

.collect(ImmutableSet.toImmutableSet());
inner.getCorrelatedTo()
.stream()
Expand Down