Skip to content

Conversation

@zhan7236
Copy link

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 LONG to the keywords list.
  • Parser.jj: Modified SqlTypeName1 rule to accept LONG as an alias for BIGINT (similar to how INT is an alias for INTEGER).
  • CalciteQueryTest.java: Added test case testCastAsLongAliasBigint() to verify the new functionality.

Testing

  • Added unit test testCastAsLongAliasBigint() that verifies CAST(dim1 AS LONG) = 2 produces the same query plan as CAST(dim1 AS BIGINT) = 2.

Checklist

  • I have read the contribution guidelines
  • My code follows the existing coding style
  • I have added tests that prove my fix is effective
  • This PR is based on the latest master branch

This change allows users to write CAST(x AS LONG) in SQL queries,
which is treated as equivalent to CAST(x AS BIGINT). This is useful
for users migrating from the native engine who are accustomed to
working with LONG types.

Changes:
- Add LONG keyword to the parser configuration
- Modify SqlTypeName1 rule to accept LONG as an alias for BIGINT
- Add test case to verify CAST AS LONG works correctly

Fixes apache#17425
@zhan7236 zhan7236 force-pushed the fix-long-as-bigint-alias branch from a26fd53 to 93486d2 Compare December 3, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle the sql type named LONG

1 participant