This is an automated email from the ASF dual-hosted git repository.
adonisling pushed a commit to branch branch-1.1-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.1-lts by this push:
new 76bb9f191f [fix](planner) Output is wrong when select from an inline
view with constant expressions (#17451)
76bb9f191f is described below
commit 76bb9f191fe1c6866e5ef8241786c961a5bf5afb
Author: Adonis Ling <[email protected]>
AuthorDate: Tue Mar 7 14:37:07 2023 +0800
[fix](planner) Output is wrong when select from an inline view with
constant expressions (#17451)
Backport #16370 #16556 #16579 .
Co-authored-by: AKIRA <[email protected]>
Co-authored-by: xueweizhang <[email protected]>
---
.../java/org/apache/doris/analysis/SelectStmt.java | 27 +++++++++++++++
.../org/apache/doris/planner/QueryPlanTest.java | 15 +--------
.../data/query_p0/subquery/test_subquery2.out | 10 ++++++
.../suites/query_p0/subquery/test_subquery2.groovy | 38 ++++++++++++++++++++++
4 files changed, 76 insertions(+), 14 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 7bf212f84d..9a83d301f2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -48,6 +48,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import com.google.common.collect.Streams;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -60,6 +61,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
@@ -732,6 +734,31 @@ public class SelectStmt extends QueryStmt {
lateralViewRef.materializeRequiredSlots(baseTblSmap,
analyzer);
}
}
+
+ // In such case, agg output must be materialized whether outer
query block required or not.
+ if (tableRef instanceof InlineViewRef) {
+ InlineViewRef inlineViewRef = (InlineViewRef) tableRef;
+ QueryStmt queryStmt = inlineViewRef.getQueryStmt();
+ boolean hasConstant = Streams.concat(resultExprs.stream(),
queryStmt.resultExprs.stream())
+ .anyMatch(new Predicate<Expr>() {
+ @Override
+ public boolean test(Expr expr) {
+ if (expr instanceof SlotRef) {
+ SlotDescriptor desc = ((SlotRef)
expr).getDesc();
+ if (desc != null) {
+ List<Expr> sourceExprs =
desc.getSourceExprs();
+ return
CollectionUtils.isNotEmpty(sourceExprs)
+ &&
sourceExprs.stream().allMatch(this);
+ }
+ return false;
+ }
+ return expr.isConstant();
+ }
+ });
+ if (hasConstant) {
+ queryStmt.resultExprs.forEach(Expr::materializeSrcExpr);
+ }
+ }
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
index 79f8389018..e2ec0f9249 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
@@ -1793,19 +1793,6 @@ public class QueryPlanTest {
Assert.assertTrue(explainString.contains("PREDICATES: `k11` >
'2021-06-01 00:00:00'"));
}
- @Test
- public void testNullColumnViewOrderBy() throws Exception {
- FeConstants.runningUnitTest = true;
- connectContext.setDatabase("default_cluster:test");
- String sql = "select * from tbl_null_column_view where add_column is
not null;";
- String explainString1 =
UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
- Assert.assertTrue(explainString1.contains("EMPTYSET"));
-
- String sql2 = "select * from tbl_null_column_view where add_column is
not null order by query_id;";
- String explainString2 =
UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql2);
- Assert.assertTrue(explainString2.contains("EMPTYSET"));
- }
-
@Test
public void testCompoundPredicateWriteRule() throws Exception {
connectContext.setDatabase("default_cluster:test");
@@ -2155,4 +2142,4 @@ public class QueryPlanTest {
String explainString =
UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryBaseTableStr);
Assert.assertTrue(explainString.contains("PREAGGREGATION: ON"));
}
-}
\ No newline at end of file
+}
diff --git a/regression-test/data/query_p0/subquery/test_subquery2.out
b/regression-test/data/query_p0/subquery/test_subquery2.out
new file mode 100644
index 0000000000..ceaff8c994
--- /dev/null
+++ b/regression-test/data/query_p0/subquery/test_subquery2.out
@@ -0,0 +1,10 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql_1 --
+abc
+
+-- !sql_2 --
+bc
+
+-- !sql_3 --
+1
+
diff --git a/regression-test/suites/query_p0/subquery/test_subquery2.groovy
b/regression-test/suites/query_p0/subquery/test_subquery2.groovy
new file mode 100644
index 0000000000..e572459cc7
--- /dev/null
+++ b/regression-test/suites/query_p0/subquery/test_subquery2.groovy
@@ -0,0 +1,38 @@
+// 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_subquery2") {
+
+ sql """DROP TABLE IF EXISTS subquerytest2"""
+
+ sql """
+ CREATE TABLE subquerytest2 (birth int)UNIQUE KEY(birth)DISTRIBUTED BY
HASH (birth)
+ BUCKETS 1 PROPERTIES("replication_allocation" = "tag.location.default:
1");
+ """
+
+ sql """insert into subquerytest2 values (2)"""
+
+
+ qt_sql_1 """select i from (select 'abc' as i, sum(birth) as j from
subquerytest2) as tmp"""
+
+ qt_sql_2 """select substring(i, 2) from (select 'abc' as i, sum(birth) as
j from subquerytest2) as tmp"""
+
+ qt_sql_3 """select count(1) from (select 'abc' as i, sum(birth) as j from
subquerytest2) as tmp"""
+
+ sql """DROP TABLE subquerytest2"""
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]