libenchao commented on code in PR #2772:
URL: https://github.com/apache/calcite/pull/2772#discussion_r855889276
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -805,36 +805,36 @@ protected SqlOperatorFixture fixture() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
- f.checkCastToScalarOkay("1.25", "INTEGER", "1");
- f.checkCastToScalarOkay("1.25E0", "INTEGER", "1");
+ f.checkFails("cast(1.25 as int)", "INTEGER", true);
+ f.checkFails("cast(1.25E0 as int)", "INTEGER", true);
if (!f.brokenTestsEnabled()) {
return;
}
- f.checkCastToScalarOkay("1.5", "INTEGER", "2");
- f.checkCastToScalarOkay("5E-1", "INTEGER", "1");
- f.checkCastToScalarOkay("1.75", "INTEGER", "2");
- f.checkCastToScalarOkay("1.75E0", "INTEGER", "2");
-
- f.checkCastToScalarOkay("-1.25", "INTEGER", "-1");
- f.checkCastToScalarOkay("-1.25E0", "INTEGER", "-1");
- f.checkCastToScalarOkay("-1.5", "INTEGER", "-2");
- f.checkCastToScalarOkay("-5E-1", "INTEGER", "-1");
- f.checkCastToScalarOkay("-1.75", "INTEGER", "-2");
- f.checkCastToScalarOkay("-1.75E0", "INTEGER", "-2");
-
- f.checkCastToScalarOkay("1.23454", "DECIMAL(8, 4)", "1.2345");
- f.checkCastToScalarOkay("1.23454E0", "DECIMAL(8, 4)", "1.2345");
- f.checkCastToScalarOkay("1.23455", "DECIMAL(8, 4)", "1.2346");
- f.checkCastToScalarOkay("5E-5", "DECIMAL(8, 4)", "0.0001");
- f.checkCastToScalarOkay("1.99995", "DECIMAL(8, 4)", "2.0000");
- f.checkCastToScalarOkay("1.99995E0", "DECIMAL(8, 4)", "2.0000");
-
- f.checkCastToScalarOkay("-1.23454", "DECIMAL(8, 4)", "-1.2345");
- f.checkCastToScalarOkay("-1.23454E0", "DECIMAL(8, 4)", "-1.2345");
- f.checkCastToScalarOkay("-1.23455", "DECIMAL(8, 4)", "-1.2346");
- f.checkCastToScalarOkay("-5E-5", "DECIMAL(8, 4)", "-0.0001");
- f.checkCastToScalarOkay("-1.99995", "DECIMAL(8, 4)", "-2.0000");
- f.checkCastToScalarOkay("-1.99995E0", "DECIMAL(8, 4)", "-2.0000");
+ f.checkFails("cast(1.5 as int)", "Value out of range.", true);
+ f.checkFails("cast(5E-1 as int)", "Value out of range.", true);
+ f.checkFails("cast(1.75 as int)", "Value out of range.", true);
+ f.checkFails("cast(1.75E0 as int)", "Value out of range.", true);
+
Review Comment:
@chunweilei As I said in jira:
> 1, There is already a feature for general cast elimination to avoid
removing loss cast in RexSimplify#simplifyCast introduced in
[CALCITE-3712](https://issues.apache.org/jira/browse/CALCITE-3712)
2, The main problem causing this issue, is the literal's simplification in
RexBuilder#makeCast
3, The runtime behavior for casting: throwing exception or truncation in
loss casting. I think this is orthogonal with current issue and can be
discussed in a separate issue.
In this pr, I only focused on 2. For the runtime behavior, it can be
discussed and tackled in an orthogonal issue. WDYT?
--
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]