Skip to content

Commit

Permalink
fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel39 committed May 20, 2022
1 parent 61ed135 commit 248aace
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 113 deletions.
6 changes: 5 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ 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());

Assert.assertEquals(dateTimeExpr, range2.upperEndpoint());
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,34 +219,34 @@ public void testCollectExprs() throws Exception {
Assert.assertEquals(1, constMap.size());

// 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;";
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;";
stmt = (QueryStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx);
exprsMap.clear();
stmt.collectExprs(exprsMap);
Expand Down
58 changes: 29 additions & 29 deletions fe/fe-core/src/test/java/org/apache/doris/catalog/RecoverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"));
}
}
Loading

0 comments on commit 248aace

Please sign in to comment.