[fix](ut) fix fe run CreateTableAsSelectStmtTest ,UserPropertyTest, ProjectPlannerFunctionTest and AggregateTest failed (#8838)

This commit is contained in:
caiconghui
2022-04-06 15:23:49 +08:00
committed by GitHub
parent f90a1a1919
commit 319f1f634a
8 changed files with 68 additions and 32 deletions

View File

@ -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")) {

View File

@ -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());

View File

@ -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) {

View File

@ -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.");

View File

@ -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" +

View File

@ -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

View File

@ -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;";

View File

@ -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"
));