Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
924060929 committed Dec 9, 2024
1 parent 7884c5a commit 1126e59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@
import org.apache.doris.nereids.StatementContext;
import org.apache.doris.nereids.analyzer.UnboundAlias;
import org.apache.doris.nereids.analyzer.UnboundFunction;
import org.apache.doris.nereids.analyzer.UnboundOneRowRelation;
import org.apache.doris.nereids.analyzer.UnboundRelation;
import org.apache.doris.nereids.analyzer.UnboundResultSink;
import org.apache.doris.nereids.analyzer.UnboundSlot;
Expand Down Expand Up @@ -470,6 +469,7 @@
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.algebra.Aggregate;
import org.apache.doris.nereids.trees.plans.algebra.OneRowRelation;
import org.apache.doris.nereids.trees.plans.algebra.SetOperation.Qualifier;
import org.apache.doris.nereids.trees.plans.commands.AddConstraintCommand;
import org.apache.doris.nereids.trees.plans.commands.AdminCheckTabletsCommand;
Expand Down Expand Up @@ -2013,18 +2013,22 @@ public Expression visitStar(StarContext ctx) {
throw new ParseException("only one replace clause is supported", ctx);
}
ReplaceContext replaceContext = (ReplaceContext) exceptOrReplace;
List<NamedExpression> expectAlias = getNamedExpressions(replaceContext.namedExpressionSeq());
boolean allAlias = expectAlias.stream()
.allMatch(e -> e instanceof UnboundAlias
&& ((UnboundAlias) e).getAlias().isPresent());
if (expectAlias.isEmpty() || !allAlias) {
throw new ParseException(
"only alias is supported in select-replace clause", ctx);
List<NamedExpression> expectAlias = Lists.newArrayList();
NamedExpressionSeqContext namedExpressions = replaceContext.namedExpressionSeq();
for (NamedExpressionContext namedExpressionContext : namedExpressions.namedExpression()) {
if (namedExpressionContext.identifierOrText() == null) {
throw new ParseException("only alias is supported in select-replace clause", ctx);
}
expectAlias.add((NamedExpression) namedExpressionContext.accept(this));
}
if (expectAlias.isEmpty()) {
throw new ParseException("only alias is supported in select-replace clause", ctx);
}
finalReplacedAlias = expectAlias;
} else {
throw new ParseException("Unsupported except or replace clause: " + exceptOrReplace.getText(),
ctx);
throw new ParseException(
"Unsupported except or replace clause: " + exceptOrReplace.getText(), ctx
);
}
}
return new UnboundStar(target, finalExpectSlots, finalReplacedAlias);
Expand Down Expand Up @@ -3541,14 +3545,6 @@ private LogicalPlan withLimit(LogicalPlan input, Optional<LimitClauseContext> li
});
}

private UnboundOneRowRelation withOneRowRelation(SelectColumnClauseContext selectCtx) {
return ParserUtils.withOrigin(selectCtx, () -> {
// fromClause does not exists.
List<NamedExpression> projects = getNamedExpressions(selectCtx.namedExpressionSeq());
return new UnboundOneRowRelation(StatementScopeIdGenerator.newRelationId(), projects);
});
}

/**
* Add a regular (SELECT) query specification to a logical plan. The query specification
* is the core of the logical plan, this is where sourcing (FROM clause), projection (SELECT),
Expand Down Expand Up @@ -3806,7 +3802,7 @@ protected LogicalPlan withProjection(LogicalPlan input, SelectColumnClauseContex
}
} else {
List<NamedExpression> projects = getNamedExpressions(selectCtx.namedExpressionSeq());
if (input instanceof UnboundOneRowRelation) {
if (input instanceof OneRowRelation) {
if (projects.stream().anyMatch(project -> project instanceof UnboundStar)) {
throw new ParseException("SELECT * must have a FROM clause");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void testParse() {
));

// need select *
String sql3 = "seelct k1, k2, v1, v2 replace(k1 / 2 as k1) from t1";
String sql3 = "select k1, k2, v1, v2 replace(k1 / 2 as k1) from t1";
Assertions.assertThrows(ParseException.class, () -> PlanChecker.from(MemoTestUtils.createConnectContext())
.checkParse(sql3, (checker) -> checker.matches(
logicalProject(
Expand All @@ -152,7 +152,7 @@ public void testParse() {
.checkParse(sql4, (checker) -> checker.matches(
logicalProject(
logicalCheckPolicy(
unboundRelation()
logicalOneRowRelation()
)
)
)));
Expand All @@ -162,9 +162,7 @@ public void testParse() {
Assertions.assertThrows(ParseException.class, () -> PlanChecker.from(MemoTestUtils.createConnectContext())
.checkParse(sql5, (checker) -> checker.matches(
logicalProject(
logicalCheckPolicy(
unboundRelation()
)
logicalOneRowRelation()
)
)));

Expand Down

0 comments on commit 1126e59

Please sign in to comment.