Skip to content

Commit 10c7669

Browse files
[feature](selectdb-cloud) Pick "[fix](planner) need add LateralViewRef's id into TableRef's allTableRefIds (apache#18220)" (apache#1573)
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 Co-authored-by: starocean999 <[email protected]>
1 parent 998e7fe commit 10c7669

5 files changed

Lines changed: 92 additions & 3 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ public List<TupleId> getTableRefIds() {
600600
return result;
601601
}
602602

603+
public List<TupleId> getAllTableRefIds() {
604+
List<TupleId> result = Lists.newArrayList();
605+
606+
for (TableRef ref : fromClause) {
607+
result.addAll(ref.getAllTableRefIds());
608+
}
609+
610+
return result;
611+
}
612+
603613
public List<TupleId> getTableRefIdsWithoutInlineView() {
604614
List<TupleId> result = Lists.newArrayList();
605615

@@ -700,7 +710,7 @@ public void materializeRequiredSlots(Analyzer analyzer) throws AnalysisException
700710
// can also be safely evaluated below the join (picked up by getBoundPredicates()).
701711
// Such predicates will be marked twice and that is ok.
702712
List<Expr> unassigned =
703-
analyzer.getUnassignedConjuncts(getTableRefIds(), true);
713+
analyzer.getUnassignedConjuncts(getAllTableRefIds(), true);
704714
List<Expr> unassignedJoinConjuncts = Lists.newArrayList();
705715
for (Expr e : unassigned) {
706716
if (analyzer.evalAfterJoin(e)) {

‎fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ public void analyzeJoin(Analyzer analyzer) throws AnalysisException {
632632
// Indicate that this table ref has an empty ON-clause.
633633
analyzer.registerOnClauseConjuncts(Collections.<Expr>emptyList(), this);
634634
}
635+
636+
if (lateralViewRefs != null) {
637+
for (LateralViewRef lateralViewRef : lateralViewRefs) {
638+
allTableRefIds.add(lateralViewRef.getId());
639+
}
640+
}
635641
}
636642

637643
public void rewriteExprs(ExprRewriter rewriter, Analyzer analyzer)

‎fe/fe-core/src/main/java/org/apache/doris/planner/AnalyticPlanner.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private SortInfo createSortInfo(
301301
ExprSubstitutionMap sortSmap = new ExprSubstitutionMap();
302302
List<Expr> sortSlotExprs = Lists.newArrayList();
303303
sortTupleDesc.setIsMaterialized(true);
304-
for (TupleId tid : input.getTupleIds()) {
304+
for (TupleId tid : input.getOutputTupleIds()) {
305305
TupleDescriptor tupleDesc = analyzer.getTupleDesc(tid);
306306
for (SlotDescriptor inputSlotDesc : tupleDesc.getSlots()) {
307307
if (!inputSlotDesc.isMaterialized()) {

‎fe/fe-core/src/main/java/org/apache/doris/planner/TableFunctionNode.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class TableFunctionNode extends PlanNode {
5252

5353
protected TableFunctionNode(PlanNodeId id, PlanNode inputNode, List<LateralViewRef> lateralViewRefs) {
5454
super(id, "TABLE FUNCTION NODE", StatisticalType.TABLE_FUNCTION_NODE);
55-
tupleIds.addAll(inputNode.getTupleIds());
55+
tupleIds.addAll(inputNode.getOutputTupleIds());
5656
tblRefIds.addAll(inputNode.getTupleIds());
5757
tblRefIds.addAll(inputNode.getTblRefIds());
5858
lateralViewTupleIds = lateralViewRefs.stream().map(e -> e.getDesc().getId())
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_inlineview_with_window_function") {
19+
sql """
20+
drop view if exists test_table_aa;
21+
"""
22+
23+
sql """
24+
drop table if exists test_table_bb;
25+
"""
26+
27+
sql """
28+
CREATE TABLE `test_table_bb` (
29+
`event_date` datetime NULL,
30+
`event_content` text NULL,
31+
`animal_id` bigint(20) NULL
32+
) ENGINE=OLAP
33+
DUPLICATE KEY(`event_date`)
34+
COMMENT 'OLAP'
35+
DISTRIBUTED BY HASH(`event_date`) BUCKETS 48
36+
PROPERTIES (
37+
"replication_allocation" = "tag.location.default: 1",
38+
"in_memory" = "false",
39+
"storage_format" = "V2",
40+
"disable_auto_compaction" = "false"
41+
);
42+
"""
43+
44+
sql """
45+
CREATE VIEW test_table_aa AS
46+
SELECT
47+
ev.event_date,
48+
ev.animal_id,
49+
get_json_int(ev.event_content, "\$.nurseOns") as nurseons
50+
FROM test_table_bb ev;
51+
"""
52+
53+
sql """
54+
SELECT row_number() over(PARTITION BY animal_id ORDER BY event_date DESC) rw
55+
FROM test_table_aa;
56+
"""
57+
58+
sql """
59+
select
60+
e1
61+
from test_table_aa
62+
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
63+
where animal_id <= e1;
64+
"""
65+
66+
sql """
67+
drop view if exists test_table_aa;
68+
"""
69+
70+
sql """
71+
drop table if exists test_table_bb;
72+
"""
73+
}

0 commit comments

Comments
 (0)