-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CALCITE-4838] Add RoundingMode in SqlConformance to document the rou… #3917
base: main
Are you sure you want to change the base?
Conversation
…nding mode when cast an approximate numeric to int
Quality Gate passedIssues Measures |
!ok | ||
|
||
|
||
select cast(5.5 as smallint), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for each statement, add comments explaining what rounding mode is being used
@@ -384,9 384,15 @@ static void checkRoundedRange(Number value, double min, double max) { | |||
} | |||
} | |||
|
|||
/** Called from BuiltInMethod.INTEGER_CAST */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc is same as next method
if methods have the same description, are both required?
* | ||
* <p> {@link org.apache.calcite.sql.SqlDialect.DatabaseProduct#CALCITE}'s | ||
* default is {@link RoundingMode#DOWN} and {@link org.apache.calcite.sql.SqlDialect.DatabaseProduct#POSTGRESQL}, | ||
* {@link org.apache.calcite.sql.SqlDialect.DatabaseProduct#MYSQL} and {@link org.apache.calcite.sql.SqlDialect.DatabaseProduct#ORACLE} is {@link RoundingMode#HALF_UP}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line is too long and can be wrapped
} | ||
return Expressions.constant(null, type); | ||
} | ||
|
||
static Expression getDefaultValue(Type type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the method without roundingMode
be deprecated?
|
||
public RexExecutorImpl(DataContext dataContext) { | ||
this.dataContext = dataContext; | ||
this.sqlConformance = SqlConformanceEnum.DEFAULT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think conformance belongs here. Conformance governs validation behavior, not runtime behavior.
@@ -133,7 152,7 @@ public static RexExecutable getExecutable(RexBuilder rexBuilder, List<RexNode> e | |||
try { | |||
code = compile(rexBuilder, constExps, (list, index, storageType) -> { | |||
throw new UnsupportedOperationException(); | |||
}); | |||
}, sqlConformance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is more readable if the lambda is the last parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sorely needed work, thank you for doing it.
@@ -505,9 505,9 @@ private Expression getConvertExpression( | |||
case SMALLINT: { | |||
if (SqlTypeName.NUMERIC_TYPES.contains(sourceType.getSqlTypeName())) { | |||
return Expressions.call( | |||
BuiltInMethod.INTEGER_CAST.method, | |||
BuiltInMethod.INTEGER_CAST_ROUNDING_MODE.method, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should apply to casts from decimal to decimal above
@@ -144,4 146,8 @@ public abstract class SqlAbstractConformance implements SqlConformance { | |||
@Override public boolean allowLenientCoercion() { | |||
return SqlConformanceEnum.DEFAULT.allowLenientCoercion(); | |||
} | |||
|
|||
@Override public RoundingMode roundingMode() { | |||
return SqlConformanceEnum.DEFAULT.roundingMode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rounding should be part of the type system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
I commented elsewhere that including SqlConformance
in RexExecutor
made me feel uneasy. SqlConformance
is about what is allowed in valid SQL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@julianhyde @mihaibudiu I will move the roundingMode
to RelDataTypeSystem
. Thanks for the advice.
@@ -315,6 316,8 @@ public enum BuiltInMethod { | |||
FP_DECIMAL_CAST(Primitive.class, "fpDecimalCast", | |||
Number.class, int.class, int.class), | |||
INTEGER_CAST(Primitive.class, "integerCast", Primitive.class, Object.class), | |||
INTEGER_CAST_ROUNDING_MODE(Primitive.class, "integerCast", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other cast method should probably be removed.
but many other cast methods have to be considered, including DECIMAL to DECIMAL, FP to integer, FP to decimal, DECIMAL to FP and perhaps even string to decimal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. According to your advice, I found some places that use the default RoudingMode.DOWN
. I'll see what I can do.
…nding mode when cast an approximate numeric to int