Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priming query patterns through JSON API requires single quotes to be unicode encoded #136

Open
jbridger opened this issue Feb 8, 2016 · 0 comments

Comments

@jbridger
Copy link
Contributor

jbridger commented Feb 8, 2016

When priming simple queries through the JSON API, single quotes must be unicode encoded. If we don't unicode encode the single quotes, it doesn't match against our query.

An example query we want to prime for:

INSERT INTO my_table (col1, col2) VALUES (val1, 'SOME_CONSTANT')

To prime for this in Java, we do the following, where single quotes are used as-is:

PrimingRequest.PrimingRequestBuilder prime = PrimingRequest.queryBuilder()
                .withQueryPattern("INSERT INTO my_table \\(col1, col2\\) VALUES \\(.+, 'SOME_CONSTANT' \\)")
                .withThen(then().withResult(PrimingRequest.Result.valueOf(exception)));

Debugging this, we can see that the use of GSON is encoding the single quotes as \u0027.

When we try to prime using the JSON API to SCassandra using the same query pattern is we would in Java, it does not match the query:

{
    "when": {
        "queryPattern": "INSERT INTO my_table \\(col1, col2\\) VALUES \\(.+, 'SOME_CONSTANT'\\)"
    },
    "then": {...}
}

If we encode the single quotes, this will match our query:

{
    "when": {
        "queryPattern": "INSERT INTO my_table \\(col1, col2\\) VALUES \\(.+, \u0027SOME_CONSTANT\u0027\\)"
    },
    "then": {...}
}

So as you can see, when priming with Java we don't need to encode the single quote (but does it behind the scenes), and we need to do it when using the JSON API. It would be nice if we didn't have to encode it, so we can have the same query patterns in Java and when sent directly through the JSON API. I haven't found anything in the JSON spec that requires the encoding of single quotes in the JSON object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant