LuciferYang commented on a change in pull request #34313:
URL: https://github.com/apache/spark/pull/34313#discussion_r732808594



##########
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:
       Or we can move part of the `j.u.Formatter.parse()` method  code from 
Java 17 to make more strict check




-- 
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]

Reply via email to