Skip to content

Commit

Permalink
[Enhancement] make LIKE operations' statistics consistent (#55023)
Browse files Browse the repository at this point in the history
Signed-off-by: Elmi Ahmadov <[email protected]>
(cherry picked from commit 6085037)
  • Loading branch information
ahmadov authored and mergify[bot] committed Feb 7, 2025
1 parent 360fcef commit b079868
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,12 @@ private ColumnStatistic binaryExpressionCalculate(CallOperator callOperator, Col
averageRowSize = Math.max(1, left.getAverageRowSize() - right.getAverageRowSize());
distinctValues = left.getDistinctValuesCount() * averageRowSize / left.getAverageRowSize();
break;
case FunctionSet.LIKE:
case FunctionSet.ILIKE:
minValue = 0;
maxValue = 1;
distinctValues = 2;
break;
default:
return ColumnStatistic.unknown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,18 @@ public void testBinaryFunctionCall() {
columnStatistic = ExpressionStatisticCalculator.calculate(callOperator, builder.build());
Assert.assertEquals(-1, columnStatistic.getMinValue(), 0.001);
Assert.assertEquals(1, columnStatistic.getMaxValue(), 0.001);

callOperator = new CallOperator(FunctionSet.LIKE, Type.BOOLEAN, Lists.newArrayList(left, right));
columnStatistic = ExpressionStatisticCalculator.calculate(callOperator, builder.build());
Assert.assertEquals(0, columnStatistic.getMinValue(), 0.001);
Assert.assertEquals(1, columnStatistic.getMaxValue(), 0.001);
Assert.assertEquals(2, columnStatistic.getDistinctValuesCount(), 0.001);

callOperator = new CallOperator(FunctionSet.ILIKE, Type.BOOLEAN, Lists.newArrayList(left, right));
columnStatistic = ExpressionStatisticCalculator.calculate(callOperator, builder.build());
Assert.assertEquals(0, columnStatistic.getMinValue(), 0.001);
Assert.assertEquals(1, columnStatistic.getMaxValue(), 0.001);
Assert.assertEquals(2, columnStatistic.getDistinctValuesCount(), 0.001);
// test multiply/divide column rang is negative
builder = Statistics.builder();
leftStatistic = new ColumnStatistic(-100, -10, 0, 0, 20);
Expand Down

0 comments on commit b079868

Please sign in to comment.