You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/04/17 07:25:29 UTC
[GitHub] [calcite] libenchao opened a new pull request, #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
libenchao opened a new pull request, #2772:
URL: https://github.com/apache/calcite/pull/2772
…d to unexpected behaviour
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] chunweilei commented on pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
chunweilei commented on PR #2772:
URL: https://github.com/apache/calcite/pull/2772#issuecomment-1107987013
BTW, could you please squash the commits?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] libenchao commented on a diff in pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] chunweilei merged pull request #2772: [CALCITE-4861] Optimization of chained CAST calls can lead to unexpected behavior
Posted by GitBox <gi...@apache.org>.
chunweilei merged PR #2772:
URL: https://github.com/apache/calcite/pull/2772
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] chunweilei commented on a diff in pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
chunweilei commented on code in PR #2772:
URL: https://github.com/apache/calcite/pull/2772#discussion_r857211808
##########
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:
Get it. LGTM.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] libenchao commented on a diff in pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
libenchao commented on code in PR #2772:
URL: https://github.com/apache/calcite/pull/2772#discussion_r855771402
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -845,15 +845,15 @@ protected SqlOperatorFixture fixture() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
- f.checkScalarExact("cast( cast(1.25 as double) as integer)", 1);
- f.checkScalarExact("cast( cast(-1.25 as double) as integer)", -1);
+ f.checkFails("cast( cast(1.25 as double) as integer)", "Value out of range.", true);
+ f.checkFails("cast( cast(-1.25 as double) as integer)", "Value out of range.", true);
if (!f.brokenTestsEnabled()) {
return;
}
- f.checkScalarExact("cast( cast(1.75 as double) as integer)", 2);
- f.checkScalarExact("cast( cast(-1.75 as double) as integer)", -2);
- f.checkScalarExact("cast( cast(1.5 as double) as integer)", 2);
- f.checkScalarExact("cast( cast(-1.5 as double) as integer)", -2);
+ f.checkFails("cast( cast(1.75 as double) as integer)", "Value out of range.", true);
+ f.checkFails("cast( cast(-1.75 as double) as integer)", "Value out of range.", true);
+ f.checkFails("cast( cast(1.5 as double) as integer)", "Value out of range.", true);
Review Comment:
nice suggestion, revised.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] libenchao commented on pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
libenchao commented on PR #2772:
URL: https://github.com/apache/calcite/pull/2772#issuecomment-1100826419
Druid tests failed due to timeout which is irrelevant with this change.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] libenchao commented on pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
libenchao commented on PR #2772:
URL: https://github.com/apache/calcite/pull/2772#issuecomment-1107991815
@chunweilei Thanks for the review, I've rebased and squashed the commits.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] chunweilei commented on a diff in pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
chunweilei commented on code in PR #2772:
URL: https://github.com/apache/calcite/pull/2772#discussion_r855714341
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -845,15 +845,15 @@ protected SqlOperatorFixture fixture() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
- f.checkScalarExact("cast( cast(1.25 as double) as integer)", 1);
- f.checkScalarExact("cast( cast(-1.25 as double) as integer)", -1);
+ f.checkFails("cast( cast(1.25 as double) as integer)", "Value out of range.", true);
+ f.checkFails("cast( cast(-1.25 as double) as integer)", "Value out of range.", true);
if (!f.brokenTestsEnabled()) {
return;
}
- f.checkScalarExact("cast( cast(1.75 as double) as integer)", 2);
- f.checkScalarExact("cast( cast(-1.75 as double) as integer)", -2);
- f.checkScalarExact("cast( cast(1.5 as double) as integer)", 2);
- f.checkScalarExact("cast( cast(-1.5 as double) as integer)", -2);
+ f.checkFails("cast( cast(1.75 as double) as integer)", "Value out of range.", true);
+ f.checkFails("cast( cast(-1.75 as double) as integer)", "Value out of range.", true);
+ f.checkFails("cast( cast(1.5 as double) as integer)", "Value out of range.", true);
Review Comment:
Besides, we could use OUT_OF_RANGE_MESSAGE instead of "Value out of range."
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] chunweilei commented on a diff in pull request #2772: [CALCITE-4861] Optimisation of chained cast calls for literal can lea…
Posted by GitBox <gi...@apache.org>.
chunweilei commented on code in PR #2772:
URL: https://github.com/apache/calcite/pull/2772#discussion_r855714342
##########
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:
I am confused. It looks "cast(1.5 as int)" would throw an exception. Is it the right behavior?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org