Skip to content

Commit 60acc8f

Browse files
sarutakcloud-fan
andcommitted
[SPARK-57332][SQL][FOLLOWUP] Fix line length exceeding 100 characters in JDBCSuite and V2ExpressionSQLBuilder
### What changes were proposed in this pull request? This PR fixes a style issue introduced by #56384. There are some lines in `JDBCSuite.scala` and `V2ExpressionSQLBuilder.java`‎ whose length exceed 100 characters. ### Why are the changes needed? To recover CI. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? GA. ### Was this patch authored or co-authored using generative AI tooling? Kiro CLI / Claude Closes #56441 from sarutak/decouple-like-pattern-escaping. Lead-authored-by: Kousuke Saruta <sarutak@amazon.co.jp> Co-authored-by: Wenchen Fan <wenchen@databricks.com> Signed-off-by: Kousuke Saruta <sarutak@apache.org>
1 parent 9018d84 commit 60acc8f

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

sql/catalyst/src/main/java/org/apache/spark/sql/connector/util/V2ExpressionSQLBuilder.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ public class V2ExpressionSQLBuilder {
5555

5656
/**
5757
* Escape the LIKE pattern special chars, using {@code \} as the escape character. The LIKE
58-
* patterns produced by {@link #visitStartsWith}, {@link #visitEndsWith} and {@link #visitContains}
59-
* declare {@code ESCAPE '\'}, so the wildcards {@code _} and {@code %} and the escape character
60-
* {@code \} itself must each be prefixed with {@code \} to be matched literally.
58+
* patterns produced by {@link #visitStartsWith}, {@link #visitEndsWith} and
59+
* {@link #visitContains} declare {@code ESCAPE '\'}, so the wildcards {@code _} and {@code %}
60+
* and the escape character {@code \} itself must each be prefixed with {@code \} to be matched
61+
* literally.
6162
*
6263
* Note: This method adopts the escape representation within Spark and is not bound to any JDBC
6364
* dialect. A JDBC dialect should overwrite this API if the underlying database has more LIKE
@@ -237,9 +238,10 @@ protected String visitContains(String l, String r) {
237238

238239
/**
239240
* Build a {@code <left> LIKE '<pattern>' ESCAPE '\'} predicate. The pattern already has its LIKE
240-
* special chars escaped (via {@link #escapeSpecialCharsForLikePattern}); both the pattern and the
241-
* {@code \} escape character are then passed through {@link #escapeStringLiteralForLikePattern} so
242-
* a dialect can add any string-literal escaping its SQL syntax requires.
241+
* special chars escaped (via {@link #escapeSpecialCharsForLikePattern}); both the pattern and
242+
* the {@code \} escape character are then passed through
243+
* {@link #escapeStringLiteralForLikePattern} so a dialect can add any string-literal escaping
244+
* its SQL syntax requires.
243245
*/
244246
private String likeWithEscape(String l, String pattern) {
245247
return l + " LIKE '" + escapeStringLiteralForLikePattern(pattern)

sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,9 @@ class JDBCSuite extends SharedSparkSession {
925925

926926
// MySQL treats backslash as an escape character inside string literals, so every backslash is
927927
// doubled again: the ESCAPE clause uses `\\` and a literal backslash in the value becomes four
928-
// backslashes (escapeSpecialCharsForLikePattern doubles it, then escapeStringLiteralForLikePattern
929-
// doubles each of those). The wildcard escaping for `%`/`_` is unchanged from the default.
928+
// backslashes (escapeSpecialCharsForLikePattern doubles it, then
929+
// escapeStringLiteralForLikePattern doubles each of those). The wildcard escaping for
930+
// `%`/`_` is unchanged from the default.
930931
val mySQLDialect = JdbcDialects.get("jdbc:mysql://127.0.0.1/db")
931932
def mySQLSQL(f: Filter): String = mySQLDialect.compileExpression(f.toV2).getOrElse("")
932933
// `c` LIKE 'ab\\\\%' ESCAPE '\\'

0 commit comments

Comments
 (0)