Skip to content

Commit

Permalink
[Enhancement] reuse column stats on TableFunctionNode (#53812)
Browse files Browse the repository at this point in the history
Signed-off-by: stephen <[email protected]>
  • Loading branch information
stephen-shelby authored Dec 12, 2024
1 parent b035941 commit c51814d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ public DomainProperty deriveDomainProperty(List<OptExpression> inputs) {
return inputs.get(0).getDomainProperty();
}



@Override
public <R, C> R accept(OperatorVisitor<R, C> visitor, C context) {
return visitor.visitLogicalTableFunction(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1447,11 +1447,17 @@ public Void visitPhysicalTableFunction(PhysicalTableFunctionOperator node, Expre
private Void computeTableFunctionNode(ExpressionContext context, List<ColumnRefOperator> outputColumns) {
Statistics.Builder builder = Statistics.builder();

Statistics inputStatistics = context.getChildStatistics(0);
Map<ColumnRefOperator, ColumnStatistic> columnStats = inputStatistics.getColumnStatistics();

for (ColumnRefOperator col : outputColumns) {
builder.addColumnStatistic(col, ColumnStatistic.unknown());
if (columnStats.containsKey(col)) {
builder.addColumnStatistic(col, columnStats.get(col));
} else {
builder.addColumnStatistic(col, ColumnStatistic.unknown());
}
}

Statistics inputStatistics = context.getChildStatistics(0);
builder.setOutputRowCount(inputStatistics.getOutputRowCount());

context.setStatistics(builder.build());
Expand Down
5 changes: 4 additions & 1 deletion fe/fe-core/src/test/java/com/starrocks/sql/plan/UDFTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ public void testUDTF() throws Exception {
@Test
public void testMultiUnnest() throws Exception {
String sql = "with t as (select [1,2,3] as a, [4,5,6] as b, [4,5,6] as c) select * from t,unnest(a,b,c)";
PhysicalTableFunctionOperator tp = (PhysicalTableFunctionOperator) getExecPlan(sql).getPhysicalPlan().getOp();
ExecPlan execPlan = getExecPlan(sql);
PhysicalTableFunctionOperator tp = (PhysicalTableFunctionOperator) execPlan.getPhysicalPlan().getOp();

Assert.assertEquals(3, tp.getFnParamColumnRefs().size());
Assert.assertEquals("[8, 9, 10]",
tp.getFnParamColumnRefs().stream().map(ColumnRefOperator::getId).collect(Collectors.toList()).toString());
Assert.assertTrue(execPlan.getOptExpression(2).getStatistics().getColumnStatistics().values()
.stream().anyMatch(x -> !x.isUnknown()));

sql = "select * from tarray, unnest(v3, v3)";
tp = (PhysicalTableFunctionOperator) getExecPlan(sql).getPhysicalPlan().getOp();
Expand Down

0 comments on commit c51814d

Please sign in to comment.