This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new 319f1f634a [fix](ut) fix fe run CreateTableAsSelectStmtTest ,UserPropertyTest, ProjectPlannerFunctionTest and AggregateTest failed (#8838) 319f1f634a is described below commit 319f1f634a53f99deb2d2ee50d12defe17995516 Author: caiconghui <55968745+caicong...@users.noreply.github.com> AuthorDate: Wed Apr 6 15:23:49 2022 +0800 [fix](ut) fix fe run CreateTableAsSelectStmtTest ,UserPropertyTest, ProjectPlannerFunctionTest and AggregateTest failed (#8838) --- .../apache/doris/analysis/FunctionCallExpr.java | 12 +++---- .../java/org/apache/doris/catalog/Catalog.java | 3 +- .../main/java/org/apache/doris/catalog/Column.java | 5 +-- .../org/apache/doris/analysis/AggregateTest.java | 4 +-- .../analysis/CreateTableAsSelectStmtTest.java | 25 +++++++------ .../org/apache/doris/catalog/UserPropertyTest.java | 41 ++++++++++++++++++++++ .../doris/planner/ProjectPlannerFunctionTest.java | 2 +- .../doris/planner/TableFunctionPlanTest.java | 8 ++--- 8 files changed, 68 insertions(+), 32 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 6115350414..261fa40725 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -236,17 +236,17 @@ public class FunctionCallExpr extends Expr { && fnParams.isStar() == o.fnParams.isStar(); } - private String paramsToSql(FunctionParams params) { + private String paramsToSql() { StringBuilder sb = new StringBuilder(); sb.append("("); - if (params.isStar()) { + if (fnParams.isStar()) { sb.append("*"); } - if (params.isDistinct()) { + if (fnParams.isDistinct()) { sb.append("DISTINCT "); } - int len = params.exprs().size(); + int len = children.size(); List<String> result = Lists.newArrayList(); if (fnName.getFunction().equalsIgnoreCase("json_array") || fnName.getFunction().equalsIgnoreCase("json_object")) { @@ -265,7 +265,7 @@ public class FunctionCallExpr extends Expr { fnName.getFunction().equalsIgnoreCase("sm4_encrypt"))) { result.add("\'***\'"); } else { - result.add(params.exprs().get(i).toSql()); + result.add(children.get(i).toSql()); } } sb.append(Joiner.on(", ").join(result)).append(")"); @@ -282,7 +282,7 @@ public class FunctionCallExpr extends Expr { } StringBuilder sb = new StringBuilder(); sb.append(((FunctionCallExpr) expr).fnName); - sb.append(paramsToSql(fnParams)); + sb.append(paramsToSql()); if (fnName.getFunction().equalsIgnoreCase("json_quote") || fnName.getFunction().equalsIgnoreCase("json_array") || fnName.getFunction().equalsIgnoreCase("json_object")) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java index 57a066680f..beaa10d415 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java @@ -3116,8 +3116,7 @@ public class Catalog { } TypeDef typeDef; Expr resultExpr = resultExprs.get(i); - // varchar/char transfer to string - if (resultExpr.getType().isStringType()) { + if (resultExpr.getType().isStringType() && resultExpr.getType().getLength() < 0) { typeDef = new TypeDef(Type.STRING); } else { typeDef = new TypeDef(resultExpr.getType()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java index 2ab61c7a9a..6ebcd9c080 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java @@ -234,10 +234,7 @@ public class Column implements Writable { public PrimitiveType getDataType() { return type.getPrimitiveType(); } public Type getType() { - if (type.isArrayType() || type.isMapType() || type.isStructType()) { - return type; - } - return ScalarType.createType(type.getPrimitiveType()); + return type; } public void setType(Type type) { 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 35225dca12..f239a303a8 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 @@ -130,7 +130,7 @@ public class AggregateTest { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The window param 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."); @@ -144,7 +144,7 @@ public class AggregateTest { try { UtFrameUtils.parseAndAnalyzeStmt(query, ctx); } catch (AnalysisException e) { - Assert.assertTrue(e.getMessage().contains("The mode param of window_funnel function must be string")); + Assert.assertTrue(e.getMessage().contains("The mode params of window_funnel function must be integer")); break; } catch (Exception e) { Assert.fail("must be AnalysisException."); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java index 7804f6c94a..bf2154c5bd 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java @@ -113,14 +113,14 @@ public class CreateTableAsSelectStmtTest { } @Test - public void testErrorType() throws Exception { + public void testErrorType() { String selectFromDecimal = "create table `test`.`select_decimal_table` PROPERTIES(\"replication_num\" = \"1\") as select * from `test`.`decimal_table`"; ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "Unsupported type", () -> UtFrameUtils.parseAndAnalyzeStmt(selectFromDecimal, connectContext)); } @Test - public void testErrorColumn() throws Exception { + public void testErrorColumn() { String selectFromColumn = "create table `test`.`select_column_table`(test_error) PROPERTIES(\"replication_num\" = \"1\") as select * from `test`.`varchar_table`"; ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "Number of columns don't equal number of SELECT statement's select list", () -> UtFrameUtils.parseAndAnalyzeStmt(selectFromColumn, connectContext)); @@ -132,8 +132,8 @@ public class CreateTableAsSelectStmtTest { createTableAsSelect(selectFromDecimal); ShowResultSet showResultSet = showCreateTable("select_varchar"); Assert.assertEquals("CREATE TABLE `select_varchar` (\n" + - " `userId` text NULL COMMENT \"\",\n" + - " `username` text NULL COMMENT \"\"\n" + + " `userId` varchar(255) NULL COMMENT \"\",\n" + + " `username` varchar(255) NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" + "DUPLICATE KEY(`userId`)\n" + "COMMENT \"OLAP\"\n" + @@ -150,7 +150,6 @@ public class CreateTableAsSelectStmtTest { String selectFromFunction1 = "create table `test`.`select_function_1` PROPERTIES(\"replication_num\" = \"1\") as select count(*) from `test`.`varchar_table`"; createTableAsSelect(selectFromFunction1); ShowResultSet showResultSet1 = showCreateTable("select_function_1"); - System.out.println(showResultSet1.getResultRows().get(0).get(1)); Assert.assertEquals("CREATE TABLE `select_function_1` (\n" + " `_col0` bigint(20) NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" + @@ -203,8 +202,8 @@ public class CreateTableAsSelectStmtTest { createTableAsSelect(selectAlias2); ShowResultSet showResultSet2 = showCreateTable("select_alias_2"); Assert.assertEquals("CREATE TABLE `select_alias_2` (\n" + - " `alias_name` text NULL COMMENT \"\",\n" + - " `username` text NULL COMMENT \"\"\n" + + " `alias_name` varchar(255) NULL COMMENT \"\",\n" + + " `username` varchar(255) NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" + "DUPLICATE KEY(`alias_name`)\n" + "COMMENT \"OLAP\"\n" + @@ -223,8 +222,8 @@ public class CreateTableAsSelectStmtTest { createTableAsSelect(selectFromJoin); ShowResultSet showResultSet = showCreateTable("select_join"); Assert.assertEquals("CREATE TABLE `select_join` (\n" + - " `userId` text NULL COMMENT \"\",\n" + - " `username` text NULL COMMENT \"\",\n" + + " `userId` varchar(255) NULL COMMENT \"\",\n" + + " `username` varchar(255) NULL COMMENT \"\",\n" + " `status` int(11) NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" + "DUPLICATE KEY(`userId`)\n" + @@ -244,8 +243,8 @@ public class CreateTableAsSelectStmtTest { createTableAsSelect(selectFromName); ShowResultSet showResultSet = showCreateTable("select_name"); Assert.assertEquals("CREATE TABLE `select_name` (\n" + - " `user` text NULL COMMENT \"\",\n" + - " `testname` text NULL COMMENT \"\",\n" + + " `user` varchar(255) NULL COMMENT \"\",\n" + + " `testname` varchar(255) NULL COMMENT \"\",\n" + " `userstatus` int(11) NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" + "DUPLICATE KEY(`user`)\n" + @@ -265,7 +264,7 @@ public class CreateTableAsSelectStmtTest { createTableAsSelect(selectFromName); ShowResultSet showResultSet = showCreateTable("select_union"); Assert.assertEquals("CREATE TABLE `select_union` (\n" + - " `userId` text NULL COMMENT \"\"\n" + + " `userId` varchar(255) NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" + "DUPLICATE KEY(`userId`)\n" + "COMMENT \"OLAP\"\n" + @@ -284,7 +283,7 @@ public class CreateTableAsSelectStmtTest { createTableAsSelect(selectFromName); ShowResultSet showResultSet = showCreateTable("select_cte"); Assert.assertEquals("CREATE TABLE `select_cte` (\n" + - " `userId` text NULL COMMENT \"\"\n" + + " `userId` varchar(255) NULL COMMENT \"\"\n" + ") ENGINE=OLAP\n" + "DUPLICATE KEY(`userId`)\n" + "COMMENT \"OLAP\"\n" + diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/UserPropertyTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/UserPropertyTest.java index 0702e2157c..f82c378929 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/UserPropertyTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/UserPropertyTest.java @@ -17,6 +17,9 @@ package org.apache.doris.catalog; +import mockit.Expectations; +import mockit.Mocked; +import org.apache.doris.blockrule.SqlBlockRuleMgr; import org.apache.doris.common.DdlException; import org.apache.doris.common.FeConstants; import org.apache.doris.common.Pair; @@ -26,7 +29,9 @@ import org.apache.doris.mysql.privilege.UserProperty; import com.google.common.collect.Lists; +import org.apache.doris.thrift.TStorageMedium; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -38,6 +43,42 @@ import java.util.List; public class UserPropertyTest { private FakeCatalog fakeCatalog; + @Mocked + private Catalog catalog; + @Mocked + private SqlBlockRuleMgr sqlBlockRuleMgr; + + @Before + public void setUp() { + new Expectations(catalog) { + { + catalog.getSqlBlockRuleMgr(); + minTimes = 0; + result = sqlBlockRuleMgr; + + sqlBlockRuleMgr.existRule("rule1"); + minTimes = 0; + result = true; + + sqlBlockRuleMgr.existRule("rule2"); + minTimes = 0; + result = true; + + sqlBlockRuleMgr.existRule("test1"); + minTimes = 0; + result = true; + + sqlBlockRuleMgr.existRule("test2"); + minTimes = 0; + result = true; + + sqlBlockRuleMgr.existRule("test3"); + minTimes = 0; + result = true; + } + }; + } + @Test public void testNormal() throws IOException, DdlException { // mock catalog diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java index 58c87a6289..0159edba6c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java @@ -46,7 +46,7 @@ public class ProjectPlannerFunctionTest { connectContext = UtFrameUtils.createDefaultCtx(); // enable hash project - Deencapsulation.setField(connectContext.getSessionVariable(), "enableHashProject", true); + Deencapsulation.setField(connectContext.getSessionVariable(), "enableProjection", true); // create database String createDbStmtStr = "create database test;"; 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 c127d2fd9c..f203c8dbf2 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 @@ -199,7 +199,7 @@ public class TableFunctionPlanTest { String sql = "explain select k1 from db1.tbl1 where explode_split(k2, \",\");"; String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql); Assert.assertTrue( - explainString.contains("No matching function with signature: explode_split(varchar(-1), varchar(-1)).")); + explainString.contains("No matching function with signature: explode_split(varchar(1), varchar(-1)).")); } // test projection @@ -340,8 +340,8 @@ public class TableFunctionPlanTest { Assert.assertTrue(explainString.contains("table function: explode_split(concat(`a`.`k2`, ',', `a`.`k3`), ',')")); Assert.assertTrue(explainString.contains("lateral view tuple id: 1")); Assert.assertTrue(explainString.contains("output slot id: 3")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=0, col=k2, type=VARCHAR(*)}")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=k3, type=VARCHAR(*)}")); + Assert.assertTrue(explainString.contains("SlotDescriptor{id=0, col=k2, type=VARCHAR(1)}")); + Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=k3, type=VARCHAR(1)}")); } // lateral view of subquery @@ -398,7 +398,7 @@ public class TableFunctionPlanTest { + "materialized=true" )); Assert.assertTrue(formatString.contains( - "SlotDescriptor{id=1,col=k2,type=VARCHAR(*)}\n" + "SlotDescriptor{id=1,col=k2,type=VARCHAR(1)}\n" + "parent=0\n" + "materialized=true" )); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org