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

[BugFix] fix concat expr with multiple args nullsFraction #52683

Merged
merged 1 commit into from
Nov 7, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ private ColumnStatistic multiaryExpressionCalculate(CallOperator callOperator,
distinctValues = Math.min(rowCount,
childColumnStatisticList.stream().mapToDouble(ColumnStatistic::getDistinctValuesCount).sum());
averageRowSize = childColumnStatisticList.stream().mapToDouble(ColumnStatistic::getAverageRowSize).sum();
nullsFraction = 1 - childColumnStatisticList.stream().mapToDouble(ColumnStatistic::getAverageRowSize)
.reduce(1, (a, b) -> (1 - a) * (1 - b));
nullsFraction = 1 - childColumnStatisticList.stream().mapToDouble(ColumnStatistic::getNullsFraction)
.reduce(1.0, (accumulator, nullFraction) -> accumulator * (1 - nullFraction));
return new ColumnStatistic(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
nullsFraction, averageRowSize, distinctValues);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

package com.starrocks.sql.optimizer.statistics;

import com.google.common.collect.Lists;
import com.starrocks.analysis.BinaryType;
import com.starrocks.catalog.Type;
import com.starrocks.sql.optimizer.Utils;
import com.starrocks.sql.optimizer.operator.scalar.BinaryPredicateOperator;
import com.starrocks.sql.optimizer.operator.scalar.CallOperator;
import com.starrocks.sql.optimizer.operator.scalar.ColumnRefOperator;
import com.starrocks.sql.optimizer.operator.scalar.CompoundPredicateOperator;
import com.starrocks.sql.optimizer.operator.scalar.ConstantOperator;
Expand Down Expand Up @@ -111,4 +113,18 @@ public void testNullEqStatistic() throws Exception {
Assert.assertEquals(5000, estimatedStatistics.getOutputRowCount(), 0.001);
Assert.assertEquals(1, estimatedStatistics.getColumnStatistic(c1).getNullsFraction(), 0.001);
}

@Test
public void testConcatExpressionCalculate() {
ColumnRefOperator c1 = new ColumnRefOperator(0, Type.VARCHAR, "c1", true);
ConstantOperator c2 = new ConstantOperator("-", Type.VARCHAR);
ColumnRefOperator c3 = new ColumnRefOperator(1, Type.VARCHAR, "c3", true);
CallOperator concat = new CallOperator("concat", Type.VARCHAR, Lists.newArrayList(c1, c2, c3));
Statistics statistics = Statistics.builder()
.addColumnStatistic(c1, ColumnStatistic.builder().setNullsFraction(0.2).setDistinctValuesCount(10).build())
.addColumnStatistic(c3, ColumnStatistic.builder().setNullsFraction(0.4).setDistinctValuesCount(10).build())
.setOutputRowCount(10000).build();
ColumnStatistic estimatedStatistics = ExpressionStatisticCalculator.calculate(concat, statistics);
Assert.assertEquals(0.52, estimatedStatistics.getNullsFraction(), 0.001);
}
}
Loading