Escape comment value in JDBC connectors#14088
Conversation
c5e2466 to
93a9940
Compare
777cd15 to
d2a7bb1
Compare
plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/TestAccumuloConnectorTest.java
Outdated
Show resolved
Hide resolved
...n/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mariadb/src/main/java/io/trino/plugin/mariadb/MariaDbClient.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
I am not sure there is much benefit of using the prepared statement for the comment.
it's nice, but we still need to know how to escape all the other stuff (table name, column names, check constraints (in the future), etc). Escaping the COMMENT value isn't any harder that what we do today.
There was a problem hiding this comment.
In case of MariaDB, they have NO_BACKSLASH_ESCAPES (global & session) property. If we escape the comment without respecting the property in our side, the inserted comment might be different from what we specified in Trino DDL. Also, I guess there're other cases we are missing. That's why I introduced prepared statements in this PR.
There was a problem hiding this comment.
We control the MariaDB connection (session), so we should force NO_BACKSLASH_ESCAPES to be true.
This is important for complex predicate pushdown as well, see RewriteVarcharConstant.
There was a problem hiding this comment.
Reverted prepared statement change. Do you want me to force NO_BACKSLASH_ESCAPES in this PR?
There was a problem hiding this comment.
We can do this as a follow up (It's a "minor correctness" problem. We just don't properly support comments with backslashes.)
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java
Outdated
Show resolved
Hide resolved
e0183d8 to
fc1b94d
Compare
There was a problem hiding this comment.
It's better to have addition of surrounding ' and escaping intra-value ' in a single place.
comment.map(PostgreSqlClient::varcharLiteral).orElse("NULL")
private static String varcharLiteral(String value) {
{
return "'" + value.replace("'", "''") + "'";
}There was a problem hiding this comment.
BTW this is SQL-standard behavior, it doesn't need to be implemented in this class, i.e. every conformant DB should behave like this, so it can be provided by the base-jdbc
plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-mariadb/src/main/java/io/trino/plugin/mariadb/MariaDbClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java
Outdated
Show resolved
Hide resolved
0e63591 to
697d9d6
Compare
Co-Authored-By: Piotr Findeisen <piotr.findeisen@gmail.com>
1c198cf to
52437d4
Compare
Description
Fixes #14058
Release notes
(x) Release notes are required, with the following suggested text: