From e0ceb7e17ed71705030f4251a84128e552ac2f06 Mon Sep 17 00:00:00 2001 From: lichi <12095047@qq.com> Date: Wed, 29 Mar 2023 18:21:58 +0800 Subject: [PATCH] [fix](planner)need add LateralViewRef's id into TableRef's allTableRefIds --- .../org/apache/doris/analysis/SelectStmt.java | 12 ++- .../org/apache/doris/analysis/TableRef.java | 6 ++ .../apache/doris/planner/AnalyticPlanner.java | 2 +- .../doris/planner/TableFunctionNode.java | 2 +- ...est_inlineview_with_window_function.groovy | 73 +++++++++++++++++++ 5 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 regression-test/suites/correctness_p0/test_inlineview_with_window_function.groovy 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 2f2ebaf9e89cd8..416e34131a47e7 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 @@ -776,6 +776,16 @@ public List getTableRefIds() { return result; } + public List getAllTableRefIds() { + List result = Lists.newArrayList(); + + for (TableRef ref : fromClause) { + result.addAll(ref.getAllTableRefIds()); + } + + return result; + } + public List getTableRefIdsWithoutInlineView() { List result = Lists.newArrayList(); @@ -876,7 +886,7 @@ public void materializeRequiredSlots(Analyzer analyzer) throws AnalysisException // can also be safely evaluated below the join (picked up by getBoundPredicates()). // Such predicates will be marked twice and that is ok. List unassigned = - analyzer.getUnassignedConjuncts(getTableRefIds(), true); + analyzer.getUnassignedConjuncts(getAllTableRefIds(), true); List 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 90d3460e85de11..a99e4cf9597dca 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 void analyzeJoin(Analyzer analyzer) throws AnalysisException { // Indicate that this table ref has an empty ON-clause. analyzer.registerOnClauseConjuncts(Collections.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 bfe9177f63b5e8..433fe76fd9ede1 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 @@ private SortInfo createSortInfo( ExprSubstitutionMap sortSmap = new ExprSubstitutionMap(); List 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 80ca77da8443e0..ff2a5f476aea2f 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 @@ -68,7 +68,7 @@ public TableFunctionNode(PlanNodeId id, PlanNode inputNode, TupleId lateralViewT protected TableFunctionNode(PlanNodeId id, PlanNode inputNode, List 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 00000000000000..0da26ff8f373b0 --- /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; + """ +}