terrymanu commented on a change in pull request #12140:
URL: https://github.com/apache/shardingsphere/pull/12140#discussion_r699823558
##########
File path:
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
##########
@@ -280,12 +279,12 @@ public static String trimComment(final String sql) {
}
/**
- * Get show like pattern.
+ * Replace all SQL pattern to java regex.
*
- * @param showLike show like segment
- * @return pattern
+ * @param pattern SQL pattern
+ * @return java regex
*/
- public static String getShowLikePattern(final ShowLikeSegment showLike) {
- return showLike.getPattern().replaceAll("_", ".{1}").replaceAll("%",
".*");
+ public static String handleSQLPattern(final String pattern) {
+ return pattern.contains("_") || pattern.contains("%") ?
pattern.replaceAll("_", ".").replaceAll("%", ".*") : pattern;
Review comment:
Please consider if the original varchar contains `%` or `_`
##########
File path:
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
##########
@@ -73,6 +76,15 @@
private static final String COMMENT_SUFFIX = "*/";
+ private static final Map<String, Pattern> PATTERNS = new LinkedHashMap<>();
+
+ static {
+ PATTERNS.put("$1.", Pattern.compile("^_|([^\\\\])_"));
+ PATTERNS.put("$1.*", Pattern.compile("^%|([^\\\\])%"));
+ PATTERNS.put("_", Pattern.compile("\\\\_"));
+ PATTERNS.put("%", Pattern.compile("\\\\%"));
Review comment:
Is it better to use variable name instead of map.
Variable name can self describe.
--
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]