[ 
https://issues.apache.org/jira/browse/SPARK-61341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Yang updated SPARK-61341:
------------------------------
    Description: 
When the pattern argument of `startswith`, endswith or contains is a column 
rather than a string literal, V2ExpressionSQLBuilder renders the predicate as a 
LIKE against a mangled copy of the column name instead of the column's value. 
For example, startswith(email, email) becomes email LIKE 'mai%' ESCAPE '\'. A 
DSv2 source that pushes these predicates down with V2ExpressionSQLBuilder 
returns wrong results without any error. In a DSv2 JDBC catalog with a custom 
JdbcDialect that builds SQL this way, 
filter(col("EMAIL").startsWith(col("EMAIL"))) over rows MAIL@x and zzz returns 
only MAIL@x. If the pattern column's name is a single character, calling 
toString on the predicate throws StringIndexOutOfBoundsException.

This affects non-JDBC DSv2 sources and JdbcDialects that override 
compileExpression with their own builder. Spark's built-in JDBC dialects are 
fixed by SPARK-57500.

  was:
When the pattern argument of startswith, endswith or contains is a column 
rather than a string literal, V2ExpressionSQLBuilder renders the predicate as a 
LIKE against a mangled copy of the column name instead of the column's value. 
For example, startswith(email, email) becomes email LIKE 'mai%' ESCAPE '\'. A 
DSv2 source that pushes these predicates down with V2ExpressionSQLBuilder 
returns wrong results without any error. In a DSv2 JDBC catalog with a custom 
JdbcDialect that builds SQL this way, 
filter(col("EMAIL").startsWith(col("EMAIL"))) over rows MAIL@x and zzz returns 
only MAIL@x. If the pattern column's name is a single character, calling 
toString on the predicate throws StringIndexOutOfBoundsException.

This affects non-JDBC DSv2 sources and JdbcDialects that override 
compileExpression with their own builder. Spark's built-in JDBC dialects are 
fixed by SPARK-57500.


> Wrong LIKE pattern from startswith/endswith/contains with a column argument 
> in DSv2 sources that use V2ExpressionSQLBuilder
> ---------------------------------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-61341
>                 URL: https://issues.apache.org/jira/browse/SPARK-61341
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 5.0.0
>            Reporter: Eric Yang
>            Priority: Major
>
> When the pattern argument of `startswith`, endswith or contains is a column 
> rather than a string literal, V2ExpressionSQLBuilder renders the predicate as 
> a LIKE against a mangled copy of the column name instead of the column's 
> value. For example, startswith(email, email) becomes email LIKE 'mai%' ESCAPE 
> '\'. A DSv2 source that pushes these predicates down with 
> V2ExpressionSQLBuilder returns wrong results without any error. In a DSv2 
> JDBC catalog with a custom JdbcDialect that builds SQL this way, 
> filter(col("EMAIL").startsWith(col("EMAIL"))) over rows MAIL@x and zzz 
> returns only MAIL@x. If the pattern column's name is a single character, 
> calling toString on the predicate throws StringIndexOutOfBoundsException.
> This affects non-JDBC DSv2 sources and JdbcDialects that override 
> compileExpression with their own builder. Spark's built-in JDBC dialects are 
> fixed by SPARK-57500.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to