-
Notifications
You must be signed in to change notification settings - Fork 444
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
[GLUTEN-8108] fix: Update logic to throw on failure for cast #8107
base: main
Are you sure you want to change the base?
Changes from all commits
2b6390d
bd318a4
e3755a6
5144292
34dfc87
3fbef08
a6df752
4d2de46
ca38e62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.sql.catalyst.expressions | ||
|
||
import org.apache.spark.sql.GlutenTestsTrait | ||
|
||
class GlutenTryCastSuite extends TryCastSuite with GlutenTestsTrait {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import org.apache.gluten.utils.{BackendTestSettings, SQLQueryTestSettings} | |
|
||
import org.apache.spark.GlutenSortShuffleSuite | ||
import org.apache.spark.sql._ | ||
import org.apache.spark.sql.catalyst.expressions.{GlutenArithmeticExpressionSuite, GlutenBitwiseExpressionsSuite, GlutenCastSuite, GlutenCollectionExpressionsSuite, GlutenComplexTypeSuite, GlutenConditionalExpressionSuite, GlutenDateExpressionsSuite, GlutenDecimalExpressionSuite, GlutenDecimalPrecisionSuite, GlutenHashExpressionsSuite, GlutenHigherOrderFunctionsSuite, GlutenIntervalExpressionsSuite, GlutenLiteralExpressionSuite, GlutenMathExpressionsSuite, GlutenMiscExpressionsSuite, GlutenNondeterministicSuite, GlutenNullExpressionsSuite, GlutenPredicateSuite, GlutenRandomSuite, GlutenRegexpExpressionsSuite, GlutenSortOrderExpressionsSuite, GlutenStringExpressionsSuite, GlutenTryEvalSuite} | ||
import org.apache.spark.sql.catalyst.expressions.{GlutenArithmeticExpressionSuite, GlutenBitwiseExpressionsSuite, GlutenCastSuite, GlutenCollectionExpressionsSuite, GlutenComplexTypeSuite, GlutenConditionalExpressionSuite, GlutenDateExpressionsSuite, GlutenDecimalExpressionSuite, GlutenDecimalPrecisionSuite, GlutenHashExpressionsSuite, GlutenHigherOrderFunctionsSuite, GlutenIntervalExpressionsSuite, GlutenLiteralExpressionSuite, GlutenMathExpressionsSuite, GlutenMiscExpressionsSuite, GlutenNondeterministicSuite, GlutenNullExpressionsSuite, GlutenPredicateSuite, GlutenRandomSuite, GlutenRegexpExpressionsSuite, GlutenSortOrderExpressionsSuite, GlutenStringExpressionsSuite, GlutenTryCastSuite, GlutenTryEvalSuite} | ||
import org.apache.spark.sql.connector._ | ||
import org.apache.spark.sql.errors.{GlutenQueryCompilationErrorsDSv2Suite, GlutenQueryCompilationErrorsSuite, GlutenQueryExecutionErrorsSuite, GlutenQueryParsingErrorsSuite} | ||
import org.apache.spark.sql.execution._ | ||
|
@@ -92,6 +92,16 @@ class VeloxTestSettings extends BackendTestSettings { | |
.exclude( | ||
"Process Infinity, -Infinity, NaN in case insensitive manner" // +inf not supported in folly. | ||
) | ||
enableSuite[GlutenTryCastSuite] | ||
.exclude( | ||
"Process Infinity, -Infinity, NaN in case insensitive manner" // +inf not supported in folly. | ||
) | ||
.exclude("ANSI mode: Throw exception on casting out-of-range value to byte type") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you add some comments on why these tests are excluded? I remember ANSI ON causes execution fallback, can the tests produce Spark expected result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests come from https://github.com/apache/spark/blob/master/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastWithAnsiOnSuite.scala and when the suite is run separately with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for providing the details. These tests are for ANSI OFF cases, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are for ANSI enabled (Spark views ANSI is enabled for TRY mode). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PHILO-HE I don't fully understand what you mean. Are you saying Velox behaviour is incorrect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acvictor, no. I am just curious why these tests of TryCastSuite can pass for vanilla Spark. I am assuming the exceptions are handled internally by Spark and null result is returned by internally catching these exceptions. But seems in these tests, exception can still be caught from external side in vanilla Spark. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acvictor, please rebase the code. The core change looks good to me. |
||
.exclude("ANSI mode: Throw exception on casting out-of-range value to short type") | ||
.exclude("ANSI mode: Throw exception on casting out-of-range value to int type") | ||
.exclude("ANSI mode: Throw exception on casting out-of-range value to long type") | ||
.exclude("cast from invalid string to numeric should throw NumberFormatException") | ||
.exclude("SPARK-26218: Fix the corner case of codegen when casting float to Integer") | ||
enableSuite[GlutenCollectionExpressionsSuite] | ||
// Rewrite in Gluten to replace Seq with Array | ||
.exclude("Shuffle") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.sql.catalyst.expressions | ||
|
||
import org.apache.spark.sql.GlutenTestsTrait | ||
|
||
class GlutenTryCastSuite extends TryCastSuite with GlutenTestsTrait {} |
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, I note Spark also sets
ansiEnabled = true
forEvalMode.TRY
, which is for re-using the code logic ofEvalMode.ANSI
. The difference is, in TRY mode any exception is caught and then NULL is returned.Velox has different implementation, which requires us to set this flag simply according to whether EvalMode is ANSI or not.
@acvictor, please leave some comments here to clarify, which should be helpful for future code maintenance.
https://github.com/apache/spark/blob/v3.5.3/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala#L471