Skip to content

Commit

Permalink
[Enhancement] Decode function add length (#55315)
Browse files Browse the repository at this point in the history
Signed-off-by: Seaven <[email protected]>
  • Loading branch information
Seaven authored Jan 24, 2025
1 parent 8c415a2 commit 5f44ce8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class DecodeCollector extends OptExpressionVisitor<DecodeInfo, DecodeInfo
FunctionSet.LTRIM, FunctionSet.REGEXP_EXTRACT, FunctionSet.REGEXP_REPLACE, FunctionSet.REPEAT,
FunctionSet.REPLACE, FunctionSet.REVERSE, FunctionSet.RIGHT, FunctionSet.RPAD, FunctionSet.RTRIM,
FunctionSet.SPLIT_PART, FunctionSet.SUBSTR, FunctionSet.SUBSTRING, FunctionSet.SUBSTRING_INDEX,
FunctionSet.TRIM, FunctionSet.UPPER, FunctionSet.IF);
FunctionSet.TRIM, FunctionSet.UPPER, FunctionSet.IF, FunctionSet.LENGTH, FunctionSet.CHAR_LENGTH);

// array<string> support:
// array<string> -> array<string>: array function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ public void testDecodeNodeRewrite4() throws Exception {
" | <slot 4> : 4: dept_name"));
}

@Test
public void testDecodeNodeRewriteLength() throws Exception {
String sql = "select length(dept_name), char_length(dept_name) from dept group by dept_name,state";
String plan = getFragmentPlan(sql);
Assert.assertTrue(plan, plan.contains(" 2:Project\n" +
" | <slot 4> : DictDecode(6: dept_name, [length(<place-holder>)])\n" +
" | <slot 5> : DictDecode(6: dept_name, [char_length(<place-holder>)])"));
}

@Test
public void testDecodeNodeRewrite5() throws Exception {
String sql = "select S_ADDRESS from supplier where S_ADDRESS " +
Expand Down
14 changes: 9 additions & 5 deletions test/sql/test_low_cardinality/R/test_low_cardinality2
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ insert into s2 select * from s2;
-- !result
[UC] analyze full table s1;
-- result:
test_db_597f05742dee11efbc9b7b0d31512d80.s1 analyze status OK
test_db_3569e679a63f46fcb95f5e935f2b4716.s1 analyze status OK
-- !result
[UC] analyze full table s2;
-- result:
test_db_597f05742dee11efbc9b7b0d31512d80.s2 analyze status OK
test_db_3569e679a63f46fcb95f5e935f2b4716.s2 analyze status OK
-- !result
function: wait_global_dict_ready('v3', 's1')
-- result:
Expand All @@ -338,6 +338,10 @@ select concat(upper(v4), "1"), max(v3) from s2 where v4 = "BJ" group by upper(v4
-- result:
BJ1 Jiangxi
-- !result
select length(v4), char_length(v4), max(v3) from s2 where v4 = "BJ" group by length(v4), char_length(v4) order by 1, 2;
-- result:
2 2 Jiangxi
-- !result
select count(distinct v3), max(v3), count(distinct v4) as a from s2;
-- result:
33 Zhejiang 34
Expand Down Expand Up @@ -484,7 +488,7 @@ FROM
-- !result
[UC] analyze full table supplier;
-- result:
test_db_597f05742dee11efbc9b7b0d31512d80.supplier analyze status OK
test_db_3569e679a63f46fcb95f5e935f2b4716.supplier analyze status OK
-- !result
function: wait_global_dict_ready('s_region', 'supplier')
-- result:
Expand All @@ -508,7 +512,7 @@ select l.S_NAME,l.mx_addr from agged_supplier_5 l right join [shuffle] supplier
3 3
4 4
-- !result
with a as ( select s_region, S_NAME from supplier where S_SUPPKEY < 10 limit 10 ), b as ( select max(upper(s_region)) as mx from a group by S_NAME ), c as ( select lower(mx) = lower('lw') from b )select *from c;
with a as ( select s_region, S_NAME from supplier where S_SUPPKEY < 10 limit 10 ), b as ( select max(upper(s_region)) as mx from a group by S_NAME ), c as ( select lower(mx) = lower('lw') from b )select *from c;
-- result:
0
0
Expand All @@ -519,4 +523,4 @@ select l.S_NAME,l.mx_addr from agged_supplier_5 l right join [shuffle] supplier
0
0
0
-- !result
-- !result
1 change: 1 addition & 0 deletions test/sql/test_low_cardinality/T/test_low_cardinality2
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ function: wait_global_dict_ready('v4', 's2')

select concat(upper(v2), "1"), max(v3) from s2 where v4 = "BJ" group by upper(v2) order by 1, 2;
select concat(upper(v4), "1"), max(v3) from s2 where v4 = "BJ" group by upper(v4) order by 1, 2;
select length(v4), char_length(v4), max(v3) from s2 where v4 = "BJ" group by length(v4), char_length(v4) order by 1, 2;

select count(distinct v3), max(v3), count(distinct v4) as a from s2;

Expand Down

0 comments on commit 5f44ce8

Please sign in to comment.