[CALCITE-5406] Support the SELECT DISTINCT ON statement for PostgreSQL dialect#4933
[CALCITE-5406] Support the SELECT DISTINCT ON statement for PostgreSQL dialect#4933xuzifu666 wants to merge 10 commits into
Conversation
a3d151d to
99a667c
Compare
99a667c to
a5629e3
Compare
|
"DISTINCT ON" is a unique syntax of PGSQL. Would it be more appropriate to implement the parsing support for this function on the babel parser |
Configuring additional keywords, join types, and binary operators in Adding custom parser methods (such as PostgreSQL's Babel itself does not have a separate syntax file; all SELECT-related syntax must be defined in
QUALIFY is a syntax specific to Snowflake, which Calcite implements in the core: The The The Validator/SqlToRelConverter logic is in the core;
The current Parser unconditionally parses This is consistent with the handling of other extensions such as QUALIFY, LATERAL, and TABLESAMPLE: the Parser is as lenient as possible, and the Validator decides whether to allow based on the dialect. so in my view:The current implementation conforms to Calcite's architectural conventions and does not require migration to Babel. For adjustments, finer-grained switches can be added to SqlConformance to control the availability of DISTINCT ON. By the way: Besides PG, ClickHouse also supports DISTINCT ON. |
|
I attempted to verify this across several databases (though my testing may not have been exhaustive) and indeed found that only PostgreSQL supports this syntax; furthermore, |
Good suggestion, I had add a config to control it in babel. |
| "parserImpls.ftl" | ||
| ] | ||
|
|
||
| includeDistinctOn: true |
There was a problem hiding this comment.
It seems like there’s a better place for this parameter.
There was a problem hiding this comment.
Would it be better to add a test case similar to "SELECT DISTINCT ON (deptno)" here? I tried executing "SELECT DISTINCT ON (deptno)" and it didn't generate any error
There was a problem hiding this comment.
OK, I had added related test cases in SqlParserTest.java.
There was a problem hiding this comment.
Perhaps it's a problem with my input method. I intended to add"SELECT DISTINCTON (deptno) empno" and "SELECT DISTINCT ON(deptno) empno". Scenarios like this, where text is written consecutively, should normally result in an error. However, the outcomes of the two situations I executed did not meet my expectations.
https://www.postgresql.org/docs/current/queries-select-lists.html#QUERIES-DISTINCT
There was a problem hiding this comment.
As far as I know, distinct on needs to be followed by an order by statement.
There was a problem hiding this comment.
As far as I know,
distinct onneeds to be followed by anorder bystatement.
Perhaps I should elaborate and add test cases similar to "SELECT DISTINCTON (deptno) empno, ename FROM emp ORDER BY deptno, empno"
|



jira: https://issues.apache.org/jira/browse/CALCITE-5406