Skip to content

Commit

Permalink
[fix](Nereids) give clean error message when there are subquery in th…
Browse files Browse the repository at this point in the history
…e on clause (#20211)

Add the rule for checking the join node in `analysis/CheckAnalysis.java` file. When we check the join node, we should check its' on clause. If there are some subquery expression, we should throw exception.

Before this PR
```
mysql> select a.k1 from baseall a join test b on b.k2 in (select 49);
ERROR 1105 (HY000): errCode = 2, detailMessage = Unexpected exception: nul
```

After this PR
```
mysql> select a.k1 from baseall a join test b on b.k2 in (select 49);
ERROR 1105 (HY000): errCode = 2, detailMessage = Unexpected exception: Not support OnClause contain Subquery, expr:k2 IN (INSUBQUERY) (LogicalOneRowRelation ( projects=[49 AS `49`#28], buildUnionNode=true ))
```
  • Loading branch information
Reminiscent authored and xiaokang committed Jun 6, 2023
1 parent eb044d8 commit 8edb297
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.SubqueryExpr;
import org.apache.doris.nereids.trees.expressions.WindowExpression;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
import org.apache.doris.nereids.trees.expressions.functions.scalar.GroupingScalarFunction;
import org.apache.doris.nereids.trees.expressions.typecoercion.TypeCheckResult;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;

import com.google.common.collect.ImmutableList;
Expand All @@ -46,12 +48,14 @@
public class CheckAnalysis implements AnalysisRuleFactory {

private static final Map<Class<? extends LogicalPlan>, Set<Class<? extends Expression>>>
UNEXPECTED_EXPRESSION_TYPE_MAP = ImmutableMap.of(
LogicalFilter.class, ImmutableSet.of(
AggregateFunction.class,
GroupingScalarFunction.class,
WindowExpression.class)
);
UNEXPECTED_EXPRESSION_TYPE_MAP = ImmutableMap.<Class<? extends LogicalPlan>,
Set<Class<? extends Expression>>>builder()
.put(LogicalFilter.class, ImmutableSet.of(
AggregateFunction.class,
GroupingScalarFunction.class,
WindowExpression.class))
.put(LogicalJoin.class, ImmutableSet.of(SubqueryExpr.class))
.build();

@Override
public List<Rule> buildRules() {
Expand Down

0 comments on commit 8edb297

Please sign in to comment.