Escape single quotes in string literals pushed to Cassandra and Geode#5075
Open
Samin061 wants to merge 1 commit into
Open
Escape single quotes in string literals pushed to Cassandra and Geode#5075Samin061 wants to merge 1 commit into
Samin061 wants to merge 1 commit into
Conversation
|
xiedeyantu
reviewed
Jul 4, 2026
xiedeyantu
left a comment
Member
There was a problem hiding this comment.
I think the idea is good, but the code is not good.
| SqlTypeName typeName = field.getType().getSqlTypeName(); | ||
| if (typeName != SqlTypeName.CHAR) { | ||
| valueString = "'" + valueString + "'"; | ||
| valueString = "'" + valueString.replace("'", "''") + "'"; |
Member
There was a problem hiding this comment.
If the value is I''m fine, I think replace will return an unexpected results.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Jira Link
No Jira filed yet; happy to open one under CALCITE if you'd prefer to track it there.
Changes Proposed
When the Cassandra and Geode adapters push a filter down to the backend, a SQL string literal is wrapped in single quotes to build the CQL/OQL predicate, but embedded single quotes are not escaped.
CassandraFilter.translateOp2andGeodeFilter.quoteCharLiteralemitcol = '<value>'verbatim, so a value that itself contains a quote breaks out of the string literal. A legitimate value such asO'Brienproduces malformed CQL/OQL, and a runtime-supplied literal can inject additional predicate syntax into the query that reachessession.execute/QueryService.newQuery.The Geode test for
WHERE city = 'a''b'currently makes the OQL parser fail withunexpected token: b, which shows the value leaking out of the literal. Doubling the embedded quote ('->'') keeps the value inside the literal for both dialects; this is the same escaping the Druid adapter already applies inDruidExpressions.stringLiteral.Added a Geode test that asserts the generated OQL is
... WHERE city = 'a''b', and a Cassandra test that a quoted filter value executes cleanly.