caicancai commented on code in PR #3790:
URL: https://github.com/apache/calcite/pull/3790#discussion_r1607483761
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -770,41 +773,39 @@ void testCastIntervalToNumeric(CastType castType,
SqlOperatorFixture f) {
f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
// interval to decimal
Review Comment:
Interval to Decimal
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java:
##########
@@ -449,6 +449,35 @@ private Expression getConvertExpression(
return defaultExpression.get();
}
+ case DECIMAL: {
+ int precision = targetType.getPrecision();
+ int scale = targetType.getScale();
+ if (precision != RelDataType.PRECISION_NOT_SPECIFIED
+ && scale != RelDataType.SCALE_NOT_SPECIFIED) {
+ if (sourceType.getFamily() == SqlTypeFamily.CHARACTER) {
+ return Expressions.call(
+ BuiltInMethod.CHAR_DECIMAL_CAST.method,
+ operand,
+ Expressions.constant(precision),
+ Expressions.constant(scale));
+ } else if (sourceType.getFamily() == SqlTypeFamily.INTERVAL_DAY_TIME) {
+ return Expressions.call(
+ BuiltInMethod.SHORT_INTERVAL_DECIMAL_CAST.method,
+ operand,
+ Expressions.constant(precision),
+ Expressions.constant(scale),
+
Expressions.constant(sourceType.getSqlTypeName().getEndUnit().multiplier));
+ } else if (sourceType.getFamily() ==
SqlTypeFamily.INTERVAL_YEAR_MONTH) {
+ return Expressions.call(
+ BuiltInMethod.LONG_INTERVAL_DECIMAL_CAST.method,
+ operand,
+ Expressions.constant(precision),
+ Expressions.constant(scale),
+
Expressions.constant(sourceType.getSqlTypeName().getEndUnit().multiplier));
+ }
+ }
Review Comment:
Should we throw an exception when a situation does not include the above
three cases
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]