druid icon indicating copy to clipboard operation
druid copied to clipboard

Handle the sql type named LONG as an alias for BIGINT

Open zhan7236 opened this issue 1 month ago • 0 comments

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

  • [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

zhan7236 avatar Nov 29 '25 13:11 zhan7236