Github user ueshin commented on a diff in the pull request:
https://github.com/apache/spark/pull/21010#discussion_r185691812
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
---
@@ -2108,35 +2133,53 @@ case class FormatNumber(x: Expression, d:
Expression)
// SPARK-13515: US Locale configures the DecimalFormat object to use
a dot ('.')
// as a decimal separator.
val usLocale = "US"
- val i = ctx.freshName("i")
- val dFormat = ctx.freshName("dFormat")
- val lastDValue =
- ctx.addMutableState(CodeGenerator.JAVA_INT, "lastDValue", v =>
s"$v = -100;")
- val pattern = ctx.addMutableState(sb, "pattern", v => s"$v = new
$sb();")
val numberFormat = ctx.addMutableState(df, "numberFormat",
v => s"""$v = new $df("", new $dfs($l.$usLocale));""")
- s"""
- if ($d >= 0) {
- $pattern.delete(0, $pattern.length());
- if ($d != $lastDValue) {
- $pattern.append("#,###,###,###,###,###,##0");
-
- if ($d > 0) {
- $pattern.append(".");
- for (int $i = 0; $i < $d; $i++) {
- $pattern.append("0");
+ right.dataType match {
+ case IntegerType =>
+ val pattern = ctx.addMutableState(sb, "pattern", v => s"$v = new
$sb();")
+ val i = ctx.freshName("i")
+ val lastDIntValue =
+ ctx.addMutableState(CodeGenerator.JAVA_INT, "lastDValue", v =>
s"$v = -100;")
+ s"""
+ if ($d >= 0) {
+ $pattern.delete(0, $pattern.length());
+ if ($d != $lastDIntValue) {
+ $pattern.append("$defaultFormat");
+
+ if ($d > 0) {
+ $pattern.append(".");
+ for (int $i = 0; $i < $d; $i++) {
+ $pattern.append("0");
+ }
+ }
+ $lastDIntValue = $d;
+ $numberFormat.applyLocalizedPattern($pattern.toString());
}
+ ${ev.value} =
UTF8String.fromString($numberFormat.format(${typeHelper(num)}));
+ } else {
+ ${ev.value} = null;
+ ${ev.isNull} = true;
}
- $lastDValue = $d;
- $numberFormat.applyLocalizedPattern($pattern.toString());
- }
- ${ev.value} =
UTF8String.fromString($numberFormat.format(${typeHelper(num)}));
- } else {
- ${ev.value} = null;
- ${ev.isNull} = true;
- }
- """
+ """
+ case StringType =>
+ val lastDStringValue =
+ ctx.addMutableState("String", "lastDValue", v => s"""$v =
"$defaultFormat";""")
+ val dValue = ctx.addMutableState("String", "dValue")
--- End diff --
Do we need to make this mutable state?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]