Skip to content

Commit

Permalink
[CALCITE-6547] Result type inferred for STDDEV_SAMP is incorrect
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
  • Loading branch information
mihaibudiu committed Aug 27, 2024
1 parent 1a18264 commit a19bb82
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,8 @@ private static RelDataType multivalentStringWithSepSumPrecision(
final RelDataType relDataType =
typeFactory.getTypeSystem().deriveAvgAggType(typeFactory,
opBinding.getOperandType(0));
if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) {
if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()
|| opBinding.getOperator().kind == SqlKind.STDDEV_SAMP) {
return typeFactory.createTypeWithNullability(relDataType, true);
} else {
return relDataType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], EXPR$2=[AVG($1)], EXPR$3=
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[CAST(POWER(/(-($1, /(*($2, $2), $3)), $3), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[CAST(POWER(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1))), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$4=[CAST(/(-($1, /(*($2, $2), $3)), $3)):INTEGER NOT NULL], EXPR$5=[CAST(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1)))):INTEGER NOT NULL])
LogicalProject(NAME=[$0], EXPR$1=[CAST(POWER(/(-($1, /(*($2, $2), $3)), $3), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[CAST(POWER(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1))), 0.5:DECIMAL(2, 1))):INTEGER], EXPR$4=[CAST(/(-($1, /(*($2, $2), $3)), $3)):INTEGER NOT NULL], EXPR$5=[CAST(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1)))):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($2)], agg#1=[$SUM0($1)], agg#2=[COUNT()])
LogicalProject(NAME=[$0], DEPTNO=[$1], $f2=[*($1, $1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
Expand Down Expand Up @@ -12133,7 +12133,7 @@ LogicalAggregate(group=[{0}], EXPR$1=[STDDEV_POP($1)], EXPR$2=[AVG($1)], EXPR$3=
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(NAME=[$0], EXPR$1=[CAST(POWER(/(-($1, /(*($2, $2), $3)), $3), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[CAST(POWER(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1))), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$4=[CAST(/(-($1, /(*($2, $2), $3)), $3)):INTEGER NOT NULL], EXPR$5=[CAST(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1)))):INTEGER NOT NULL])
LogicalProject(NAME=[$0], EXPR$1=[CAST(POWER(/(-($1, /(*($2, $2), $3)), $3), 0.5:DECIMAL(2, 1))):INTEGER NOT NULL], EXPR$2=[CAST(/($2, $3)):INTEGER NOT NULL], EXPR$3=[CAST(POWER(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1))), 0.5:DECIMAL(2, 1))):INTEGER], EXPR$4=[CAST(/(-($1, /(*($2, $2), $3)), $3)):INTEGER NOT NULL], EXPR$5=[CAST(/(-($1, /(*($2, $2), $3)), CASE(=($3, 1), null:BIGINT, -($3, 1)))):INTEGER NOT NULL])
LogicalAggregate(group=[{0}], agg#0=[$SUM0($2)], agg#1=[$SUM0($1)], agg#2=[COUNT()])
LogicalProject(NAME=[$0], DEPTNO=[$1], $f2=[*($1, $1)])
LogicalProject(NAME=[$1], DEPTNO=[$0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14897,7 +14897,7 @@ void testTimestampDiff(boolean coercionEnabled) {
false);
f.checkType("stddev_samp(cast(null as varchar(2)))", "DECIMAL(19, 9)");
f.checkType("stddev_samp(CAST(NULL AS INTEGER))", "INTEGER");
f.checkAggType("stddev_samp(DISTINCT 1.5)", "DECIMAL(2, 1) NOT NULL");
f.checkAggType("stddev_samp(DISTINCT 1.5)", "DECIMAL(2, 1)");
final String[] values = {"0", "CAST(null AS FLOAT)", "3", "3"};
if (f.brokenTestsEnabled()) {
// verified on Oracle 10g
Expand Down Expand Up @@ -14929,7 +14929,7 @@ void testTimestampDiff(boolean coercionEnabled) {
false);
f.checkType("stddev(cast(null as varchar(2)))", "DECIMAL(19, 9)");
f.checkType("stddev(CAST(NULL AS INTEGER))", "INTEGER");
f.checkAggType("stddev(DISTINCT 1.5)", "DECIMAL(2, 1) NOT NULL");
f.checkAggType("stddev(DISTINCT 1.5)", "DECIMAL(2, 1)");
// with one value
f.checkAgg("stddev(x)", new String[]{"5"}, isNullValue());
// with zero values
Expand Down

0 comments on commit a19bb82

Please sign in to comment.