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

[CALCITE-6830] AVG() returns double precision by default when its argument type is INT_TYPES #4193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -363,7 +363,12 @@ && getDefaultPrecision(typeName) != RelDataType.PRECISION_NOT_SPECIFIED) {

@Override public RelDataType deriveAvgAggType(RelDataTypeFactory typeFactory,
RelDataType argumentType) {
return argumentType;
if (SqlTypeName.INT_TYPES.contains(argumentType.getSqlTypeName())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type system is actually pluggable. See feldera/feldera#3588 for the right way to do this. We should not change RelDataTypeSystemImpl.

return typeFactory.createTypeWithNullability(
typeFactory.createSqlType(SqlTypeName.DOUBLE), false);
} else {
return argumentType;
}
}

@Override public RelDataType deriveCovarType(RelDataTypeFactory typeFactory,
Expand Down
12 changes: 6 additions & 6 deletions core/src/test/java/org/apache/calcite/test/JdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4015,7 +4015,7 @@ public void checkOrderBy(final boolean desc,
+ "from \"hr\".\"emps\"\n"
+ "where \"deptno\" < 0")
.explainContains(""
+ "PLAN=EnumerableCalc(expr#0..1=[{inputs}], expr#2=[0], expr#3=[=($t0, $t2)], expr#4=[null:JavaType(class java.lang.Integer)], expr#5=[CASE($t3, $t4, $t1)], expr#6=[/($t5, $t0)], expr#7=[CAST($t6):JavaType(class java.lang.Integer)], CS=[$t0], C=[$t0], S=[$t5], A=[$t7])\n"
+ "PLAN=EnumerableCalc(expr#0..1=[{inputs}], expr#2=[0], expr#3=[=($t0, $t2)], expr#4=[null:JavaType(class java.lang.Integer)], expr#5=[CASE($t3, $t4, $t1)], expr#6=[CAST($t5):DOUBLE], expr#7=[/($t6, $t0)], CS=[$t0], C=[$t0], S=[$t5], A=[$t7])\n"
+ " EnumerableAggregate(group=[{}], CS=[COUNT()], S=[$SUM0($1)])\n"
+ " EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[<($t1, $t5)], proj#0..4=[{exprs}], $condition=[$t6])\n"
+ " EnumerableTableScan(table=[[hr, emps]])\n")
Expand Down Expand Up @@ -4448,12 +4448,12 @@ private void startOfGroupStep3(String startOfGroup) {
+ ") t\n"
+ ") group by group_id\n")
.typeIs(
"[GROUP_ID INTEGER NOT NULL, MIN_RN INTEGER NOT NULL, MAX_RN INTEGER NOT NULL, CNT_RN BIGINT NOT NULL, AVG_VAL INTEGER NOT NULL]")
"[GROUP_ID INTEGER NOT NULL, MIN_RN INTEGER NOT NULL, MAX_RN INTEGER NOT NULL, CNT_RN BIGINT NOT NULL, AVG_VAL DOUBLE NOT NULL]")
.returnsUnordered(
"GROUP_ID=1; MIN_RN=1; MAX_RN=2; CNT_RN=2; AVG_VAL=0",
"GROUP_ID=2; MIN_RN=3; MAX_RN=3; CNT_RN=1; AVG_VAL=1",
"GROUP_ID=3; MIN_RN=4; MAX_RN=6; CNT_RN=3; AVG_VAL=0",
"GROUP_ID=4; MIN_RN=7; MAX_RN=8; CNT_RN=2; AVG_VAL=1");
"GROUP_ID=1; MIN_RN=1; MAX_RN=2; CNT_RN=2; AVG_VAL=0.0",
"GROUP_ID=2; MIN_RN=3; MAX_RN=3; CNT_RN=1; AVG_VAL=1.0",
"GROUP_ID=3; MIN_RN=4; MAX_RN=6; CNT_RN=3; AVG_VAL=0.0",
"GROUP_ID=4; MIN_RN=7; MAX_RN=8; CNT_RN=2; AVG_VAL=1.0");
}

