From eeaf6725fd4341caeb6fa37ecac261104c5f342c Mon Sep 17 00:00:00 2001 From: EmmyMiao87 <522274284@qq.com> Date: Wed, 9 Feb 2022 13:07:03 +0800 Subject: [PATCH] (fix)[lateral-view] Solve the problem of not recognizing the lateral view on the view (#7968) If the tableRef behind represents a CTE or a view, the tableRef will be reset during semantic parsing. The new tableRef needs to inherit the lateral view property of the origin tableRef to ensure that the lateral view is not accidentally lost during parsing. --- .../org/apache/doris/analysis/InlineViewRef.java | 7 +++++-- .../doris/planner/TableFunctionPlanTest.java | 16 +++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java index 750fcfea9f..8df63b4492 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/InlineViewRef.java @@ -108,9 +108,12 @@ public class InlineViewRef extends TableRef { // TODO(zc) // view_.getTableName().toString().toLowerCase(), view.getName().toLowerCase() if (view.isLocalView()) { - aliases_ = new String[] { view.getName() }; + aliases_ = new String[]{view.getName()}; } else { - aliases_ = new String[] { name.toString(), view.getName() }; + aliases_ = new String[]{name.toString(), view.getName()}; + } + if (origTblRef.getLateralViewRefs() != null) { + lateralViewRefs = (ArrayList) origTblRef.getLateralViewRefs().clone(); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java index a2b26e4b85..c127d2fd9c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java @@ -480,7 +480,7 @@ public class TableFunctionPlanTest { } @Test - public void testLaterViewWithView() throws Exception { + public void testLateralViewWithView() throws Exception { // test 1 String createViewStr = "create view db1.v1 (k1,e1) as select k1,e1 from db1.table_for_view lateral view explode_split(k3,',') tmp as e1;"; CreateViewStmt createViewStmt = (CreateViewStmt) UtFrameUtils.parseAndAnalyzeStmt(createViewStr, ctx); @@ -495,7 +495,7 @@ public class TableFunctionPlanTest { } @Test - public void testLaterViewWithWhere() throws Exception { + public void testLateralViewWithWhere() throws Exception { String sql = "select k1,e1 from db1.table_for_view lateral view explode_split(k3,',') tmp as e1 where k1 in (select k2 from db1.table_for_view);"; String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); Assert.assertTrue(explainString.contains("join op: LEFT SEMI JOIN (BROADCAST)")); @@ -504,23 +504,21 @@ public class TableFunctionPlanTest { } @Test - public void testLaterViewWithCTE() throws Exception { + public void testLateralViewWithCTE() throws Exception { String sql = "with tmp as (select k1,e1 from db1.table_for_view lateral view explode_split(k3,',') tmp2 as e1) select * from tmp;"; String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); Assert.assertTrue(explainString.contains("table function: explode_split(`default_cluster:db1`.`table_for_view`.`k3`, ',') ")); } - @Ignore - // errCode = 2, detailMessage = Unknown column 'e1' in 'table list' - public void testLaterViewWithCTEBug() throws Exception { + @Test + public void testLateralViewWithCTEBug() throws Exception { String sql = "with tmp as (select * from db1.table_for_view where k2=1) select k1,e1 from tmp lateral view explode_split(k3,',') tmp2 as e1;"; String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); Assert.assertTrue(!explainString.contains("Unknown column 'e1' in 'table list'")); } - @Ignore - // errCode = 2, detailMessage = Unknown column 'e1' in 'table list' - public void testLaterViewUnknowColumnBug() throws Exception { + @Test + public void testLateralViewUnknownColumnBug() throws Exception { // test2 String createViewStr = "create view db1.v2 (k1,k3) as select k1,k3 from db1.table_for_view;"; CreateViewStmt createViewStmt = (CreateViewStmt) UtFrameUtils.parseAndAnalyzeStmt(createViewStr, ctx);