You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "nanjeshramesh (via GitHub)" <gi...@apache.org> on 2026/09/22 08:16:21 UTC

[PR] Accept LONG as an alias for BIGINT in CAST expressions (druid)

nanjeshramesh opened a new pull request, #20402:
URL: https://github.com/apache/druid/pull/20402

   Fixes #17425.
   
   ### Description
   
   People using Druid's native engine write `CAST(x AS LONG)` because `LONG` is the name the native engine uses for its 64-bit integer type. The SQL parser only recognized `BIGINT`, so that CAST failed with a parse error even though `LONG` and `BIGINT` mean the same thing.
   
   #### Accept LONG as an alias for BIGINT
   
   `LONG` is added to the `SqlTypeName1` production in `Parser.jj` alongside `BIGINT`, in the same alternative, so both parse to `SqlTypeName.BIGINT` and behave identically (including the existing `UNSIGNED` suffix handling). No new `ColumnType` or code path is introduced; `CAST(x AS LONG)` is indistinguishable from `CAST(x AS BIGINT)` downstream.
   
   `LONG` is also added to `nonReservedKeywordsToAdd` in `config.fmpp`, following the same pattern already used for `OVERWRITE`, `EXTERN`, `IF`, `PROPERTIES`, `PROJECTION` and `SEALED`. This keeps `LONG` usable unquoted as an ordinary identifier (a column or alias named `long`), so the change is additive only.
   
   #### Release note
   `CAST(x AS LONG)` is now accepted as an alias for `CAST(x AS BIGINT)` in Druid SQL.
   
   <hr>
   
   ##### Key changed/added classes in this PR
   * `sql/src/main/codegen/config.fmpp`
   * `sql/src/main/codegen/templates/Parser.jj`
   
   <hr>
   
   This PR has:
   
   - [x] been self-reviewed.
   - [x] added documentation for new or modified features or behaviors.
   - [x] a release note entry in the PR description.
   - [x] added or updated tests to cover the new code path (`testCountStarWithFilterOnCastAsLong`, `testLongIsUsableAsAnIdentifier` in `CalciteQueryTest`).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] feat: accept LONG as an alias for BIGINT in CAST expressions (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20402:
URL: https://github.com/apache/druid/pull/20402#discussion_r4105064875


##########
docs/querying/sql-data-types.md:
##########
@@ -60,7 +60,7 @@ The following table describes how Druid maps SQL types onto native types when ru
 |TINYINT|LONG|`0`||
 |SMALLINT|LONG|`0`||
 |INTEGER|LONG|`0`||
-|BIGINT|LONG|`0`|Druid LONG columns (except `__time`) are reported as BIGINT|
+|BIGINT|LONG|`0`|Druid LONG columns (except `__time`) are reported as BIGINT. In a `CAST` expression only, for example `CAST(x AS LONG)`, `LONG` is also accepted as an alias for `BIGINT`, matching the name Druid's native engine uses for this type. This does not apply to other type positions, such as a column type in `CREATE TABLE` or `EXTERN`, where `LONG` continues to be treated as any other identifier.|

Review Comment:
   there's no CREATE TABLE in druid.
   
   Druid LONG columns (except `__time`) are reported as BIGINT while LONG is supported only as a CAST alias.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Accept LONG as an alias for BIGINT in CAST expressions (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20402:
URL: https://github.com/apache/druid/pull/20402#discussion_r4071496823


##########
sql/src/main/codegen/templates/Parser.jj:
##########
@@ -6319,7 +6319,7 @@ SqlTypeNameSpec SqlTypeName1(Span s) :
             s.add(this); sqlTypeName = unsigned ? SqlTypeName.USMALLINT : SqlTypeName.SMALLINT;
         }
     |
-        <BIGINT> ( <UNSIGNED> { unsigned = true; })? {
+        ( <BIGINT> | <LONG> ) ( <UNSIGNED> { unsigned = true; })? {

Review Comment:
   [P1] LONG changes existing DDL type parsing
   
   **Finding:** SqlTypeName1 is called by DataType(), not just CAST. Adding <LONG> therefore makes every Druid DDL/type position parse LONG as SqlTypeName.BIGINT. The unchanged DruidSqlDdlParserTest.testColumnNamedProjection currently expects `CREATE TABLE t (projection LONG)` to remain a bare user-defined/native type and render as `projection `LONG``; this head selects the new BIGINT branch instead, breaking that test and changing the AST/unparse contract for existing DDL.
   
   **Suggestion:** Keep LONG scoped to the CAST type grammar, or deliberately widen the type-name contract and update the DDL/EXTEND/other DataType call sites, tests, and documentation together.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] feat: accept LONG as an alias for BIGINT in CAST expressions (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 merged PR #20402:
URL: https://github.com/apache/druid/pull/20402


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] feat: accept LONG as an alias for BIGINT in CAST expressions (druid)

Posted by "nanjeshramesh (via GitHub)" <gi...@apache.org>.
nanjeshramesh commented on PR #20402:
URL: https://github.com/apache/druid/pull/20402#issuecomment-5783166788

   Good catch, thanks both. You are right that `SqlTypeName1` is reached from `DataType()` broadly, not just CAST, and that this broke `testColumnNamedProjection`.
   
   Fixed by reverting the `SqlTypeName1` change and instead recognizing `LONG` only inside the `CAST`/`SAFE_CAST`/`TRY_CAST` production, ahead of `dt = DataType()`, constructing the same `SqlDataTypeSpec`/`BIGINT` node `SqlTypeName1` would have. `LONG` stays in `nonReservedKeywordsToAdd` so it is still usable unquoted as an identifier everywhere, exactly as before this PR.
   
   `DruidSqlDdlParserTest#testColumnNamedProjection` and the rest of `DruidSqlDdlParserTest` (38 tests) now pass unchanged, along with `DruidSqlParserTest` and the CAST/LONG tests in `CalciteQueryTest` (66 tests total). Updated the docs and release note wording to say this is scoped to CAST only, and does not apply to DDL column types, EXTEND, or other type positions, per @kdelay's point about widening vs. scoping — going with scoping down since that is what the issue actually asked for and keeps existing DDL behavior untouched.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] feat: accept LONG as an alias for BIGINT in CAST expressions (druid)

Posted by "nanjeshramesh (via GitHub)" <gi...@apache.org>.
nanjeshramesh commented on PR #20402:
URL: https://github.com/apache/druid/pull/20402#issuecomment-5836379685

   Thanks @FrankChen021, you are right, Druid has no CREATE TABLE. Simplified that docs line to say `LONG` is supported only as a `CAST` alias for `BIGINT`, and updated the PR description, which still described the earlier version of the change.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org