diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java index df8ec64fc2..562e84275d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java @@ -41,6 +41,7 @@ import org.apache.doris.nereids.trees.plans.algebra.Generate; import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; import org.apache.doris.nereids.trees.plans.logical.LogicalDeferMaterializeOlapScan; 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.LogicalOlapScan; import org.apache.doris.nereids.trees.plans.logical.LogicalSort; import org.apache.doris.nereids.trees.plans.logical.LogicalTopN; @@ -179,6 +180,18 @@ public class CheckAfterRewrite extends OneAnalysisRuleFactory { throw new AnalysisException(Type.OnlyMetricTypeErrorMsg); } }); + } else if (plan instanceof LogicalJoin) { + LogicalJoin join = (LogicalJoin) plan; + for (Expression conjunct : join.getHashJoinConjuncts()) { + if (conjunct.anyMatch(e -> ((Expression) e).getDataType().isVariantType())) { + throw new AnalysisException("variant type could not in join equal conditions: " + conjunct.toSql()); + } + } + for (Expression conjunct : join.getMarkJoinConjuncts()) { + if (conjunct.anyMatch(e -> ((Expression) e).getDataType().isVariantType())) { + throw new AnalysisException("variant type could not in join equal conditions: " + conjunct.toSql()); + } + } } } diff --git a/regression-test/suites/nereids_p0/join/test_join_on.groovy b/regression-test/suites/nereids_p0/join/test_join_on.groovy new file mode 100644 index 0000000000..22182f2c74 --- /dev/null +++ b/regression-test/suites/nereids_p0/join/test_join_on.groovy @@ -0,0 +1,27 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_join_on", "nereids_p0") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + test { + sql """select * from (select cast('' as variant) as a) t1 join (select cast('' as variant) as a) t2 on t1.a = t2.a""" + exception "variant type could not in join equal conditions" + } +} +