druid
druid copied to clipboard
Handle the sql type named LONG as an alias for BIGINT
Description
This PR adds support for using LONG as an alias for BIGINT in SQL CAST expressions. Users who are familiar with Druid's native engine often use LONG as a type name, but the SQL parser previously did not recognize it, resulting in an error.
After this change, the following SQL will work correctly:
SELECT CAST(column_name AS LONG) FROM table
This is equivalent to:
SELECT CAST(column_name AS BIGINT) FROM table
Motivation
People using the native engine may write CAST(some AS LONG) because they are accustomed to working with those types. However, the SQL parser didn't know that type and returned an error. This change handles LONG as an alias to BIGINT for better user experience.
Fixes #17425
Changes
- config.fmpp: Added
LONGto the keywords list. - Parser.jj: Modified
SqlTypeName1rule to acceptLONGas an alias forBIGINT(similar to howINTis an alias forINTEGER). - CalciteQueryTest.java: Added test case
testCastAsLongAliasBigint()to verify the new functionality.
Testing
- Added unit test
testCastAsLongAliasBigint()that verifiesCAST(dim1 AS LONG) = 2produces the same query plan asCAST(dim1 AS BIGINT) = 2.
Checklist
- [x] I have read the contribution guidelines
- [x] My code follows the existing coding style
- [x] I have added tests that prove my fix is effective
- [x] This PR is based on the latest master branch