From acfbd0c5b43b42e3c923255a56efc8a3b4c587c0 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 20 May 2022 10:27:52 +0800 Subject: [PATCH] fix UT --- .../java/org/apache/doris/catalog/Type.java | 6 +- .../apache/doris/analysis/AggregateTest.java | 27 +++++--- .../analysis/ComparisonPredicateTest.java | 4 +- .../doris/analysis/InPredicateTest.java | 2 +- .../apache/doris/analysis/QueryStmtTest.java | 54 ++++++++-------- .../org/apache/doris/catalog/RecoverTest.java | 58 ++++++++--------- .../planner/MaterializedViewFunctionTest.java | 64 +++++++++---------- .../apache/doris/planner/QueryPlanTest.java | 25 ++++---- 8 files changed, 128 insertions(+), 112 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java index 90b0fd249f59d11..1f3374224a56f88 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java @@ -1309,8 +1309,12 @@ private static Type getDateComparisonResultType(ScalarType t1, ScalarType t2) { return t1; } else if (t1.isDatetimeV2() && t2.isDatetimeV2()) { return t1.decimalScale() > t2.decimalScale() ? t1 : t2; + } else if (t1.isDatetimeV2()) { + return t1; + } else if (t2.isDatetimeV2()) { + return t2; } else { - throw new AnalysisException(""); + return DateLiteral.getDefaultDateType(Type.DATETIME); } } catch (AnalysisException ignored) { LOG.error("Invalid date type: {} and {}", t1, t2); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/AggregateTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/AggregateTest.java index 1da669e25aed779..ca67f10941dddc0 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/AggregateTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/AggregateTest.java @@ -53,11 +53,13 @@ public void testCountDisintctAnalysisException() throws Exception { // NOT support mix distinct, one DistinctAggregationFunction has one column, the other DistinctAggregationFunction has some columns. do { - String query = "select count(distinct empid), count(distinct salary), count(distinct empid, salary) from " + DB_NAME + "." + TABLE_NAME; + String query = "select count(distinct empid), count(distinct salary), " + + "count(distinct empid, salary) from " + DB_NAME + "." + TABLE_NAME; try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The query contains multi count distinct or sum distinct, each can't have multi columns.")); + Assert.assertTrue(e.getMessage().contains( + "The query contains multi count distinct or sum distinct, each can't have multi columns.")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); @@ -147,7 +149,8 @@ public void testWindowFunnelAnalysisException() throws Exception { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The window params of window_funnel function must be integer")); + Assert.assertTrue( + e.getMessage().contains("The window params of window_funnel function must be integer")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); @@ -161,7 +164,8 @@ public void testWindowFunnelAnalysisException() throws Exception { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The window params of window_funnel function must be integer")); + Assert.assertTrue( + e.getMessage().contains("The window params of window_funnel function must be integer")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); @@ -175,7 +179,8 @@ public void testWindowFunnelAnalysisException() throws Exception { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The mode params of window_funnel function must be integer")); + Assert.assertTrue( + e.getMessage().contains("The mode params of window_funnel function must be integer")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); @@ -189,7 +194,8 @@ public void testWindowFunnelAnalysisException() throws Exception { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The mode params of window_funnel function must be integer")); + Assert.assertTrue( + e.getMessage().contains("The mode params of window_funnel function must be integer")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); @@ -203,7 +209,8 @@ public void testWindowFunnelAnalysisException() throws Exception { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The 3rd param of window_funnel function must be DATE or DATETIME")); + Assert.assertTrue( + e.getMessage().contains("The 3rd param of window_funnel function must be DATE or DATETIME")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); @@ -217,7 +224,8 @@ public void testWindowFunnelAnalysisException() throws Exception { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The 4th and subsequent params of window_funnel function must be boolean")); + Assert.assertTrue(e.getMessage().contains( + "The 4th and subsequent params of window_funnel function must be boolean")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); @@ -231,7 +239,8 @@ public void testWindowFunnelAnalysisException() throws Exception { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The 4th and subsequent params of window_funnel function must be boolean")); + Assert.assertTrue(e.getMessage().contains( + "The 4th and subsequent params of window_funnel function must be boolean")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/ComparisonPredicateTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/ComparisonPredicateTest.java index febd551dd00343f..1c3004f7e5a946c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/ComparisonPredicateTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/ComparisonPredicateTest.java @@ -154,7 +154,7 @@ public void testConvertToRangeForDateTimeV2() { Assert.assertEquals(dateTimeExpr, range1.upperEndpoint()); Assert.assertEquals(dateTimeV2Expr1, range1.upperEndpoint()); - Assert.assertNotEquals(dateTimeV2Expr2, range1.upperEndpoint()); + Assert.assertEquals(dateTimeV2Expr2, range1.upperEndpoint()); Assert.assertEquals(BoundType.CLOSED, range1.upperBoundType()); Assert.assertFalse(range1.hasLowerBound()); @@ -162,6 +162,6 @@ public void testConvertToRangeForDateTimeV2() { Assert.assertEquals(dateTimeV2Expr1, range2.upperEndpoint()); Assert.assertEquals(BoundType.CLOSED, range2.upperBoundType()); Assert.assertFalse(range2.hasLowerBound()); - Assert.assertNotEquals(dateTimeV2Expr2, range2.upperEndpoint()); + Assert.assertEquals(dateTimeV2Expr2, range2.upperEndpoint()); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/InPredicateTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/InPredicateTest.java index b2bb477a2ee7384..d2f32e37c979597 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/InPredicateTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/InPredicateTest.java @@ -173,7 +173,7 @@ public void testUnionWithDateV2() throws AnalysisException { InPredicate union = inPredicate1.union(inPredicate2); Assert.assertEquals(slotRef1, union.getChild(0)); Assert.assertTrue(union.isLiteralChildren()); - Assert.assertEquals(3, union.getListChildren().size()); + Assert.assertEquals(2, union.getListChildren().size()); Assert.assertTrue(union.getListChildren().contains(literalChild1)); Assert.assertTrue(union.getListChildren().contains(literalChild2)); Assert.assertTrue(union.getListChildren().contains(literalChild5)); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java index f4c52b9be0baa98..a3b1c4a5f48442b 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/QueryStmtTest.java @@ -220,33 +220,33 @@ public void testCollectExprs() throws Exception { // expr in subquery associate with column in grandparent level sql = "WITH aa AS\n" + - " (SELECT DATE_FORMAT(workDateTime, '%Y-%m') mon,\n" + - " DATE_FORMAT(workDateTimeV2, '%Y-%m') mon1,\n" + - " siteid\n" + - " FROM db1.table1\n" + - " WHERE workDateTime >= concat(year(now())-1, '-01-01 00:00:00')\n" + - " AND workDateTimeV2 >= concat(year(now())-1, '-01-01 00:00:00')\n" + - " AND workDateTimeV2 >= concat(year(now())-1, '-01-01 00:00:00.000000')\n" + - " AND workDateTime < now()\n" + - " AND workDateTimeV2 < now()\n" + - " GROUP BY siteid,\n" + - " DATE_FORMAT(workDateTime, '%Y-%m'),\n" + - " DATE_FORMAT(workDateTimeV2, '%Y-%m')),\n" + - " bb AS\n" + - " (SELECT mon,\n" + - " count(DISTINCT siteid) total\n" + - " FROM aa\n" + - " GROUP BY mon),\n" + - " cc AS\n" + - " (SELECT mon,\n" + - " count(DISTINCT siteid) num\n" + - " FROM aa\n" + - " GROUP BY mon)\n" + - "SELECT bb.mon,\n" + - " round(cc.num / bb.total, 4) rate\n" + - "FROM bb\n" + - "LEFT JOIN cc ON cc.mon = bb.mon\n" + - "ORDER BY mon;"; + + " (SELECT DATE_FORMAT(workDateTime, '%Y-%m') mon,\n" + + " DATE_FORMAT(workDateTimeV2, '%Y-%m') mon1,\n" + + " siteid\n" + + " FROM db1.table1\n" + + " WHERE workDateTime >= concat(year(now())-1, '-01-01 00:00:00')\n" + + " AND workDateTimeV2 >= concat(year(now())-1, '-01-01 00:00:00')\n" + + " AND workDateTimeV2 >= concat(year(now())-1, '-01-01 00:00:00.000000')\n" + + " AND workDateTime < now()\n" + + " AND workDateTimeV2 < now()\n" + + " GROUP BY siteid,\n" + + " DATE_FORMAT(workDateTime, '%Y-%m'),\n" + + " DATE_FORMAT(workDateTimeV2, '%Y-%m')),\n" + + " bb AS\n" + + " (SELECT mon,\n" + + " count(DISTINCT siteid) total\n" + + " FROM aa\n" + + " GROUP BY mon),\n" + + " cc AS\n" + + " (SELECT mon,\n" + + " count(DISTINCT siteid) num\n" + + " FROM aa\n" + + " GROUP BY mon)\n" + + "SELECT bb.mon,\n" + + " round(cc.num / bb.total, 4) rate\n" + + "FROM bb\n" + + "LEFT JOIN cc ON cc.mon = bb.mon\n" + + "ORDER BY mon;"; stmt = (QueryStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); exprsMap.clear(); stmt.collectExprs(exprsMap); diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/RecoverTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/RecoverTest.java index f673e27e131cfee..4720803458c9783 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/RecoverTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/RecoverTest.java @@ -41,7 +41,7 @@ public class RecoverTest { - private static String runningDir = "fe/mocked/RecoverTest/" + UUID.randomUUID().toString() + "/"; + private static String runningDir = "fe/mocked/RecoverTest/" + UUID.randomUUID() + "/"; private static ConnectContext connectContext; @@ -217,8 +217,8 @@ public void testRecover() throws Exception { @Test public void testRecover2() throws Exception { - createDb("test"); - createTable("CREATE TABLE test.`table1` (\n" + createDb("test2"); + createTable("CREATE TABLE test2.`table2` (\n" + " `event_date` datetime(3) NOT NULL COMMENT \"\",\n" + " `app_name` varchar(64) NOT NULL COMMENT \"\",\n" + " `package_name` varchar(64) NOT NULL COMMENT \"\",\n" @@ -243,30 +243,30 @@ public void testRecover2() throws Exception { + " \"replication_num\" = \"1\"\n" + ");"); - Assert.assertTrue(checkDbExist("test")); - Assert.assertTrue(checkTableExist("test", "table1")); + Assert.assertTrue(checkDbExist("test2")); + Assert.assertTrue(checkTableExist("test2", "table2")); - dropDb("test"); - Assert.assertFalse(checkDbExist("test")); - Assert.assertFalse(checkTableExist("test", "table1")); + dropDb("test2"); + Assert.assertFalse(checkDbExist("test2")); + Assert.assertFalse(checkTableExist("test2", "table2")); - recoverDb("test"); - Assert.assertTrue(checkDbExist("test")); - Assert.assertTrue(checkTableExist("test", "table1")); + recoverDb("test2"); + Assert.assertTrue(checkDbExist("test2")); + Assert.assertTrue(checkTableExist("test2", "table2")); - dropTable("test", "table1"); - Assert.assertTrue(checkDbExist("test")); - Assert.assertFalse(checkTableExist("test", "table1")); + dropTable("test2", "table2"); + Assert.assertTrue(checkDbExist("test2")); + Assert.assertFalse(checkTableExist("test2", "table2")); - recoverTable("test", "table1"); - Assert.assertTrue(checkDbExist("test")); - Assert.assertTrue(checkTableExist("test", "table1")); + recoverTable("test2", "table2"); + Assert.assertTrue(checkDbExist("test2")); + Assert.assertTrue(checkTableExist("test2", "table2")); - dropTable("test", "table1"); - Assert.assertTrue(checkDbExist("test")); - Assert.assertFalse(checkTableExist("test", "table1")); + dropTable("test2", "table2"); + Assert.assertTrue(checkDbExist("test2")); + Assert.assertFalse(checkTableExist("test2", "table2")); - createTable("CREATE TABLE test.`table1` (\n" + createTable("CREATE TABLE test2.`table2` (\n" + " `event_date` datetime(3) NOT NULL COMMENT \"\",\n" + " `app_name` varchar(64) NOT NULL COMMENT \"\",\n" + " `package_name` varchar(64) NOT NULL COMMENT \"\",\n" @@ -290,21 +290,21 @@ public void testRecover2() throws Exception { + " `model`, `brand`, `hours`) BUCKETS 1 PROPERTIES (\n" + " \"replication_num\" = \"1\"\n" + ");"); - Assert.assertTrue(checkDbExist("test")); - Assert.assertTrue(checkTableExist("test", "table1")); + Assert.assertTrue(checkDbExist("test2")); + Assert.assertTrue(checkTableExist("test2", "table2")); try { - recoverTable("test", "table1"); + recoverTable("test2", "table2"); Assert.fail("should not recover succeed"); } catch (DdlException e) { e.printStackTrace(); } - Assert.assertTrue(checkPartitionExist("test", "table1", "p1")); - dropPartition("test", "table1", "p1"); - Assert.assertFalse(checkPartitionExist("test", "table1", "p1")); + Assert.assertTrue(checkPartitionExist("test2", "table2", "p1")); + dropPartition("test2", "table2", "p1"); + Assert.assertFalse(checkPartitionExist("test2", "table2", "p1")); - recoverPartition("test", "table1", "p1"); - Assert.assertTrue(checkPartitionExist("test", "table1", "p1")); + recoverPartition("test2", "table2", "p1"); + Assert.assertTrue(checkPartitionExist("test2", "table2", "p1")); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java index 672fe921be49f77..c451b5db3394757 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java @@ -344,8 +344,8 @@ public void testJoinOnRightProjectToJoin() throws Exception { @Test public void testJoinOnProjectsToJoin() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select deptno, sum(salary), sum" + - "(commission) from " + EMPS_TABLE_NAME + " group by deptno;"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select deptno, sum(salary), sum" + + "(commission) from " + EMPS_TABLE_NAME + " group by deptno;"; String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno, max(cost) from " + DEPTS_TABLE_NAME + " group by deptno;"; String query = "select * from (select deptno , sum(salary) from " + EMPS_TABLE_NAME + " group by deptno) A " @@ -356,34 +356,34 @@ public void testJoinOnProjectsToJoin() throws Exception { @Test public void testJoinOnCalcToJoin0() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + - EMPS_TABLE_NAME + ";"; - String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + - DEPTS_TABLE_NAME + ";"; - String query = "select * from (select empid, deptno from " + EMPS_TABLE_NAME + " where deptno > 10 ) A " + - "join (select deptno from " + DEPTS_TABLE_NAME + " ) B on A.deptno = B.deptno;"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + + EMPS_TABLE_NAME + ";"; + String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + + DEPTS_TABLE_NAME + ";"; + String query = "select * from (select empid, deptno from " + EMPS_TABLE_NAME + " where deptno > 10 ) A " + + "join (select deptno from " + DEPTS_TABLE_NAME + " ) B on A.deptno = B.deptno;"; dorisAssert.withMaterializedView(createDeptsMVSQL).withMaterializedView(createEmpsMVsql).query(query) .explainContains(QUERY_USE_EMPS_MV, QUERY_USE_DEPTS_MV); } @Test public void testJoinOnCalcToJoin1() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + - EMPS_TABLE_NAME + ";"; - String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + - DEPTS_TABLE_NAME + ";"; - String query = "select * from (select empid, deptno from " + EMPS_TABLE_NAME + " ) A join (select " + - "deptno from " + DEPTS_TABLE_NAME + " where deptno > 10 ) B on A.deptno = B.deptno;"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + + EMPS_TABLE_NAME + ";"; + String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + + DEPTS_TABLE_NAME + ";"; + String query = "select * from (select empid, deptno from " + EMPS_TABLE_NAME + " ) A join (select " + + "deptno from " + DEPTS_TABLE_NAME + " where deptno > 10 ) B on A.deptno = B.deptno;"; dorisAssert.withMaterializedView(createDeptsMVSQL).withMaterializedView(createEmpsMVsql).query(query) .explainContains(QUERY_USE_EMPS_MV, QUERY_USE_DEPTS_MV); } @Test public void testJoinOnCalcToJoin2() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + - EMPS_TABLE_NAME + ";"; - String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + - DEPTS_TABLE_NAME + ";"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + + EMPS_TABLE_NAME + ";"; + String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + + DEPTS_TABLE_NAME + ";"; String query = "select * from (select empid, deptno from " + EMPS_TABLE_NAME + " where empid >10 ) A " + "join (select deptno from " + DEPTS_TABLE_NAME + " where deptno > 10 ) B on A.deptno = B.deptno;"; dorisAssert.withMaterializedView(createDeptsMVSQL).withMaterializedView(createEmpsMVsql).query(query) @@ -392,10 +392,10 @@ public void testJoinOnCalcToJoin2() throws Exception { @Test public void testJoinOnCalcToJoin3() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + - EMPS_TABLE_NAME + ";"; - String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + - DEPTS_TABLE_NAME + ";"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + + EMPS_TABLE_NAME + ";"; + String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + + DEPTS_TABLE_NAME + ";"; String query = "select * from (select empid, deptno + 1 deptno from " + EMPS_TABLE_NAME + " where empid >10 )" + " A join (select deptno from " + DEPTS_TABLE_NAME + " where deptno > 10 ) B on A.deptno = B.deptno;"; @@ -405,10 +405,10 @@ public void testJoinOnCalcToJoin3() throws Exception { @Test public void testJoinOnCalcToJoin4() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + - EMPS_TABLE_NAME + ";"; - String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + - DEPTS_TABLE_NAME + ";"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select empid, deptno from " + + EMPS_TABLE_NAME + ";"; + String createDeptsMVSQL = "create materialized view " + DEPTS_MV_NAME + " as select deptno from " + + DEPTS_TABLE_NAME + ";"; String query = "select * from (select empid, deptno + 1 deptno from " + EMPS_TABLE_NAME + " where empid is not null ) A full join (select deptno from " + DEPTS_TABLE_NAME + " where deptno is not null ) B on A.deptno = B.deptno;"; @@ -418,24 +418,24 @@ public void testJoinOnCalcToJoin4() throws Exception { @Test public void testOrderByQueryOnProjectView() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select deptno, empid from " + - EMPS_TABLE_NAME + ";"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select deptno, empid from " + + EMPS_TABLE_NAME + ";"; String query = "select empid from " + EMPS_TABLE_NAME + " order by deptno"; dorisAssert.withMaterializedView(createEmpsMVsql).query(query).explainContains(QUERY_USE_EMPS_MV); } @Test public void testOrderByQueryOnOrderByView() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select deptno, empid from " + - EMPS_TABLE_NAME + " order by deptno;"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select deptno, empid from " + + EMPS_TABLE_NAME + " order by deptno;"; String query = "select empid from " + EMPS_TABLE_NAME + " order by deptno"; dorisAssert.withMaterializedView(createEmpsMVsql).query(query).explainContains(QUERY_USE_EMPS_MV); } @Test public void testQueryOnStar() throws Exception { - String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select time_col, deptno," + - "empid, name, salary, commission from " + EMPS_TABLE_NAME + " order by time_col, deptno, empid;"; + String createEmpsMVsql = "create materialized view " + EMPS_MV_NAME + " as select time_col, deptno," + + "empid, name, salary, commission from " + EMPS_TABLE_NAME + " order by time_col, deptno, empid;"; String query = "select * from " + EMPS_TABLE_NAME + " where deptno = 1"; dorisAssert.withMaterializedView(createEmpsMVsql).query(query).explainContains(QUERY_USE_EMPS_MV); } 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 d5b7139e9067093..690dcbda3e88be4 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 @@ -238,12 +238,13 @@ protected void runBeforeAll() throws Exception { + " `use_time` double SUM NOT NULL COMMENT \"\",\n" + " `start_times` bigint(20) SUM NOT NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`event_date`, `app_name`, `package_name`, `age`, `gender`, `level`, `city`, `model`, `brand`, `hours`)\n" - + "COMMENT \"OLAP\"\n" + + "AGGREGATE KEY(`event_date`, `app_name`, `package_name`, `age`, `gender`, `level`, " + + "`city`, `model`, `brand`, `hours`) COMMENT \"OLAP\"\n" + "PARTITION BY RANGE(`event_date`)\n" + "(PARTITION p_20200301 VALUES [('2020-02-27'), ('2020-03-02')),\n" + "PARTITION p_20200306 VALUES [('2020-03-02'), ('2020-03-07')))\n" - + "DISTRIBUTED BY HASH(`event_date`, `app_name`, `package_name`, `age`, `gender`, `level`, `city`, `model`, `brand`, `hours`) BUCKETS 1\n" + + "DISTRIBUTED BY HASH(`event_date`, `app_name`, `package_name`, `age`, `gender`, `level`, " + + "`city`, `model`, `brand`, `hours`) BUCKETS 1\n" + "PROPERTIES (\n" + " \"replication_num\" = \"1\"\n" + ");"); @@ -960,7 +961,7 @@ public void testConvertCaseWhenToConstant() throws Exception { String sql232 = "select case k1 when substr(k7,2,1) then 2 when 1 then 'a' when false then 3 else 0 end" + " as col232 from test.baseall"; Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql232), - "OUTPUT EXPRS:CASE `k1` WHEN substr(`k7`, 2, 1) THEN '2' WHEN '1' THEN 'a'" + "OUTPUT EXPRS:CASE `k1` WHEN substr(`k7`, 2, 1) THEN '2' WHEN '1' THEN 'a' " + "WHEN '0' THEN '3' ELSE '0' END")); // 3.1 test float,float in case expr @@ -1000,13 +1001,13 @@ public void testConvertCaseWhenToConstant() throws Exception { // 5.4 test return CastExpr with other SlotRef in selectListItem String sql54 = "select k2, case when 2 < 1 then 'all' else k1 end as col54, k7 from test.baseall" - + "group by k2, col54, k7"; + + " group by k2, col54, k7"; Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql54), "OUTPUT EXPRS: `k2` | `k1` | `k7`")); // 5.5 test return CastExpr> with other SlotRef in selectListItem String sql55 = "select case when 2 < 1 then 'all' else cast(k1 as int) end as col55, k7 from" - + "test.baseall group by col55, k7"; + + " test.baseall group by col55, k7"; Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql55), "OUTPUT EXPRS: CAST(`k1` AS INT) | `k7`")); } @@ -1170,7 +1171,7 @@ public void testBucketShuffleJoin() throws Exception { // support recurse of bucket shuffle because t4 join t2 and join column name is same as t2 distribute column name queryStr = "explain select * from test.jointest t1 join test.bucket_shuffle1 t2 on t1.k1 = t2.k1 and" - + "t1.k1 = t2.k2 join test.colocate1 t3 on t2.k1 = t3.k1 join test.jointest t4 on t4.k1 = t2.k1 and" + + " t1.k1 = t2.k2 join test.colocate1 t3 on t2.k1 = t3.k1 join test.jointest t4 on t4.k1 = t2.k1 and" + " t4.k1 = t2.k2"; explainString = getSQLPlanOrErrorMsg(queryStr); Assert.assertTrue(explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t1`.`k1`, `t1`.`k1`")); @@ -1574,7 +1575,7 @@ public void testLeadAndLagFunction() throws Exception { queryStr = "explain select time_col, lead(time_col, 1, '2020-01-01 00:00:00') over () as time2 from test.test1"; explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("lead(`time`, 1, '2020-01-01 00:00:00')")); + Assert.assertTrue(explainString.contains("lead(`time_col`, 1, '2020-01-01 00:00:00')")); queryStr = "explain select time_col, lag(query_time, 1, 2) over () as time2 from test.test1"; explainString = getSQLPlanOrErrorMsg(queryStr); @@ -1911,10 +1912,12 @@ public void testOutfile() throws Exception { ");"); // test after query rewrite, outfile still work - String sql = "select * from test.outfile1 where `date` between '2021-10-07' and '2021-10-11'" + - "INTO OUTFILE \"file:///tmp/1_\" FORMAT AS CSV PROPERTIES ( \"column_separator\" = \",\", \"line_delimiter\" = \"\\n\", \"max_file_size\" = \"500MB\" );"; + String sql = "select * from test.outfile1 where `date` between '2021-10-07' and '2021-10-11' " + + " INTO OUTFILE \"file:///tmp/1_\" FORMAT AS CSV PROPERTIES ( \"column_separator\" = \",\", " + + " \"line_delimiter\" = \"\\n\", \"max_file_size\" = \"500MB\" );"; String explainStr = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07 00:00:00', `date` <= '2021-10-11 00:00:00'")); + Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07 00:00:00'," + + " `date` <= '2021-10-11 00:00:00'")); } // Fix: issue-#7929