This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 51741e886e42de2eb0a028cd4c393cbb556891c0 Author: starocean999 <[email protected]> AuthorDate: Thu Mar 30 11:32:18 2023 +0800 [fix](planner )need add LateralViewRef's id into TableRef's allTableRefIds (#18220) 1. add LateralViewRef's id into TableRef's allTableRefIds, so the caller won't miss LateralViewRef when trying to get all the tableref ids. 2. TableFunctionNode should use child node's output tuple id as the input tuple id --- .../java/org/apache/doris/analysis/SelectStmt.java | 12 +++- .../java/org/apache/doris/analysis/TableRef.java | 6 ++ .../org/apache/doris/planner/AnalyticPlanner.java | 2 +- .../apache/doris/planner/TableFunctionNode.java | 2 +- .../test_inlineview_with_window_function.groovy | 73 ++++++++++++++++++++++ 5 files changed, 92 insertions(+), 3 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 b3fab0ccea..0baffbc15f 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 @@ -596,6 +596,16 @@ public class SelectStmt extends QueryStmt { return result; } + public List<TupleId> getAllTableRefIds() { + List<TupleId> result = Lists.newArrayList(); + + for (TableRef ref : fromClause) { + result.addAll(ref.getAllTableRefIds()); + } + + return result; + } + public List<TupleId> getTableRefIdsWithoutInlineView() { List<TupleId> result = Lists.newArrayList(); @@ -696,7 +706,7 @@ public class SelectStmt extends QueryStmt { // can also be safely evaluated below the join (picked up by getBoundPredicates()). // Such predicates will be marked twice and that is ok. List<Expr> unassigned = - analyzer.getUnassignedConjuncts(getTableRefIds(), true); + analyzer.getUnassignedConjuncts(getAllTableRefIds(), true); List<Expr> unassignedJoinConjuncts = Lists.newArrayList(); for (Expr e : unassigned) { if (analyzer.evalAfterJoin(e)) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java index 1caa0bba97..7e9deadd84 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java @@ -681,6 +681,12 @@ public class TableRef implements ParseNode, Writable { // Indicate that this table ref has an empty ON-clause. analyzer.registerOnClauseConjuncts(Collections.<Expr>emptyList(), this); } + + if (lateralViewRefs != null) { + for (LateralViewRef lateralViewRef : lateralViewRefs) { + allTableRefIds.add(lateralViewRef.getId()); + } + } } public void rewriteExprs(ExprRewriter rewriter, Analyzer analyzer) diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/AnalyticPlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/AnalyticPlanner.java index e7e7533ff6..33417662df 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/AnalyticPlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/AnalyticPlanner.java @@ -301,7 +301,7 @@ public class AnalyticPlanner { ExprSubstitutionMap sortSmap = new ExprSubstitutionMap(); List<Expr> sortSlotExprs = Lists.newArrayList(); sortTupleDesc.setIsMaterialized(true); - for (TupleId tid : input.getTupleIds()) { + for (TupleId tid : input.getOutputTupleIds()) { TupleDescriptor tupleDesc = analyzer.getTupleDesc(tid); for (SlotDescriptor inputSlotDesc : tupleDesc.getSlots()) { if (!inputSlotDesc.isMaterialized()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/TableFunctionNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/TableFunctionNode.java index 592621e54d..4c21a89e5d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/TableFunctionNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/TableFunctionNode.java @@ -52,7 +52,7 @@ public class TableFunctionNode extends PlanNode { protected TableFunctionNode(PlanNodeId id, PlanNode inputNode, List<LateralViewRef> lateralViewRefs) { super(id, "TABLE FUNCTION NODE", StatisticalType.TABLE_FUNCTION_NODE); - tupleIds.addAll(inputNode.getTupleIds()); + tupleIds.addAll(inputNode.getOutputTupleIds()); tblRefIds.addAll(inputNode.getTupleIds()); tblRefIds.addAll(inputNode.getTblRefIds()); lateralViewTupleIds = lateralViewRefs.stream().map(e -> e.getDesc().getId()) diff --git a/regression-test/suites/correctness_p0/test_inlineview_with_window_function.groovy b/regression-test/suites/correctness_p0/test_inlineview_with_window_function.groovy new file mode 100644 index 0000000000..0da26ff8f3 --- /dev/null +++ b/regression-test/suites/correctness_p0/test_inlineview_with_window_function.groovy @@ -0,0 +1,73 @@ +// 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_inlineview_with_window_function") { + sql """ + drop view if exists test_table_aa; + """ + + sql """ + drop table if exists test_table_bb; + """ + + sql """ + CREATE TABLE `test_table_bb` ( + `event_date` datetime NULL, + `event_content` text NULL, + `animal_id` bigint(20) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`event_date`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`event_date`) BUCKETS 48 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2", + "disable_auto_compaction" = "false" + ); + """ + + sql """ + CREATE VIEW test_table_aa AS + SELECT + ev.event_date, + ev.animal_id, + get_json_int(ev.event_content, "\$.nurseOns") as nurseons + FROM test_table_bb ev; + """ + + sql """ + SELECT row_number() over(PARTITION BY animal_id ORDER BY event_date DESC) rw + FROM test_table_aa; + """ + + sql """ + select + e1 + from test_table_aa + lateral view explode([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]) tmp1 as e1 + where animal_id <= e1; + """ + + sql """ + drop view if exists test_table_aa; + """ + + sql """ + drop table if exists test_table_bb; + """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
