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-6026] MongoDB: Column is not quoted in "order by" clause and throws JsonParseException #3443

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

tindzk
Copy link
Contributor

@tindzk tindzk commented Sep 26, 2023

The following query fails with a JsonParseException:

select state as "STATE", avg(pop) as "AVG(pop)"
from zips
group by "STATE"
order by "AVG(pop)"

Stack trace:

org.bson.json.JsonParseException: JSON reader was expecting ':' but found '('.
	at org.bson.json.JsonReader.readBsonType(JsonReader.java:150)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:85)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42)
	at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:104)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87)
	at org.bson.BsonDocument.parse(BsonDocument.java:66)
	at org.apache.calcite.adapter.mongodb.MongoTable.aggregate(MongoTable.java:138)
	at org.apache.calcite.adapter.mongodb.MongoTable.access$200(MongoTable.java:53)
	at org.apache.calcite.adapter.mongodb.MongoTable$MongoQueryable.aggregate(MongoTable.java:189)

This is caused by the column name in the order by clause not being escaped.

… throws JsonParseException

The following query fails with a `JsonParseException`:

```sql
select state as "STATE", avg(pop) as "AVG(pop)"
from zips
group by "STATE"
order by "AVG(pop)"
```

Stack trace:
```
org.bson.json.JsonParseException: JSON reader was expecting ':' but found '('.
	at org.bson.json.JsonReader.readBsonType(JsonReader.java:150)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:85)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42)
	at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:104)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87)
	at org.bson.BsonDocument.parse(BsonDocument.java:66)
	at org.apache.calcite.adapter.mongodb.MongoTable.aggregate(MongoTable.java:138)
	at org.apache.calcite.adapter.mongodb.MongoTable.access$200(MongoTable.java:53)
	at org.apache.calcite.adapter.mongodb.MongoTable$MongoQueryable.aggregate(MongoTable.java:189)
```

This is caused by the column name in the `order by` clause not being escaped.
@sonarcloud
Copy link

sonarcloud bot commented Sep 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@dssysolyatin
Copy link
Contributor

LGTM

@dssysolyatin dssysolyatin merged commit 683e4ae into apache:main Sep 26, 2023
18 checks passed
@tindzk tindzk deleted the fix/CALCITE-6026 branch September 26, 2023 08:46
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