Skip to content

Commit

Permalink
Remove Symbol from RelationPlanner
Browse files Browse the repository at this point in the history
  • Loading branch information
rongrong authored and Rongrong Zhong committed Jul 31, 2019
1 parent e265ed1 commit 70010a8
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected RelationPlan visitJoin(Join node, Void context)
PlanBuilder leftPlanBuilder = initializePlanBuilder(leftPlan);
PlanBuilder rightPlanBuilder = initializePlanBuilder(rightPlan);

// NOTE: symbols must be in the same order as the outputDescriptor
// NOTE: variables must be in the same order as the outputDescriptor
List<VariableReferenceExpression> outputs = ImmutableList.<VariableReferenceExpression>builder()
.addAll(leftPlan.getFieldMappings())
.addAll(rightPlan.getFieldMappings())
Expand Down Expand Up @@ -296,7 +296,7 @@ else if (firstDependencies.stream().allMatch(right::canResolve) && secondDepende
joinConditionComparisonOperators.add(comparisonOperator.flip());
}
else {
// the case when we mix symbols from both left and right join side on either side of condition.
// the case when we mix variables from both left and right join side on either side of condition.
complexJoinExpressions.add(conjunct);
}
}
Expand Down Expand Up @@ -379,7 +379,7 @@ else if (firstDependencies.stream().allMatch(right::canResolve) && secondDepende
}

if (node.getType() == INNER) {
// rewrite all the other conditions using output symbols from left + right plan node.
// rewrite all the other conditions using output variables from left + right plan node.
PlanBuilder rootPlanBuilder = new PlanBuilder(translationMap, root, analysis.getParameters());
rootPlanBuilder = subqueryPlanner.handleSubqueries(rootPlanBuilder, complexJoinExpressions, node);

Expand Down Expand Up @@ -560,7 +560,7 @@ private static boolean isEqualComparisonExpression(Expression conjunct)
private RelationPlan planCrossJoinUnnest(RelationPlan leftPlan, Join joinNode, Unnest node)
{
RelationType unnestOutputDescriptor = analysis.getOutputDescriptor(node);
// Create symbols for the result of unnesting
// Create variables for the result of unnesting
ImmutableList.Builder<VariableReferenceExpression> unnestedVariablesBuilder = ImmutableList.builder();
for (Field field : unnestOutputDescriptor.getVisibleFields()) {
VariableReferenceExpression variable = variableAllocator.newVariable(field);
Expand Down Expand Up @@ -600,7 +600,7 @@ else if (type instanceof MapType) {
}
}
Optional<VariableReferenceExpression> ordinalityVariable = node.isWithOrdinality() ? Optional.of(unnestedVariablesIterator.next()) : Optional.empty();
checkState(!unnestedVariablesIterator.hasNext(), "Not all output symbols were matched with input symbols");
checkState(!unnestedVariablesIterator.hasNext(), "Not all output variables were matched with input variables");

UnnestNode unnestNode = new UnnestNode(idAllocator.getNextId(), projectNode, leftPlan.getFieldMappings(), unnestVariables.build(), ordinalityVariable);
return new RelationPlan(unnestNode, analysis.getScope(joinNode), unnestNode.getOutputVariables());
Expand Down Expand Up @@ -700,7 +700,7 @@ else if (type instanceof MapType) {
}
}
Optional<VariableReferenceExpression> ordinalityVariable = node.isWithOrdinality() ? Optional.of(unnestedVariablesIterator.next()) : Optional.empty();
checkState(!unnestedVariablesIterator.hasNext(), "Not all output symbols were matched with input symbols");
checkState(!unnestedVariablesIterator.hasNext(), "Not all output variables were matched with input variables");
ValuesNode valuesNode = new ValuesNode(
idAllocator.getNextId(),
argumentVariables.build(), ImmutableList.of(values.build()));
Expand Down Expand Up @@ -732,16 +732,15 @@ private RelationPlan addCoercions(RelationPlan plan, Type[] targetColumnTypes)
Assignments.Builder assignments = Assignments.builder();
for (int i = 0; i < targetColumnTypes.length; i++) {
VariableReferenceExpression inputVariable = oldVariables.get(i);
Symbol inputSymbol = new Symbol(inputVariable.getName());
Type outputType = targetColumnTypes[i];
if (!outputType.equals(inputVariable.getType())) {
Expression cast = new Cast(inputSymbol.toSymbolReference(), outputType.getTypeSignature().toString());
Expression cast = new Cast(new SymbolReference(inputVariable.getName()), outputType.getTypeSignature().toString());
VariableReferenceExpression outputVariable = variableAllocator.newVariable(cast, outputType);
assignments.put(outputVariable, castToRowExpression(cast));
newVariables.add(outputVariable);
}
else {
SymbolReference symbolReference = inputSymbol.toSymbolReference();
SymbolReference symbolReference = new SymbolReference(inputVariable.getName());
VariableReferenceExpression outputVariable = variableAllocator.newVariable(symbolReference, outputType);
assignments.put(outputVariable, castToRowExpression(symbolReference));
newVariables.add(outputVariable);
Expand Down Expand Up @@ -809,7 +808,7 @@ private SetOperationPlan process(SetOperation node)
for (RelationPlan relationPlan : subPlans) {
List<VariableReferenceExpression> childOutputVariables = relationPlan.getFieldMappings();
if (outputs == null) {
// Use the first Relation to derive output symbol names
// Use the first Relation to derive output variable names
RelationType descriptor = relationPlan.getDescriptor();
ImmutableList.Builder<VariableReferenceExpression> outputVariableBuilder = ImmutableList.builder();
for (Field field : descriptor.getVisibleFields()) {
Expand Down Expand Up @@ -843,7 +842,7 @@ private PlanBuilder initializePlanBuilder(RelationPlan relationPlan)
{
TranslationMap translations = new TranslationMap(relationPlan, analysis, lambdaDeclarationToVariableMap);

// Make field->symbol mapping from underlying relation plan available for translations
// Make field->variable mapping from underlying relation plan available for translations
// This makes it possible to rewrite FieldOrExpressions that reference fields from the underlying tuple directly
translations.setFieldMappings(relationPlan.getFieldMappings());

Expand Down

0 comments on commit 70010a8

Please sign in to comment.