[CALCITE-7822] AssertionError "type mismatch" in SqlToRelConverter for OVER () in a GROUP BY query - #5293
Open
kalayciburak wants to merge 1 commit into
Open
[CALCITE-7822] AssertionError "type mismatch" in SqlToRelConverter for OVER () in a GROUP BY query#5293kalayciburak wants to merge 1 commit into
kalayciburak wants to merge 1 commit into
Conversation
…r OVER () in a GROUP BY query A RANGE window without ORDER BY used the FROM item's monotonic column as an implicit sort key. After GROUP BY that column is no longer an input, but its original ordinal still became a RexInputRef, so Project.isValid failed (SMALLINT NOT NULL vs TINYINT). Keep the converted key when its input refs match the current input. Otherwise rebind a simple column by name, or drop the key if GROUP BY removed it. Unbounded RANGE already allows an empty order list.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Jira Link
CALCITE-7822
Changes Proposed
A RANGE window without ORDER BY takes an implicit sort key from the FROM item's monotonic column. After GROUP BY that column is no longer an input, but its original ordinal was still turned into a RexInputRef.
Project.isValidthen failed, for exampleSMALLINT NOT NULL(EMPNO) versusTINYINT(DEPTNO).The converted key is kept when its input refs match the current input. Otherwise a simple column is rebound by name, or dropped if GROUP BY removed it. Unbounded RANGE already allows an empty order list.
select deptno, count(*) over () as c from emp group by deptnoon the scott schema now returnsDEPTNO=10/20/30withC=3. The same shape with an explicit RANGE frame andmax(max(sal)) over ()grouped by job also converts. ROWS framing, an explicit ORDER BY, and GROUP BY of the monotonic column itself are unchanged.Tests
JAVA_HOME=21 ./gradlew :core:test --tests org.apache.calcite.test.JdbcTest.testEmptyOverInAggregateQuery— failed before the fix withAssertionError: type mismatch: ref: SMALLINT NOT NULL input: TINYINT; passed after./gradlew :core:test --tests org.apache.calcite.test.JdbcTest.testWin* --tests org.apache.calcite.test.JdbcTest.testOver* --tests org.apache.calcite.test.SqlToRelConverterTest.testWindow* --tests org.apache.calcite.test.SqlToRelConverterTest.testOver*— 39 completed, 0 failed./gradlew :core:checkstyleMain :core:checkstyleTest— passed