-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-37013][SQL] Forbid %0$
usage explicitly to ensure format_string
has same behavior when using Java 8 and Java 17
#34313
Closed
Closed
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
52aa467
fix SPARPK-37013
LuciferYang 7674b55
Merge branch 'upmaster' into SPARK-37013
LuciferYang c457603
fix SPARK-37013
LuciferYang b3bc471
revert
LuciferYang 321f67a
revert
LuciferYang 8d22f3e
revert
LuciferYang c57b424
revert
LuciferYang 3ffe3f9
refactor
LuciferYang 75a1ed2
update text.sql.out
LuciferYang 7e8c3d6
use StringLiteral
LuciferYang ba7c160
sql-migration-guide.md
LuciferYang File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1617,6 +1617,8 @@ case class ParseUrl(children: Seq[Expression], failOnError: Boolean = SQLConf.ge | |
case class FormatString(children: Expression*) extends Expression with ImplicitCastInputTypes { | ||
|
||
require(children.nonEmpty, s"$prettyName() should take at least 1 argument") | ||
require(checkArgumentIndexNotZero(children(0)), "Illegal format argument index = 0") | ||
|
||
|
||
override def foldable: Boolean = children.forall(_.foldable) | ||
override def nullable: Boolean = children(0).nullable | ||
|
@@ -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 pattern: Literal if pattern.dataType == StringType => !pattern.toString.contains("%0$") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
case _ => true | ||
} | ||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use the new error framework to throw error in newly added code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan Sorry, is there any sample? I'll fix it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan Like this PR? https://github.com/apache/spark/pull/34208/files ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very sorry I haven't started this week