-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-45880][SQL] Make the like pattern semantics used in all commands consistent
#43751
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e418b3d
[SPARK-45880][SQL] Introduce a new TableCatalog.listTable overload th…
panbingkun 43bfe0f
fix UT
panbingkun bf18462
Merge branch 'master' into SPARK-45880
panbingkun c51043f
update ShowTablesExtendedExec & ShowTablesExec
panbingkun 55fa734
update ref
panbingkun 3fa8e9a
update TableCatalog ref
panbingkun 315c8b7
Merge branch 'master' into SPARK-45880
panbingkun 48acc95
Merge branch 'master' into SPARK-45880
panbingkun c414e8e
Merge branch 'master' into SPARK-45880
panbingkun 596de52
[SPARK-45880][SQL] `Like` pattern accept only SQL type like expressio…
panbingkun 6181d3c
rebase master
panbingkun 4d382ef
fix some UT
panbingkun 677f2c9
fix ut
panbingkun 3992a7d
Merge branch 'master' into SPARK-45880
panbingkun 4b096f2
update comment & doc & ut
panbingkun 3a43818
Merge branch 'master' into SPARK-45880
panbingkun 2aeb620
improve
panbingkun 7abf241
fix style
panbingkun b276a3d
Merge branch 'master' into SPARK-45880
panbingkun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -108,26 +108,84 @@ object StringUtils extends Logging { | |
| // scalastyle:on caselocale | ||
|
|
||
| /** | ||
| * This utility can be used for filtering pattern in the "Like" of "Show Tables / Functions" DDL | ||
| * get Wildcard that represent matching "all" | ||
| */ | ||
| def getMatchAllWildcard: String = { | ||
| if (SQLConf.get.legacyUseStarAndVerticalBarAsWildcardsInLikePattern) { | ||
| "*" | ||
| } else { | ||
| "%" | ||
| } | ||
| } | ||
|
|
||
| def filterPattern(names: Seq[String], pattern: String): Seq[String] = { | ||
| if (SQLConf.get.legacyUseStarAndVerticalBarAsWildcardsInLikePattern) { | ||
| legacyFilterPattern(names, pattern) | ||
| } else { | ||
| filterBySQLLikePattern(names, pattern) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This legacy utility can be used for filtering pattern in the "Like" of | ||
| * "Show Tables / Functions" DDL. | ||
| * @param names the names list to be filtered | ||
| * @param pattern the filter pattern, only '*' and '|' are allowed as wildcards, others will | ||
| * follow regular expression convention, case insensitive match and white spaces | ||
| * on both ends will be ignored | ||
| * @return the filtered names list in order | ||
| */ | ||
| def filterPattern(names: Seq[String], pattern: String): Seq[String] = { | ||
| def legacyFilterPattern(names: Seq[String], pattern: String): Seq[String] = { | ||
| val funcNames = scala.collection.mutable.SortedSet.empty[String] | ||
| pattern.trim().split("\\|").foreach { subPattern => | ||
| try { | ||
| val regex = ("(?i)" + subPattern.replaceAll("\\*", ".*")).r | ||
| funcNames ++= names.filter{ name => regex.pattern.matcher(name).matches() } | ||
| funcNames ++= names.filter { name => regex.pattern.matcher(name).matches() } | ||
| } catch { | ||
| case _: PatternSyntaxException => | ||
| } | ||
| } | ||
| funcNames.toSeq | ||
| } | ||
|
|
||
| /** | ||
| * This utility can be used for filtering pattern in the "Like" of "Show Tables / Functions" DDL. | ||
| * @param names the names list to be filtered | ||
| * @param pattern the filter pattern, same as SQL type `like` expressions: | ||
| * '%' for any character(s), and '_' for a single character | ||
| * @return the filtered names list | ||
| */ | ||
| def filterBySQLLikePattern(names: Seq[String], pattern: String): Seq[String] = { | ||
| try { | ||
| val p = Pattern.compile(likePatternToRegExp(pattern), Pattern.CASE_INSENSITIVE) | ||
| names.filter { name => p.matcher(name).matches() } | ||
| } catch { | ||
| case _: PatternSyntaxException => Seq.empty[String] | ||
| } | ||
| } | ||
|
|
||
| private[util] def likePatternToRegExp(pattern: String): String = { | ||
|
Contributor
Author
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. Follow the implementation logic of hive: |
||
| val regExp = new StringBuilder() | ||
|
|
||
| var index = 0 | ||
| while (index < pattern.length) { | ||
| val cur = pattern.charAt(index) | ||
| cur match { | ||
| // Make a special case for "\\_" and "\\%" | ||
| case '\\' if (index + 1 < pattern.length() | ||
| && (pattern.charAt(index + 1) == '_' || pattern.charAt(index + 1) == '%')) => | ||
| regExp += pattern.charAt(index + 1) | ||
| index = index + 1 | ||
| case '_' => regExp ++= "." | ||
| case '%' => regExp ++= ".*?" | ||
| case _ => regExp ++= Pattern.quote(Character.toString(cur)) | ||
| } | ||
| index = index + 1 | ||
| } | ||
|
|
||
| regExp.result() | ||
| } | ||
|
|
||
| /** | ||
| * A string concatenator for plan strings. Uses length from a configured value, and | ||
| * prints a warning the first time a plan is truncated. | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Before:

After:
