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

Temporary tables #2962

Merged
merged 18 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
2 changes: 1 addition & 1 deletion docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Starting with version [3.4.455.0](#344550), the semantics of `UnnestedRecordType
* **Performance** Improvement 4 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
* **Performance** Improvement 5 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
* **Feature** Add more lucene exception handling tests [(Issue #2939)](https://github.com/FoundationDB/fdb-record-layer/issues/2939)
* **Feature** Feature 2 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
* **Feature** Support temporary table planning and execution [(Issue #2962)](https://github.com/FoundationDB/fdb-record-layer/pull/2962)
* **Feature** Feature 3 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
* **Feature** Feature 4 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
* **Feature** Feature 5 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Bindings {
/**
* Bindings slots used internally by plan operators.
*/
public enum Internal {
public enum BindingKind {
IN("__in_"),
RANK("__rank_"),
CORRELATION("__corr_"),
Expand All @@ -54,7 +54,7 @@ public enum Internal {
private final String value;


Internal(String value) {
BindingKind(String value) {
this.value = value;
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public PBindingKind toProto(@Nonnull final PlanSerializationContext serializatio

@Nonnull
@SuppressWarnings("unused")
public static Internal fromProto(@Nonnull final PlanSerializationContext serializationContext, @Nonnull final PBindingKind bindingKindProto) {
public static BindingKind fromProto(@Nonnull final PlanSerializationContext serializationContext, @Nonnull final PBindingKind bindingKindProto) {
switch (bindingKindProto) {
case IN:
return IN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ public Object getBinding(@Nonnull String name) {
/**
* Get the value bound to a single parameter.
*
* @param type the type of the parameter
* @param alias the correlation identifier
*
* @return the value bound to the given parameter
*/
public Object getBinding(@Nonnull CorrelationIdentifier alias) {
return bindings.get(Bindings.Internal.CORRELATION.bindingName(alias.getId()));
public Object getBinding(@Nonnull Bindings.BindingKind type, @Nonnull CorrelationIdentifier alias) {
return bindings.get(type.bindingName(alias.getId()));
}

/**
Expand All @@ -144,7 +146,7 @@ public Object getBinding(@Nonnull CorrelationIdentifier alias) {
@SuppressWarnings("unchecked")
@Nullable
public Object dereferenceConstant(@Nonnull final CorrelationIdentifier alias, @Nonnull final String constantId) {
final var constantsMap = (Map<String, ?>)bindings.get(Bindings.Internal.CONSTANT.bindingName(alias.getId()));
final var constantsMap = (Map<String, ?>)bindings.get(Bindings.BindingKind.CONSTANT.bindingName(alias.getId()));
if (constantsMap == null) {
throw new RecordCoreException("could not find constant in the evaluation context")
.addLogInfo(LogMessageKeys.KEY, "'" + alias.getId() + "' - '" + constantId + "'");
Expand Down Expand Up @@ -201,11 +203,13 @@ public EvaluationContext withBinding(@Nonnull String bindingName, @Nullable Obje
* context included all bindings except that it will bind an additional
* parameter to an additional value.
*
* @param type the type of the binding.
* @param alias the alias determining the binding name to add
* @param value the value to bind the name to
*
* @return a new <code>EvaluationContext</code> with the new binding
*/
public EvaluationContext withBinding(@Nonnull CorrelationIdentifier alias, @Nullable Object value) {
return childBuilder().setBinding(Bindings.Internal.CORRELATION.bindingName(alias.getId()), value).build(typeRepository);
public EvaluationContext withBinding(final Bindings.BindingKind type, @Nonnull CorrelationIdentifier alias, @Nullable Object value) {
return childBuilder().setBinding(type.bindingName(alias.getId()), value).build(typeRepository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public EvaluationContextBuilder setBinding(@Nonnull String name, @Nullable Objec
* @return this <code>EvaluationContextBuilder</code>
*/
public EvaluationContextBuilder setBinding(@Nonnull CorrelationIdentifier alias, @Nullable Object value) {
return setBinding(Bindings.Internal.CORRELATION.bindingName(alias.getId()), value);
return setBinding(Bindings.BindingKind.CORRELATION.bindingName(alias.getId()), value);
}

public EvaluationContextBuilder setConstant(@Nonnull CorrelationIdentifier alias, @Nullable Object value) {
return setBinding(Bindings.Internal.CONSTANT.bindingName(alias.getId()), value);
return setBinding(Bindings.BindingKind.CONSTANT.bindingName(alias.getId()), value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.apple.foundationdb.record.cursors.aggregate;

import com.apple.foundationdb.record.Bindings;
import com.apple.foundationdb.record.EvaluationContext;
import com.apple.foundationdb.record.RecordCursorResult;
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase;
Expand Down Expand Up @@ -183,13 +184,13 @@ private void finalizeGroup(Object nextGroup) {
}

private void accumulate(@Nullable Object currentObject) {
EvaluationContext nestedContext = context.withBinding(alias, currentObject);
EvaluationContext nestedContext = context.withBinding(Bindings.BindingKind.CORRELATION, alias, currentObject);
final Object partial = aggregateValue.evalToPartial(store, nestedContext);
accumulator.accumulate(partial);
}

private Object evalGroupingKey(@Nullable final Object currentObject) {
final EvaluationContext nestedContext = context.withBinding(alias, currentObject);
final EvaluationContext nestedContext = context.withBinding(Bindings.BindingKind.CORRELATION, alias, currentObject);
return Objects.requireNonNull(groupingKeyValue).eval(store, nestedContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public <M extends Message> boolean shouldIndexThisRecord(@Nonnull FDBRecordStore
CorrelationIdentifier objectQuantifier = Quantifier.current();
QueryPredicate queryPredicate = getQueryPredicate(store.getRecordMetaData(), savedRecord.getRecordType(), objectQuantifier);

String bindingName = Bindings.Internal.CORRELATION.bindingName(objectQuantifier.getId());
String bindingName = Bindings.BindingKind.CORRELATION.bindingName(objectQuantifier.getId());
Bindings bindings = Bindings.newBuilder().set(bindingName, QueryResult.ofComputed(savedRecord.getRecord())).build();

return Boolean.TRUE.equals(queryPredicate.eval(store, EvaluationContext.forBindings(bindings)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,19 +1150,19 @@ public abstract static class ParameterComparisonBase implements ComparisonWithPa
@Nonnull
protected final String parameter;
@Nullable
protected final Bindings.Internal internal;
protected final Bindings.BindingKind bindingKind;
@Nonnull
protected final ParameterRelationshipGraph parameterRelationshipGraph;
@Nonnull
protected final Supplier<Integer> hashCodeSupplier;

protected ParameterComparisonBase(@Nonnull Type type, @Nonnull String parameter,
@Nullable Bindings.Internal internal,
@Nullable Bindings.BindingKind bindingKind,
@Nonnull ParameterRelationshipGraph parameterRelationshipGraph) {
checkInternalBinding(parameter, internal);
checkInternalBinding(parameter, bindingKind);
this.type = type;
this.parameter = parameter;
this.internal = internal;
this.bindingKind = bindingKind;
if (type.isUnary()) {
throw new RecordCoreException("Unary comparison type " + type + " cannot be bound to a parameter");
}
Expand All @@ -1183,15 +1183,15 @@ public Type getType() {
}

public boolean isCorrelation() {
return internal == Bindings.Internal.CORRELATION;
return bindingKind == Bindings.BindingKind.CORRELATION;
}

@Override
public boolean isCorrelatedTo(@Nonnull final CorrelationIdentifier alias) {
if (!isCorrelation()) {
return false;
}
return Bindings.Internal.CORRELATION.identifier(getParameter()).equals(alias.getId());
return Bindings.BindingKind.CORRELATION.identifier(getParameter()).equals(alias.getId());
}

@Nullable
Expand All @@ -1212,7 +1212,7 @@ public Object getComparand(@Nullable FDBRecordStoreBase<?> store, @Nullable Eval
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public Comparison translateCorrelations(@Nonnull final TranslationMap translationMap) {
if (isCorrelation()) {
final var alias = CorrelationIdentifier.of(Bindings.Internal.CORRELATION.identifier(parameter));
final var alias = CorrelationIdentifier.of(Bindings.BindingKind.CORRELATION.identifier(parameter));
final var quantifiedObjectValue = QuantifiedObjectValue.of(alias,
com.apple.foundationdb.record.query.plan.cascades.typing.Type.any());

Expand Down Expand Up @@ -1309,7 +1309,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.BindingKind.CORRELATION.identifier(parameter));
}

@Override
Expand Down Expand Up @@ -1359,10 +1359,10 @@ public int queryHash(@Nonnull final QueryHashKind hashKind) {
}

@Nonnull
private static String checkInternalBinding(@Nonnull String parameter, @Nullable Bindings.Internal internal) {
if (internal == null && Bindings.Internal.isInternal(parameter)) {
private static String checkInternalBinding(@Nonnull String parameter, @Nullable Bindings.BindingKind bindingKind) {
if (bindingKind == null && Bindings.BindingKind.isInternal(parameter)) {
throw new RecordCoreException(
"Parameter is internal, parameters cannot start with \"" + Bindings.Internal.PREFIX + "\"");
"Parameter is internal, parameters cannot start with \"" + Bindings.BindingKind.PREFIX + "\"");
}
return parameter;
}
Expand All @@ -1373,17 +1373,17 @@ private static String checkInternalBinding(@Nonnull String parameter, @Nullable
*/
public static class ParameterComparison extends ParameterComparisonBase {
protected ParameterComparison(@Nonnull Type type, @Nonnull String parameter,
@Nullable Bindings.Internal internal,
@Nullable Bindings.BindingKind bindingKind,
@Nonnull ParameterRelationshipGraph parameterRelationshipGraph) {
super(type, parameter, internal, parameterRelationshipGraph);
super(type, parameter, bindingKind, parameterRelationshipGraph);
}

public ParameterComparison(@Nonnull Type type, @Nonnull String parameter) {
this(type, parameter, null, ParameterRelationshipGraph.unbound());
}

public ParameterComparison(@Nonnull Type type, @Nonnull String parameter, @Nullable Bindings.Internal internal) {
this(type, parameter, internal, ParameterRelationshipGraph.unbound());
public ParameterComparison(@Nonnull Type type, @Nonnull String parameter, @Nullable Bindings.BindingKind bindingKind) {
this(type, parameter, bindingKind, ParameterRelationshipGraph.unbound());
}

@Nonnull
Expand All @@ -1392,23 +1392,23 @@ public Comparison withType(@Nonnull final Type newType) {
if (type == newType) {
return this;
}
return new ParameterComparison(newType, parameter, internal, parameterRelationshipGraph);
return new ParameterComparison(newType, parameter, bindingKind, parameterRelationshipGraph);
}

@Nonnull
@Override
protected ParameterComparisonBase withTranslatedCorrelation(@Nonnull CorrelationIdentifier translatedAlias) {
return new ParameterComparison(type,
Bindings.Internal.CORRELATION.bindingName(translatedAlias.getId()),
Bindings.Internal.CORRELATION,
Bindings.BindingKind.CORRELATION.bindingName(translatedAlias.getId()),
Bindings.BindingKind.CORRELATION,
parameterRelationshipGraph);
}

@Nonnull
@Override
public Comparison withParameterRelationshipMap(@Nonnull final ParameterRelationshipGraph parameterRelationshipGraph) {
Verify.verify(this.parameterRelationshipGraph.isUnbound());
return new ParameterComparison(type, parameter, internal, parameterRelationshipGraph);
return new ParameterComparison(type, parameter, bindingKind, parameterRelationshipGraph);
}

@Nonnull
Expand All @@ -1418,8 +1418,8 @@ public PParameterComparison toProto(@Nonnull final PlanSerializationContext seri
.setType(type.toProto(serializationContext))
.setParameter(parameter);

if (internal != null) {
builder.setInternal(internal.toProto(serializationContext));
if (bindingKind != null) {
builder.setInternal(bindingKind.toProto(serializationContext));
}
return builder.build();
}
Expand All @@ -1433,15 +1433,15 @@ public PComparison toComparisonProto(@Nonnull final PlanSerializationContext ser
@Nonnull
public static ParameterComparison fromProto(@Nonnull final PlanSerializationContext serializationContext,
@Nonnull final PParameterComparison parameterComparisonProto) {
final Bindings.Internal internal;
final Bindings.BindingKind bindingKind;
if (parameterComparisonProto.hasInternal()) {
internal = Bindings.Internal.fromProto(serializationContext, Objects.requireNonNull(parameterComparisonProto.getInternal()));
bindingKind = Bindings.BindingKind.fromProto(serializationContext, Objects.requireNonNull(parameterComparisonProto.getInternal()));
} else {
internal = null;
bindingKind = null;
}
return new ParameterComparison(Type.fromProto(serializationContext, Objects.requireNonNull(parameterComparisonProto.getType())),
Objects.requireNonNull(parameterComparisonProto.getParameter()),
internal);
bindingKind);
}

/**
Expand Down
Loading