Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] fixup isNullable of cast #15380

Merged
merged 4 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix ut
  • Loading branch information
silverbullet233 committed Dec 20, 2022
commit 8cc8ed4ad427cce510d400826e5ba5bba8781e8e
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void setUp() throws Exception {
starRocksAssert.withDatabase("db1").useDatabase("db1");
starRocksAssert.withTable(createTblStmtStr);
starRocksAssert.withTable("CREATE TABLE `test_decimal_type6` (\n" +
" `dec_1_2` decimal32(2, 1) NOT NULL COMMENT \"\",\n" +
" `dec_2_1` decimal32(2, 1) NOT NULL COMMENT \"\",\n" +
" `dec_18_0` decimal64(18, 0) NOT NULL COMMENT \"\",\n" +
" `dec_18_18` decimal64(18, 18) NOT NULL COMMENT \"\",\n" +
" `dec_10_2` decimal64(10, 2) NOT NULL COMMENT \"\",\n" +
Expand All @@ -72,9 +72,9 @@ public static void setUp() throws Exception {
" dec_4_2 decimal64(4, 2),\n" +
" dec_5_1 decimal64(5, 1)\n" +
") ENGINE=OLAP\n" +
"DUPLICATE KEY(`dec_1_2`)\n" +
"DUPLICATE KEY(`dec_2_1`)\n" +
"COMMENT \"OLAP\"\n" +
"DISTRIBUTED BY HASH(`dec_1_2`) BUCKETS 10\n" +
"DISTRIBUTED BY HASH(`dec_2_1`) BUCKETS 10\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\",\n" +
"\"in_memory\" = \"false\",\n" +
Expand Down Expand Up @@ -317,7 +317,7 @@ public void testDecimal32Stddev() throws Exception {
String sql = "select stddev(col_decimal32p9s2) from db1.decimal_table";
String plan = UtFrameUtils.getVerboseFragmentPlan(ctx, sql);
String snippet = "aggregate: stddev[(cast([2: col_decimal32p9s2, DECIMAL32(9,2), false] as DOUBLE)); " +
"args: DOUBLE; result: DOUBLE; args nullable: true; result nullable: true]";
"args: DOUBLE; result: DOUBLE; args nullable: false; result nullable: true]";
Assert.assertTrue(plan.contains(snippet));
}

Expand All @@ -326,7 +326,7 @@ public void testDecimal32Variance() throws Exception {
String sql = "select variance(col_decimal32p9s2) from db1.decimal_table";
String plan = UtFrameUtils.getVerboseFragmentPlan(ctx, sql);
String snippet = "aggregate: variance[(cast([2: col_decimal32p9s2, DECIMAL32(9,2), false] as DOUBLE)); " +
"args: DOUBLE; result: DOUBLE; args nullable: true; result nullable: true]";
"args: DOUBLE; result: DOUBLE; args nullable: false; result nullable: true]";
Assert.assertTrue(plan.contains(snippet));
}

Expand Down Expand Up @@ -402,7 +402,7 @@ public void testDecimalAddRule() throws Exception {
// decimal(10, 2) + decimal(10, 2) = decimal(11, 2)
sql = "select count(`dec_10_2` + dec_10_2) from `test_decimal_type6`;";
plan = UtFrameUtils.getVerboseFragmentPlan(ctx, sql);
Assert.assertTrue(plan.contains("[12: cast, DECIMAL64(11,2), true] + [12: cast, DECIMAL64(11,2), true]"));
Assert.assertTrue(plan.contains("[12: cast, DECIMAL64(11,2), false] + [12: cast, DECIMAL64(11,2), false]"));

sql = "select count(`dec_10_2` + dec_12_10) from `test_decimal_type6`;";
plan = UtFrameUtils.getVerboseFragmentPlan(ctx, sql);
Expand All @@ -419,9 +419,9 @@ public void testDecimalAddRule() throws Exception {
plan = UtFrameUtils.getVerboseFragmentPlan(ctx, sql);
Assert.assertTrue(plan.contains(" 2 <-> 1000000000000000000.000000000000000001"));

sql = "select dec_1_2 + dec_1_2 from test_decimal_type6";
sql = "select dec_2_1 + dec_2_1 from test_decimal_type6";
plan = UtFrameUtils.getVerboseFragmentPlan(ctx, sql);
Assert.assertTrue(plan.contains("[11: cast, DECIMAL32(3,1), true] + [11: cast, DECIMAL32(3,1), true]"));
Assert.assertTrue(plan.contains("[11: cast, DECIMAL32(3,1), false] + [11: cast, DECIMAL32(3,1), false]"));
}

@Test
Expand Down Expand Up @@ -494,7 +494,7 @@ public void testDecimalNullableProperties() throws Exception {
plan = UtFrameUtils.getVerboseFragmentPlan(ctx, sql);
System.out.println("plan = " + plan);
Assert.assertTrue(plan.contains(
"round[(cast([2: dec_18_0, DECIMAL64(18,0), false] as DECIMAL128(18,0))); args: DECIMAL128; result: DECIMAL128(38,0); args nullable: true; result nullable: true]"));
"round[(cast([2: dec_18_0, DECIMAL64(18,0), false] as DECIMAL128(18,0))); args: DECIMAL128; result: DECIMAL128(38,0); args nullable: false; result nullable: true]"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public void testJoinOnExpression() throws Exception {
String plan = getCostExplain(sql);
assertContains(plan, "6:HASH JOIN\n" +
" | join op: INNER JOIN (PARTITIONED)\n" +
" | equal join conjunct: [29: cast, BIGINT, true] = [30: add, BIGINT, true]\n" +
" | equal join conjunct: [29: cast, BIGINT, false] = [30: add, BIGINT, false]\n" +
" | output columns: 14, 15, 20, 22\n" +
" | cardinality: 600000000");
assertContains(plan, "|----5:EXCHANGE\n" +
Expand All @@ -552,7 +552,7 @@ public void testJoinOnExpression() throws Exception {
"GROUP BY l_shipmode, l_shipinstruct, o_orderdate, o_orderstatus;";
plan = getCostExplain(sql);
Assert.assertTrue(
plan.contains("equal join conjunct: [29: multiply, BIGINT, true] = [30: add, BIGINT, true]\n" +
plan.contains("equal join conjunct: [29: multiply, BIGINT, false] = [30: add, BIGINT, false]\n" +
" | output columns: 14, 15, 20, 22\n" +
" | cardinality: 600000000"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ public void runFileUnitTest(String filename, boolean debug) {
e.printStackTrace();
}
System.out.println("DEBUG MODE!");
System.out.println("DEBUG FILE: " + debugFile.getPath());
}

Pattern regex = Pattern.compile("\\[plan-(\\d+)]");
Expand Down
8 changes: 4 additions & 4 deletions fe/fe-core/src/test/java/com/starrocks/sql/plan/SetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ public void testUnionNullConstant() throws Exception {
" | output exprs:\n" +
" | [7, DECIMAL64(12,2), true]\n" +
" | child exprs:\n" +
" | [3, DECIMAL64(12,2), true]\n" +
" | [6, DECIMAL64(12,2), true]\n");
" | [3, DECIMAL64(12,2), false]\n" +
" | [6, DECIMAL64(12,2), false]\n");

sql = "select count(*) from (select cast('1.2' as decimal(5,2)) as c1 union all " +
"select cast('1.2' as decimal(10,0)) as c1) t group by t.c1";
Expand All @@ -313,8 +313,8 @@ public void testUnionNullConstant() throws Exception {
" | output exprs:\n" +
" | [7, DECIMAL64(12,2), true]\n" +
" | child exprs:\n" +
" | [3, DECIMAL64(12,2), true]\n" +
" | [6, DECIMAL64(12,2), true]");
" | [3, DECIMAL64(12,2), false]\n" +
" | [6, DECIMAL64(12,2), false]");
}

@Test
Expand Down
10 changes: 8 additions & 2 deletions fe/fe-core/src/test/resources/sql/tpch-histogram-cost/q11.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ OutPut Exchange Id: 30
| cardinality: 1
|
10:AGGREGATE (update finalize)
| aggregate: sum[([20: expr, DOUBLE, true]); args: DOUBLE; result: DOUBLE; args nullable: true; result nullable: true]
| aggregate: sum[([20: expr, DOUBLE, false]); args: DOUBLE; result: DOUBLE; args nullable: false; result nullable: true]
| group by: [1: PS_PARTKEY, INT, false]
| cardinality: 3200000
| probe runtime filters:
Expand Down Expand Up @@ -118,6 +118,7 @@ OutPut Exchange Id: 30
table: partsupp, rollup: partsupp
preAggregation: on
partitionsRatio=1/1, tabletsRatio=10/10
tabletList=10181,10183,10185,10187,10189,10191,10193,10195,10197,10199
actualRows=0, avgRowSize=28.0
cardinality: 80000000
probe runtime filters:
Expand Down Expand Up @@ -165,7 +166,7 @@ OutPut Partition: UNPARTITIONED
OutPut Exchange Id: 22

21:AGGREGATE (update serialize)
| aggregate: sum[([41: expr, DOUBLE, true]); args: DOUBLE; result: DOUBLE; args nullable: true; result nullable: true]
| aggregate: sum[([41: expr, DOUBLE, false]); args: DOUBLE; result: DOUBLE; args nullable: false; result nullable: true]
| cardinality: 1
| column statistics:
| * sum-->[1.0, 9999000.0, 0.0, 8.0, 1.0] ESTIMATE
Expand Down Expand Up @@ -198,6 +199,7 @@ OutPut Exchange Id: 22
table: partsupp, rollup: partsupp
preAggregation: on
partitionsRatio=1/1, tabletsRatio=10/10
tabletList=10181,10183,10185,10187,10189,10191,10193,10195,10197,10199
actualRows=0, avgRowSize=20.0
cardinality: 80000000
probe runtime filters:
Expand Down Expand Up @@ -239,6 +241,7 @@ OutPut Exchange Id: 18
table: supplier, rollup: supplier
preAggregation: on
partitionsRatio=1/1, tabletsRatio=1/1
tabletList=10176
actualRows=0, avgRowSize=8.0
cardinality: 1000000
probe runtime filters:
Expand All @@ -265,6 +268,7 @@ table: nation, rollup: nation
preAggregation: on
Predicates: [37: N_NAME, CHAR, false] = 'PERU'
partitionsRatio=1/1, tabletsRatio=1/1
tabletList=10250
actualRows=0, avgRowSize=29.0
cardinality: 1
column statistics:
Expand Down Expand Up @@ -303,6 +307,7 @@ OutPut Exchange Id: 07
table: supplier, rollup: supplier
preAggregation: on
partitionsRatio=1/1, tabletsRatio=1/1
tabletList=10176
actualRows=0, avgRowSize=8.0
cardinality: 1000000
probe runtime filters:
Expand All @@ -329,6 +334,7 @@ table: nation, rollup: nation
preAggregation: on
Predicates: [16: N_NAME, CHAR, false] = 'PERU'
partitionsRatio=1/1, tabletsRatio=1/1
tabletList=10250
actualRows=0, avgRowSize=29.0
cardinality: 1
column statistics:
Expand Down