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

[feature](Nereids) support values inline table in query #28972

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ statement
partitionSpec? // partition define
(WITH LABEL labelName=identifier)? cols=identifierList? // label and columns define
(LEFT_BRACKET hints=identifierSeq RIGHT_BRACKET)? // hint define
(query | inlineTable) #insertTable
query #insertTable
| explain? cte? UPDATE tableName=multipartIdentifier tableAlias
SET updateAssignmentSeq
fromClause?
Expand Down Expand Up @@ -286,6 +286,7 @@ setQuantifier
queryPrimary
: querySpecification #queryPrimaryDefault
| LEFT_PAREN query RIGHT_PAREN #subquery
| inlineTable #valuesTable
;

querySpecification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public LogicalPlan visitInsertTable(InsertTableContext ctx) {
List<String> colNames = ctx.cols == null ? ImmutableList.of() : visitIdentifierList(ctx.cols);
// TODO visit partitionSpecCtx
Pair<Boolean, List<String>> partitionSpec = visitPartitionSpec(ctx.partitionSpec());
LogicalPlan plan = ctx.query() != null ? visitQuery(ctx.query()) : visitInlineTable(ctx.inlineTable());
LogicalPlan plan = visitQuery(ctx.query());
UnboundTableSink<?> sink = new UnboundTableSink<>(
tableName.build(),
colNames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.doris.nereids.analyzer.UnboundSlot;
import org.apache.doris.nereids.analyzer.UnboundTVFRelation;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.parser.LogicalPlanBuilder;
import org.apache.doris.nereids.properties.OrderKey;
import org.apache.doris.nereids.rules.AppliedAwareRule.AppliedAwareRuleCondition;
import org.apache.doris.nereids.rules.Rule;
Expand All @@ -36,13 +37,15 @@
import org.apache.doris.nereids.trees.UnaryNode;
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.BoundStar;
import org.apache.doris.nereids.trees.expressions.DefaultValueSlot;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.expressions.ExprId;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.Properties;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator;
import org.apache.doris.nereids.trees.expressions.functions.BoundFunction;
import org.apache.doris.nereids.trees.expressions.functions.Function;
import org.apache.doris.nereids.trees.expressions.functions.FunctionBuilder;
Expand All @@ -67,6 +70,7 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalIntersect;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
import org.apache.doris.nereids.trees.plans.logical.LogicalResultSink;
Expand All @@ -87,6 +91,7 @@
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -528,6 +533,26 @@ protected boolean condition(Rule rule, Plan plan) {
return new LogicalHaving<>(boundConjuncts, having.child());
})
),
RuleType.BINDING_INLINE_TABLE_SLOT.build(
logicalInlineTable().thenApply(ctx -> {
LogicalInlineTable logicalInlineTable = ctx.root;
// ensure all expressions are valid.
List<LogicalPlan> relations
= Lists.newArrayListWithCapacity(logicalInlineTable.getConstantExprsList().size());
for (int i = 0; i < logicalInlineTable.getConstantExprsList().size(); i++) {
if (logicalInlineTable.getConstantExprsList().get(i).stream()
.anyMatch(DefaultValueSlot.class::isInstance)) {
throw new AnalysisException("Default expression"
+ " can't exist in SELECT statement at row " + (i + 1));
}
relations.add(new UnboundOneRowRelation(StatementScopeIdGenerator.newRelationId(),
logicalInlineTable.getConstantExprsList().get(i)));
}
// construct union all tree
return LogicalPlanBuilder.reduceToLogicalPlanTree(0, relations.size() - 1,
relations, Qualifier.ALL);
})
),
RuleType.BINDING_ONE_ROW_RELATION_SLOT.build(
// we should bind UnboundAlias in the UnboundOneRowRelation
unboundOneRowRelation().thenApply(ctx -> {
Expand All @@ -540,16 +565,6 @@ protected boolean condition(Rule rule, Plan plan) {
return new LogicalOneRowRelation(oneRowRelation.getRelationId(), projects);
})
),
RuleType.BINDING_INLINE_TABLE_SLOT.build(
logicalInlineTable().thenApply(ctx -> {
LogicalInlineTable logicalInlineTable = ctx.root;
// ensure all expressions are valid.
logicalInlineTable.getExpressions().forEach(expr ->
bindSlot(expr, ImmutableList.of(), ctx.cascadesContext, false)
);
return null;
})
),
RuleType.BINDING_SET_OPERATION_SLOT.build(
// LogicalSetOperation don't bind again if LogicalSetOperation.outputs is not empty, this is special
// we should not remove LogicalSetOperation::canBind, because in default case, the plan can run into
Expand Down
Loading