-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix](Nereids)Check bounding of expression in analyze process after b…
…ounding and before apply more complex analyze rules
- Loading branch information
1 parent
fb377a9
commit b1a002a
Showing
6 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckBound.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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. | ||
|
||
package org.apache.doris.nereids.rules.analysis; | ||
|
||
import org.apache.doris.nereids.analyzer.Unbound; | ||
import org.apache.doris.nereids.analyzer.UnboundFunction; | ||
import org.apache.doris.nereids.analyzer.UnboundSlot; | ||
import org.apache.doris.nereids.exceptions.AnalysisException; | ||
import org.apache.doris.nereids.rules.Rule; | ||
import org.apache.doris.nereids.rules.RuleType; | ||
import org.apache.doris.nereids.trees.plans.Plan; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Check bound rule to check semantic correct after bounding of expression by Nereids. | ||
* Also give operator information without LOGICAL_ | ||
*/ | ||
public class CheckBound implements AnalysisRuleFactory { | ||
|
||
@Override | ||
public List<Rule> buildRules() { | ||
return ImmutableList.of( | ||
RuleType.CHECK_BOUND.build( | ||
any().then(plan -> { | ||
checkBound(plan); | ||
return null; | ||
}) | ||
) | ||
); | ||
} | ||
|
||
private void checkBound(Plan plan) { | ||
Set<Unbound> unbounds = plan.getExpressions().stream() | ||
.<Set<Unbound>>map(e -> e.collect(Unbound.class::isInstance)) | ||
.flatMap(Set::stream) | ||
.collect(Collectors.toSet()); | ||
if (!unbounds.isEmpty()) { | ||
throw new AnalysisException(String.format("unbounded object %s in %s clause.", | ||
StringUtils.join(unbounds.stream() | ||
.map(unbound -> { | ||
if (unbound instanceof UnboundSlot) { | ||
return ((UnboundSlot) unbound).toSql(); | ||
} else if (unbound instanceof UnboundFunction) { | ||
return ((UnboundFunction) unbound).toSql(); | ||
} | ||
return unbound.toString(); | ||
}) | ||
.collect(Collectors.toSet()), ", "), | ||
plan.getType().toString().substring("LOGICAL_".length()) | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
regression-test/suites/nereids_p0/except/test_bound_exception.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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_bound_exception") { | ||
sql "SET enable_nereids_planner=true" | ||
sql "SET enable_fallback_to_original_planner=false" | ||
def tbName = "test_bound_exception" | ||
def dbName = "test_bound_db" | ||
sql "CREATE DATABASE IF NOT EXISTS ${dbName}" | ||
sql "USE ${dbName}" | ||
|
||
sql """ DROP TABLE IF EXISTS ${tbName} """ | ||
sql """ | ||
create table if not exists ${tbName} (id int, name char(10)) | ||
distributed by hash(id) buckets 1 properties("replication_num"="1"); | ||
""" | ||
test { | ||
sql "SELECT id FROM ${tbName} GROUP BY id ORDER BY id123" | ||
exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in SORT clause." | ||
} | ||
test { | ||
sql "SELECT id123 FROM ${tbName} ORDER BY id" | ||
exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in PROJECT clause." | ||
} | ||
test { | ||
sql "SELECT id123 FROM ${tbName} GROUP BY id ORDER BY id" | ||
exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in AGGREGATE clause." | ||
} | ||
test { | ||
sql "SELECT id FROM ${tbName} GROUP BY id123 ORDER BY id" | ||
exception "errCode = 2, detailMessage = Unexpected exception: cannot bind GROUP BY KEY: id123" | ||
} | ||
test { | ||
sql "SELECT id FROM ${tbName} WHERE id = (SELECT id from ${tbName} ORDER BY id123 LIMIT 1) ORDER BY id" | ||
exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in SORT clause." | ||
} | ||
test { | ||
sql "SELECT id FROM ${tbName} WHERE id123 = 123 ORDER BY id" | ||
exception "errCode = 2, detailMessage = Unexpected exception: Invalid call to dataType on unbound object" | ||
} | ||
} |