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

[CALCITE-6509] MongoAdapter throws 'Invalid JSON Number' exception if first character of field name is number #3896

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dssysolyatin
Copy link
Contributor

… first character of field name is number

Copy link

sonarcloud bot commented Aug 1, 2024

@@ -114,10 +114,14 @@ static String quote(String s) {
}

private static boolean needsQuote(String s) {
for (int i = 0, n = s.length(); i < n; i++) {
if (!s.isEmpty()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field name can contain '$' ? The new code doesn't cover when '$' is in the middle of the field like 'te$st'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is valid to use $ in the middle of an identifier. It is invalid only when it is at the beginning of the string.

db.zip.aggregate({ $project: { te$st: "$zip_code" } })

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Looks good. Do you think we should add this case in a unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because $ in the middle will work in any case, whether quoted or unquoted. Instead of writing all possible tests for quoting, it would be better to rewrite the Mongo adapter to use MongoDB builders. This way, we can avoid such mistakes.

See: https://issues.apache.org/jira/browse/CALCITE-6510

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly modified code and test cases do not cover the original code logic. Testing coverage is not enough for this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your reply, I know it works for me. But only focus on the code, I don't know.

Copy link
Contributor Author

@dssysolyatin dssysolyatin Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the best option would be to find a specification for fieldName and add it as a comment. I will try to find it tomorrow. Because usually, people don't write tests to check if letters 'e', 'a', or 'b' are allowed in the middle of a string if the specification states that they are allowed.

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

Successfully merging this pull request may close these issues.

2 participants