AngersZhuuuu commented on a change in pull request #33217:
URL: https://github.com/apache/spark/pull/33217#discussion_r664201809
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -119,6 +119,39 @@ object IntervalUtils {
}
}
+ private def throwIllegalIntervalFormatException(
+ input: UTF8String,
+ startFiled: Byte,
+ endField: Byte,
+ intervalStr: String,
+ typeName: String,
+ fallBackNotice: Option[String] = None) = {
+ throw new IllegalArgumentException(
+ s"Interval string does not match $intervalStr format of " +
+ s"${supportedFormat((startFiled, endField))
+ .map(format => s"`$format`").mkString(", ")} " +
+ s"when cast to $typeName: ${input.toString}" +
Review comment:
> Should we add a gap between the two line?
> Could you show an example of the error message, please. I just wonder is
it readable ...
```
Interval string does not match day-time format of `[+|-]d h`, `INTERVAL
[+|-]'[+|-]d h' DAY TO HOUR` when cast to interval day to hour: INTERVAL '1
01:01:01.12345' DAY TO SECOND, set spark.sql.legacy.fromDayTimeString.enabled
to true to restore the behavior before Spark 3.0.
```
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -119,6 +119,39 @@ object IntervalUtils {
}
}
+ private def throwIllegalIntervalFormatException(
+ input: UTF8String,
+ startFiled: Byte,
+ endField: Byte,
+ intervalStr: String,
+ typeName: String,
+ fallBackNotice: Option[String] = None) = {
+ throw new IllegalArgumentException(
+ s"Interval string does not match $intervalStr format of " +
+ s"${supportedFormat((startFiled, endField)).map(format =>
s"`$format`").mkString(", ")} " +
+ s"when cast to $typeName: ${input.toString}" +
+ s"${fallBackNotice.map(s => s", $s").getOrElse("")}")
+ }
+
+ private def checkStringIntervalType(
+ input: UTF8String,
+ targetStartField: Byte,
+ targetEndField: Byte,
+ inputIntervalType: DataType,
+ fallBackNotice: Option[String] = None): Unit = {
Review comment:
FYI @MaxGekk rename the parameter make it more clear
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -119,6 +119,39 @@ object IntervalUtils {
}
}
+ private def throwIllegalIntervalFormatException(
+ input: UTF8String,
+ startFiled: Byte,
+ endField: Byte,
+ intervalStr: String,
+ typeName: String,
+ fallBackNotice: Option[String] = None) = {
+ throw new IllegalArgumentException(
+ s"Interval string does not match $intervalStr format of " +
+ s"${supportedFormat((startFiled, endField))
+ .map(format => s"`$format`").mkString(", ")} " +
+ s"when cast to $typeName: ${input.toString}" +
+ s"${fallBackNotice.map(s => s", $s").getOrElse("")}")
+ }
+
+ private def checkStringIntervalType(
+ input: UTF8String,
+ startField: Byte,
+ endField: Byte,
+ targetInterval: DataType): Unit = {
+ val (intervalStr, typeName, targetStartField, targetEndField) =
targetInterval match {
+ case DT(startField, endField) =>
+ ("day-time", targetInterval.typeName, startField, endField)
+ case YM(startField, endField) =>
+ ("year-month", targetInterval.typeName, startField, endField)
+ }
+ if (startField != targetStartField || endField != targetEndField) {
Review comment:
In current code if `targetStartField == inputStartField &&
targetEndField == inputEndField`
Since target code from cast's target DT/YM type, it should be valid. so it's
necessary to check this here?
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuiteBase.scala
##########
@@ -1249,7 +1257,12 @@ abstract class CastSuiteBase extends SparkFunSuite with
ExpressionEvalHelper {
val e = intercept[IllegalArgumentException] {
cast(Literal.create(interval), dataType).eval()
}.getMessage
- assert(e.contains("Interval string does not match day-time format"))
+ assert(e.contains(s"Interval string does not match day-time format
of " +
+ s"${IntervalUtils.supportedFormat((dataType.startField,
dataType.endField))
+ .map(format => s"`$format`").mkString(", ")} " +
+ s"when cast to ${dataType.typeName}: $interval, " +
+ s"set spark.sql.legacy.fromDayTimeString.enabled to true " +
Review comment:
> Let's use `LEGACY_FROM_DAYTIME_STRING.key`.
Done and tested in local
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuiteBase.scala
##########
@@ -1267,7 +1280,12 @@ abstract class CastSuiteBase extends SparkFunSuite with
ExpressionEvalHelper {
val e = intercept[IllegalArgumentException] {
cast(Literal.create(interval), dataType).eval()
}.getMessage
- assert(e.contains("Interval string does not match day-time format"))
+ assert(e.contains(s"Interval string does not match day-time format
of " +
+ s"${IntervalUtils.supportedFormat((dataType.startField,
dataType.endField))
+ .map(format => s"`$format`").mkString(", ")} " +
+ s"when cast to ${dataType.typeName}: $interval, " +
+ s"set spark.sql.legacy.fromDayTimeString.enabled to true " +
Review comment:
> Please, replace it by `LEGACY_FROM_DAYTIME_STRING.key`
Done and tested in lcoal
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]