/**
Expand Down
58 changes: 29 additions & 29 deletions core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,8 @@ and e1.sal > (select avg(e2.sal) from emp e2
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], DEPTNO1=[CAST($11):INTEGER], $f1=[CAST($12):INTEGER])
LogicalJoin(condition=[AND(=($9, $11), >($5, $12))], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], DEPTNO1=[CAST($11):INTEGER], $f1=[CAST($12):DOUBLE])
LogicalJoin(condition=[AND(=($9, $11), >(CAST($5):DOUBLE NOT NULL, $12))], joinType=[inner])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
Expand Down Expand Up @@ -1365,8 +1365,8 @@ and e1.sal > (select avg(e2.sal) from emp e2
<![CDATA[
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], DEPTNO1=[CAST($11):INTEGER], EXPR$0=[CAST($12):INTEGER])
LogicalJoin(condition=[AND(=($9, $11), >($5, $12))], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], DEPTNO1=[CAST($11):INTEGER], EXPR$0=[CAST($12):DOUBLE])
LogicalJoin(condition=[AND(=($9, $11), >(CAST($5):DOUBLE NOT NULL, $12))], joinType=[inner])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
Expand Down Expand Up @@ -1409,8 +1409,8 @@ and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)]]>
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], EMPNO0=[CAST($11):INTEGER], EXPR$0=[CAST($12):INTEGER])
LogicalJoin(condition=[AND(=($0, $11), >($5, $12))], joinType=[inner])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], EMPNO0=[CAST($11):INTEGER], EXPR$0=[CAST($12):DOUBLE])
LogicalJoin(condition=[AND(=($0, $11), >(CAST($5):DOUBLE NOT NULL, $12))], joinType=[inner])
LogicalJoin(condition=[=($7, $9)], joinType=[inner])
LogicalFilter(condition=[<($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
Expand All @@ -1432,7 +1432,7 @@ and e1.sal > (select avg(sal) from emp e2 where e1.empno = e2.empno)]]>
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0])
LogicalFilter(condition=[AND(=($7, $9), <($7, 10), <($9, 15), >($5, $SCALAR_QUERY({
LogicalFilter(condition=[AND(=($7, $9), <($7, 10), <($9, 15), >(CAST($5):DOUBLE NOT NULL, $SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[AVG($0)])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[=($cor0.EMPNO, $0)])
Expand Down Expand Up @@ -2940,8 +2940,8 @@ LogicalProject(DEPTNO=[$7])
<Resource name="planExpanded">
<![CDATA[
LogicalProject(DEPTNO=[$9], SAL=[$7])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10], DEPTNO1=[CAST($11):INTEGER], EXPR$0=[CAST($12):INTEGER])
LogicalJoin(condition=[AND(=($0, $11), <($7, $12))], joinType=[inner])
LogicalProject(DEPTNO=[$0], NAME=[$1], EMPNO=[$2], ENAME=[$3], JOB=[$4], MGR=[$5], HIREDATE=[$6], SAL=[$7], COMM=[$8], DEPTNO0=[$9], SLACKER=[$10], DEPTNO1=[CAST($11):INTEGER], EXPR$0=[CAST($12):DOUBLE])
LogicalJoin(condition=[AND(=($0, $11), <(CAST($7):DOUBLE NOT NULL, $12))], joinType=[inner])
LogicalJoin(condition=[=($9, $0)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
Expand All @@ -2953,7 +2953,7 @@ LogicalProject(DEPTNO=[$9], SAL=[$7])
<Resource name="planNotExpanded">
<![CDATA[
LogicalProject(DEPTNO=[$9], SAL=[$7])
LogicalFilter(condition=[AND(=($9, $0), <($7, $SCALAR_QUERY({
LogicalFilter(condition=[AND(=($9, $0), <(CAST($7):DOUBLE NOT NULL, $SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[AVG($0)])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
Expand Down Expand Up @@ -3584,7 +3584,7 @@ from (values (cast(null as int), 1),
<Resource name="planExpanded">
<![CDATA[
LogicalProject(DEPTNO=[$9], SAL=[$7])
LogicalJoin(condition=[AND(=($9, $0), <($7, $0))], joinType=[inner])
LogicalJoin(condition=[AND(=($9, $0), <(CAST($7):DOUBLE NOT NULL, $0))], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EXPR$0=[$10])
LogicalJoin(condition=[=($0, $9)], joinType=[left])
Expand All @@ -3597,7 +3597,7 @@ LogicalProject(DEPTNO=[$9], SAL=[$7])
<Resource name="planNotExpanded">
<![CDATA[
LogicalProject(DEPTNO=[$9], SAL=[$7])
LogicalJoin(condition=[AND(=($9, $0), <($7, $SCALAR_QUERY({
LogicalJoin(condition=[AND(=($9, $0), <(CAST($7):DOUBLE NOT NULL, $SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[AVG($0)])
LogicalProject(SAL=[$5])
LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
Expand Down Expand Up @@ -4051,7 +4051,7 @@ LogicalProject(DEPTNO=[$9], SAL=[$7])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
LogicalJoin(condition=[true], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EXPR$0=[>($0, 0)])
LogicalProject(EXPR$0=[>($0, 0.0E0)])
LogicalAggregate(group=[{}], agg#0=[AVG($0)])
LogicalProject(SAL=[$5])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
Expand Down Expand Up @@ -5103,7 +5103,7 @@ group by deptno]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EXPR$0=[CAST(/(SUM(+(+($1, *(2, $2)), *(3, $3))) OVER (PARTITION BY $0), COUNT(+(+($1, *(2, $2)), *(3, $3))) OVER (PARTITION BY $0))):INTEGER NOT NULL])
LogicalProject(EXPR$0=[/(SUM(+(+($1, *(2, $2)), *(3, $3))) OVER (PARTITION BY $0), COUNT(+(+($1, *(2, $2)), *(3, $3))) OVER (PARTITION BY $0))])
LogicalAggregate(group=[{0}], agg#0=[SUM($1)], agg#1=[MIN($2)], agg#2=[AVG($2)])
LogicalProject(DEPTNO=[$7], SAL=[$5], EMPNO=[$0])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
Expand Down Expand Up @@ -6042,7 +6042,7 @@ LogicalSort(sort0=[$1], dir0=[ASC])
<TestCase name="testOverAvg">
<Resource name="plan">
<![CDATA[
LogicalProject(EXPR$0=[CASE(>(COUNT($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), 0), SUM($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), null:INTEGER)], EXPR$1=[CAST(/(CASE(>(COUNT($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), 0), SUM($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), null:INTEGER), COUNT($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING))):INTEGER])
LogicalProject(EXPR$0=[CASE(>(COUNT($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), 0), SUM($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), null:INTEGER)], EXPR$1=[/(CAST(CASE(>(COUNT($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), 0), SUM($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING), null:INTEGER)):DOUBLE, COUNT($5) OVER (PARTITION BY $2 ORDER BY $4 ROWS 2 PRECEDING))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand Down Expand Up @@ -9534,7 +9534,7 @@ group by deptno]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EXPR$0=[CAST(/(SUM($0) OVER (), COUNT($0) OVER ())):INTEGER NOT NULL])
LogicalProject(EXPR$0=[/(CAST(SUM($0) OVER ()):DOUBLE NOT NULL, COUNT($0) OVER ())])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
Expand Down
53 changes: 32 additions & 21 deletions core/src/test/resources/sql/agg.iq
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ from (select deptno, count(*) from emp group by deptno);

!ok

# [CALCITE-6830] AVG aggregation with integer argument type should return double
SELECT avg(deptno) as a FROM emp;
+------+
| A |
+------+
| 32.5 |
+------+
(1 row)

!ok

# [CALCITE-6557] AggregateMergeRule throws 'type mismatch' AssertionError
#
# The scenario has the same aggregate function (SUM) at multiple levels; the
Expand All @@ -168,11 +179,11 @@ FROM (
# [CALCITE-998] Exception when calling STDDEV_SAMP, STDDEV_POP
# stddev_samp
select stddev_samp(deptno) as s from emp;
+----+
| S |
+----+
| 19 |
+----+
+--------------------+
| S |
+--------------------+
| 19.086270308410555 |
+--------------------+
(1 row)

!ok
Expand Down Expand Up @@ -201,22 +212,22 @@ select some(deptno > 100), every(deptno > 0) from emp where deptno > 1000;

# stddev_pop
select stddev_pop(deptno) as s from emp;
+----+
| S |
+----+
| 17 |
+----+
+--------------------+
| S |
+--------------------+
| 17.853571071357123 |
+--------------------+
(1 row)

!ok

# stddev
select stddev(deptno) as s from emp;
+----+
| S |
+----+
| 19 |
+----+
+--------------------+
| S |
+--------------------+
| 19.086270308410555 |
+--------------------+
(1 row)

!ok
Expand All @@ -229,12 +240,12 @@ select gender,
count(deptno) as c
from emp
group by gender;
+--------+----+----+----+---+
| GENDER | P | S | SS | C |
+--------+----+----+----+---+
| F | 17 | 19 | 19 | 5 |
| M | 17 | 20 | 20 | 3 |
+--------+----+----+----+---+
+--------+--------------------+--------------------+--------------------+---+
| GENDER | P | S | SS | C |
+--------+--------------------+--------------------+--------------------+---+
| F | 17.435595774162696 | 19.493588689617926 | 19.493588689617926 | 5 |
| M | 16.996731711975947 | 20.816659994661325 | 20.816659994661325 | 3 |
+--------+--------------------+--------------------+--------------------+---+
(2 rows)

!ok
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/resources/sql/measure-paper.iq
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ GROUP BY o."prodName";
+----------+----------------+--------+
| prodName | weightedAvgAge | avgAge |
+----------+----------------+--------+
| Acme | 41 | 41 |
| Happy | 29 | 32 |
| Whizz | 17 | 17 |
| Acme | 41.0 | 41.0 |
| Happy | 29.0 | 32.0 |
| Whizz | 17.0 | 17.0 |
+----------+----------------+--------+
(3 rows)

Expand Down
10 changes: 5 additions & 5 deletions core/src/test/resources/sql/measure.iq
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ GROUP BY job;
+-----------+-----------+
| JOB | AVG_EMPNO |
+-----------+-----------+
| ANALYST | 7845 |
| CLERK | 7769 |
| MANAGER | 7682 |
| PRESIDENT | 7839 |
| SALESMAN | 7629 |
| ANALYST | 7845.0 |
| CLERK | 7769.75 |
| MANAGER | 7682.0 |
| PRESIDENT | 7839.0 |
| SALESMAN | 7629.5 |
+-----------+-----------+
(5 rows)

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/sql/unnest.iq
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ FROM UNNEST(array [0, 2, 4, 4, 5]) as x;
+-----+
| avg |
+-----+
| 3 |
| 3.0 |
+-----+
(1 row)

Expand Down
18 changes: 9 additions & 9 deletions core/src/test/resources/sql/winagg.iq
Original file line number Diff line number Diff line change
Expand Up @@ -852,15 +852,15 @@ select emps."AGE", emps."DEPTNO", emps."GENDER",
var_samp(emps."AGE") over() as "var_samp",
var_samp(emps."AGE") over(partition by emps."GENDER") as "var_samp by gender"
from emps order by emps."AGE";
+-----+--------+--------+---------+----------------+----------+--------------------+
| AGE | DEPTNO | GENDER | var_pop | var_pop by age | var_samp | var_samp by gender |
+-----+--------+--------+---------+----------------+----------+--------------------+
| 5 | 20 | F | 1005 | 0 | 1508 | |
| 25 | 10 | | 1005 | 0 | 1508 | |
| 80 | 20 | M | 1005 | 0 | 1508 | |
| | 40 | F | 1005 | | 1508 | |
| | 40 | M | 1005 | | 1508 | |
+-----+--------+--------+---------+----------------+----------+--------------------+
+-----+--------+--------+--------------------+----------------+--------------------+--------------------+
| AGE | DEPTNO | GENDER | var_pop | var_pop by age | var_samp | var_samp by gender |
+-----+--------+--------+--------------------+----------------+--------------------+--------------------+
| 5 | 20 | F | 1005.5555555555555 | 0.0 | 1508.3333333333333 | 0.0 |
| 25 | 10 | | 1005.5555555555555 | 0.0 | 1508.3333333333333 | 0.0 |
| 80 | 20 | M | 1005.5555555555555 | 0.0 | 1508.3333333333333 | 0.0 |
| | 40 | F | 1005.5555555555555 | 0.0 | 1508.3333333333333 | 0.0 |
| | 40 | M | 1005.5555555555555 | 0.0 | 1508.3333333333333 | 0.0 |
+-----+--------+--------+--------------------+----------------+--------------------+--------------------+
(5 rows)

!ok
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/resources/sql/within-distinct.iq
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ FROM FriendStates;
+------+-----+
| AA_S | C_S |
+------+-----+
| 25 | 1 |
| 25.0 | 1 |
+------+-----+
(1 row)

Expand All @@ -933,7 +933,7 @@ FROM FriendStates;
+------+-----+
| AA_S | C_S |
+------+-----+
| 25 | 2 |
| 25.0 | 2 |
+------+-----+
(1 row)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ private void checkGroupBySingleSortLimit(boolean approx) {
+ "order by 1";
sql(sql)
.limit(2)
.returnsUnordered("state_province=CA; A=3; S=74748; C=16347; C0=24441",
.returnsUnordered("state_province=CA; A=3.0583036700625996; S=74748; C=16347; C0=24441",
"state_province=OR; A=3; S=67659; C=21610; C0=21610")
.explainContains("PLAN=EnumerableInterpreter\n"
+ " BindableProject(state_province=[$0], A=[/(CASE(=($2, 0), null:BIGINT, $1), $2)], "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ private void checkGroupBySingleSortLimit(boolean approx) {
+ "order by 1";
sql(sql)
.limit(2)
.returnsUnordered("state_province=CA; A=3; S=74748; C=16347; C0=24441",
.returnsUnordered("state_province=CA; A=3.0583036700625996; S=74748; C=16347; C0=24441",
"state_province=OR; A=3; S=67659; C=21610; C0=21610")
.explainContains("PLAN=EnumerableInterpreter\n"
+ " BindableProject(state_province=[$0], A=[/(CASE(=($2, 0), null:BIGINT, $1), $2)], "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ private static Consumer<ResultSet> sortedResultSetChecker(String column,

calciteAssert()
.query("select count(*), max(pop), min(pop), sum(pop), avg(pop) from zips")
.returns("EXPR$0=149; EXPR$1=112047; EXPR$2=21; EXPR$3=7865489; EXPR$4=52788\n");
.returns("EXPR$0=149; EXPR$1=112047; EXPR$2=21; EXPR$3=7865489;"
+ " EXPR$4=52788.51677852349\n");
}

@Test void groupBy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private CalciteAssert.AssertThat assertModel(URL url) {
.query(
"select state, avg(pop) as a from zips group by state order by state")
.limit(2)
.returns("STATE=AK; A=26856\nSTATE=AL; A=43383\n")
.returns("STATE=AK; A=26856.0\nSTATE=AL; A=43383.666666666664\n")
.queryContains(
mongoChecker(
"{$project: {STATE: '$state', POP: '$pop'}}",
Expand All @@ -473,8 +473,8 @@ private CalciteAssert.AssertThat assertModel(URL url) {
.query(
"select state, avg(pop) as a, sum(pop) as s, count(pop) as c from zips group by state order by state")
.limit(2)
.returns("STATE=AK; A=26856; S=80568; C=3\n"
+ "STATE=AL; A=43383; S=130151; C=3\n")
.returns("STATE=AK; A=26856.0; S=80568; C=3\n"
+ "STATE=AL; A=43383.666666666664; S=130151; C=3\n")
.queryContains(
mongoChecker(
"{$project: {STATE: '$state', POP: '$pop'}}",
Expand Down Expand Up @@ -836,6 +836,6 @@ private static Consumer<List> mongoChecker(final String... expected) {
+ "group by \"STATE\" "
+ "order by \"AVG(pop)\"")
.limit(2)
.returns("STATE=VT; AVG(pop)=26408\nSTATE=AK; AVG(pop)=26856\n");
.returns("STATE=VT; AVG(pop)=26408.333333333332\nSTATE=AK; AVG(pop)=26856.0\n");
}
}
Loading
Loading