[
https://issues.apache.org/jira/browse/CALCITE-7120?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18011611#comment-18011611
]
Steve Carlin edited comment on CALCITE-7120 at 8/2/25 4:58 PM:
---------------------------------------------------------------
I suppose if we really wanted to enhance this, we should make this configurable.
But some of it just seems common sense. We already have precedence for this.
To me, it seems common sense that the following code which already does this:
if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) {
result = SqlTypeName.INTEGER;
} else {
result = SqlTypeName.BIGINT;
}
should have looked like this.
if ((l >= Byte.MIN_VALUE) && (l <= Byte.MAX_VALUE))
{ result = SqlTypeName.TINYINT; }
else if ((l >= Short.MIN_VALUE) && (l <= Short.MAX_VALUE))
{ result = SqlTypeName.SMALLINT; }
else if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) {
result = SqlTypeName.INTEGER;
} else {
result = SqlTypeName.BIGINT;
}
This is causing me great pain as/is with my current code.
I understand this will break things, which is why I think this should be a
configurable option.
was (Author: scarlin):
I suppose if we really wanted to enhance this, we should make this configurable.
But some of it just seems common sense. We already have precedence for this.
To me, it seems common sense that the following code which already does this:
if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) \{
result = SqlTypeName.INTEGER;
} else \{
result = SqlTypeName.BIGINT;
}
should have looked like this.
if ((l >= Byte.MIN_VALUE) && (l <= Byte.MAX_VALUE)) {
result = SqlTypeName.TINYINT;
} else if ((l >= Short.MIN_VALUE) && (l <= Short.MAX_VALUE)) {
result = SqlTypeName.SMALLINT;
} else if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) \{
result = SqlTypeName.INTEGER;
} else \{
result = SqlTypeName.BIGINT;
}
This is causing me great pain as/is with my current code.
> 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)