[
https://issues.apache.org/jira/browse/CALCITE-7120?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18011640#comment-18011640
]
Julian Hyde commented on CALCITE-7120:
--------------------------------------
Sorry, I missed that the code was in the {{SqlNumericLiteral.createSqlType}}
method. You just said "in there", and I did a grep for the code fragment, and
found the wrong piece of code.
For what it's worth, I think of the {{createSqlType}} method as validator code
even though it lives in an AST class.
Can we shift this conversation to talk about specification, rather than
implementation? I think that would be a more productive framing. (I know that
you have some code that you have written, and solves your problem, that you
would like to get accepted. Apparently I wrote the code, 13 years ago, that you
would like to change, but as you can tell I have forgotten how that code is
structured.)
If I write {code}SELECT 10_000_000_000, 1_000_000, 1_000, 100{code} today, the
column types are {{BIGINT}}, {{INTEGER}}, {{INTEGER}}, {{INTEGER}}. If I
understand correctly, you would like the last two columns to have type
{{SMALLINT}} and {{TINYINT}}. Did I get your requirements correct? If we agree
on requirements, implementation is straightforward.
> Allow SqlNumericLiteral to create more restrictive integer types
> ----------------------------------------------------------------
>
> Key: CALCITE-7120
> URL: https://issues.apache.org/jira/browse/CALCITE-7120
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Steve Carlin
> Priority: Major
>
> It would be nice if SqlNumericLiteral created more restrictive datatypes for
> integers.
> There is already some logic in there that differentiates between INTEGER and
> BIGINT
>
> {code:java}
> if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) {
> result = SqlTypeName.INTEGER;
> } else {
> result = SqlTypeName.BIGINT;
> }
> {code}
> If we can enhance this for TINYINT and SMALLINT, oh how wonderful that would
> be for me.
> Background: Without this, it is causing me to use various workarounds by
> overriding methods that are less than ideal. Upon upgrade from 1.37 to 1.40,
> my current implementation failed. A query such as ...
> "SELECT 1 INTERSECT SELECT tinyint_col FROM my_tbl"
> ... is generating a validated SQLNode tree which casts the tinyint_col to an
> INTEGER (when using type coercing) which causes me issues. (side note, I
> need type coercing enabled for other issues so I can't just turn it off)
> Should we do this via a config option? Putting this in by default will
> probably break a lot of people's code.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)