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] Support rewrite window function sort partition by in lowcardinality optimization #8957

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public DecodeContext(Map<Long, List<Integer>> tableIdToStringColumnIds, ColumnRe
}
}

// if column ref is an applied optimized string column, return the dictionary column.
// else return column ref itself
ColumnRefOperator getMappedOperator(ColumnRefOperator columnRef) {
int id = columnRef.getId();
Integer mapped = stringColumnIdToDictColumnIds.getOrDefault(id, id);
return columnRefFactory.getColumnRef(mapped);
}

public void clear() {
stringColumnIdToDictColumnIds.clear();
stringFunctions.clear();
Expand Down Expand Up @@ -473,6 +481,14 @@ private PhysicalTopNOperator rewriteTopNOperator(PhysicalTopNOperator operator,
orderingList.add(orderDesc);
}
}

List<ColumnRefOperator> partitionByColumns = null;
if (operator.getPartitionByColumns() != null) {
partitionByColumns =
operator.getPartitionByColumns().stream().map(context::getMappedOperator)
.collect(Collectors.toList());
}

OrderSpec newOrderSpec = new OrderSpec(orderingList);

ScalarOperator predicate = operator.getPredicate();
Expand All @@ -487,7 +503,7 @@ private PhysicalTopNOperator rewriteTopNOperator(PhysicalTopNOperator operator,

return new PhysicalTopNOperator(newOrderSpec, operator.getLimit(),
operator.getOffset(),
null,
partitionByColumns,
Operator.DEFAULT_LIMIT,
operator.getSortPhase(),
operator.getTopNType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ public void testJoin() throws Exception {
plan = getVerboseExplain(sql);
Assert.assertFalse(plan.contains("Decode"));

sql = "select count(*) from supplier l join [broadcast] (select max(id_int) as id_int from table_int) r on l.S_ADDRESS = r.id_int where l.S_ADDRESS not like '%key%'";
sql = "select count(*) from supplier l join [broadcast] (select max(id_int) as id_int from table_int) r on l.S_ADDRESS = r.id_int where l.S_ADDRESS not like '%key%'";
plan = getVerboseExplain(sql);
Assert.assertFalse(plan.contains("Decode"));

Expand Down Expand Up @@ -944,6 +944,24 @@ public void testGroupByWithOrderBy() throws Exception {
connectContext.getSessionVariable().setNewPlanerAggStage(0);
}

@Test
public void testAnalytic() throws Exception {
// Test partition by string column
String sql;
String plan;
// Analytic with where
sql = "select sum(rm) from (" +
"select row_number() over( partition by L_COMMENT order by L_PARTKEY) as rm from lineitem" +
") t where rm < 10";
plan = getCostExplain(sql);

Assert.assertTrue(plan.contains(" 3:SORT\n" +
" | order by: [20, INT, false] ASC, [2, INT, false] ASC"));
Assert.assertTrue(plan.contains(" 1:PARTITION-TOP-N\n" +
" | partition by: [20: L_COMMENT, INT, false] "));
Assert.assertTrue(plan.contains(" | order by: [20, INT, false] ASC, [2, INT, false] ASC"));
}

@Test
public void testProjectionPredicate() throws Exception {
String sql = "select count(t.a) from(select S_ADDRESS in ('kks', 'kks2') as a from supplier) as t";
Expand Down