You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/06/28 06:51:11 UTC
[GitHub] [spark] AngersZhuuuu commented on a change in pull request #32365: [SPARK-35228][SQL] Add expression ToPrettyString for keep consistent between hive/spark format in df.show and transform
AngersZhuuuu commented on a change in pull request #32365:
URL: https://github.com/apache/spark/pull/32365#discussion_r659522065
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -2649,3 +2652,155 @@ case class Sentences(
copy(str = newFirst, language = newSecond, country = newThird)
}
+
+case class ToPrettyString(child: Expression, timeZoneId: Option[String] = None)
+ extends CastBase {
+ import ToPrettyString._
+
+ override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression =
+ copy(timeZoneId = Option(timeZoneId))
+
+ override def dataType: DataType = StringType
+
+ private lazy val timeFormatters: TimeFormatters =
+ TimeFormatters(DateFormatter(zoneId), TimestampFormatter.getFractionFormatter(zoneId))
+
+ override def leftBracket: String = "{"
+ override def rightBracket: String = "}"
+ override def elementSpace: String = ""
+ override def keyValueSeparator: String = ":"
+ override def structTypeWithSchema: Boolean = true
+
+ override def nullSafeEval(input: Any): Any = {
+ UTF8String.fromString(toHiveString((input, child.dataType), false, timeFormatters))
Review comment:
Year, just override `castToString` and `castToStringCode`
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -2649,3 +2652,155 @@ case class Sentences(
copy(str = newFirst, language = newSecond, country = newThird)
}
+
+case class ToPrettyString(child: Expression, timeZoneId: Option[String] = None)
+ extends CastBase {
+ import ToPrettyString._
+
+ override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression =
+ copy(timeZoneId = Option(timeZoneId))
+
+ override def dataType: DataType = StringType
+
+ private lazy val timeFormatters: TimeFormatters =
+ TimeFormatters(DateFormatter(zoneId), TimestampFormatter.getFractionFormatter(zoneId))
+
+ override def leftBracket: String = "{"
+ override def rightBracket: String = "}"
+ override def elementSpace: String = ""
+ override def keyValueSeparator: String = ":"
+ override def structTypeWithSchema: Boolean = true
+
+ override def nullSafeEval(input: Any): Any = {
+ UTF8String.fromString(toHiveString((input, child.dataType), false, timeFormatters))
+ }
+
+ override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
Review comment:
removed
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org