srowen commented on a change in pull request #34313:
URL: https://github.com/apache/spark/pull/34313#discussion_r732791348
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -1688,6 +1690,21 @@ case class FormatString(children: Expression*) extends
Expression with ImplicitC
override protected def withNewChildrenInternal(
newChildren: IndexedSeq[Expression]): FormatString =
FormatString(newChildren: _*)
+
+ /**
+ * SPARK-37013: The `formatSpecifier` defined in `j.u.Formatter` as follows:
+ * "%[argument_index$][flags][width][.precision][t]conversion"
+ * The optional `argument_index` is a decimal integer indicating the
position of the argument
+ * in the argument list. The first argument is referenced by "1$", the
second by "2$", etc.
+ * However, for the illegal definition of "%0$", Java 8 and Java 11 uses it
as "%1$",
+ * and Java 17 throws IllegalFormatArgumentIndexException(Illegal format
argument index = 0).
+ * Therefore, manually check that the pattern string not contains "%0$" to
ensure consistent
+ * behavior of Java 8, Java 11 and Java 17.
+ */
+ private def checkArgumentIndexNotZero(expression: Expression): Boolean =
expression match {
+ case StringLiteral(pattern) => !pattern.contains("%0$")
Review comment:
I think there may be more ways to use index 0 - what if you have
something between the % and 0$?
This might in practice be close enough, just wondering if there is a simple
way to make this more comprehensive without false positives
--
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]