diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/logical/LogicalTableFunctionOperator.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/logical/LogicalTableFunctionOperator.java index b3b1fca8dc0ab..5e1d100074eb1 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/logical/LogicalTableFunctionOperator.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/logical/LogicalTableFunctionOperator.java @@ -122,8 +122,6 @@ public DomainProperty deriveDomainProperty(List inputs) { return inputs.get(0).getDomainProperty(); } - - @Override public R accept(OperatorVisitor visitor, C context) { return visitor.visitLogicalTableFunction(this, context); diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java index b953b3ff4824a..367321a4ff5b4 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java @@ -1447,11 +1447,17 @@ public Void visitPhysicalTableFunction(PhysicalTableFunctionOperator node, Expre private Void computeTableFunctionNode(ExpressionContext context, List outputColumns) { Statistics.Builder builder = Statistics.builder(); + Statistics inputStatistics = context.getChildStatistics(0); + Map 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()); diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/plan/UDFTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/plan/UDFTest.java index bf129fef6b511..fed07c63ab8b6 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/plan/UDFTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/plan/UDFTest.java @@ -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();