Skip to content
Closed
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 @@ -457,9 +457,8 @@ private boolean expandSelectItem(
selectItems.add(expanded);
aliases.add(alias);

if (expanded != null) {
inferUnknownTypes(targetType, scope, expanded);
}
inferUnknownTypes(targetType, selectScope, expanded);

RelDataType type = deriveType(selectScope, expanded);
// Re-derive SELECT ITEM's data type that may be nullable in AggregatingSelectScope when it
// appears in advanced grouping elements such as CUBE, ROLLUP , GROUPING SETS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7293,6 +7293,13 @@ public boolean isBangEqualAllowed() {
+ "group by rollup(empno), deptno")
.ok()
.type("RecordType(INTEGER NOT NULL DEPTNO, INTEGER EMPNO) NOT NULL");

// empno becomes NULL because it is rolled up, and so does empno + 1.
sql("select empno, empno + 1 as e1\n"
+ "from emp\n"
+ "group by rollup(empno)")
.ok()
.type("RecordType(INTEGER EMPNO, INTEGER E1) NOT NULL");
}

@Test void testGroupByCorrelatedColumn() {
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/resources/sql/agg.iq
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,24 @@ having count(*) > 3;

!ok

# ROLLUP column used in expression; see [CALCITE-5296]
# In a query with ROLLUP, validator wrongly infers that a column is NOT NULL
select deptno, deptno + 1 as d1 from emp group by rollup(deptno);
+--------+----+
| DEPTNO | D1 |
+--------+----+
| 10 | 11 |
| 20 | 21 |
| 30 | 31 |
| 50 | 51 |
| 60 | 61 |
| | |
| | |
+--------+----+
(7 rows)

!ok

# CUBE and DISTINCT
select distinct count(*) from emp group by cube(deptno, gender);
+--------+
Expand Down