Skip to content

Commit

Permalink
[CALCITE-6509] MongoAdapter throws 'Invalid JSON Number' exception if…
Browse files Browse the repository at this point in the history
… first character of field name is number
  • Loading branch information
dssysolyatin authored and dssysolyatin committed Aug 1, 2024
1 parent 61ee73e commit 1ccd12e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
&& (!Character.isJavaIdentifierStart(s.charAt(0)) || s.charAt(0) == '$')) {
return true;
}

for (int i = 1, n = s.length(); i < n; i++) {
char c = s.charAt(i);
if (!Character.isJavaIdentifierPart(c)
|| c == '$') {
if (!Character.isJavaIdentifierPart(c)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static void setUp() throws Exception {
doc.put("value", new BsonInt32(1231));
doc.put("ownerId", new BsonString("531e7789e4b0853ddb861313"));
doc.put("arr", new BsonArray(Arrays.asList(new BsonString("a"), new BsonString("b"))));
doc.put("1_minute_aggregation", new BsonInt32(10));
datatypes.insertOne(doc);

schema = new MongoSchema(database);
Expand Down Expand Up @@ -605,18 +606,22 @@ private CalciteAssert.AssertThat assertModel(URL url) {
"{$limit: 5}"));
}

@Disabled("broken; [CALCITE-2115] is logged to fix it")
@Test void testProject() {
assertModel(MODEL)
.query("select state, city, 0 as zero from zips order by state, city")
.limit(2)
.returns("STATE=AK; CITY=AKHIOK; ZERO=0\n"
+ "STATE=AK; CITY=AKIACHAK; ZERO=0\n")
.returns("STATE=AK; CITY=ANCHORAGE; ZERO=0\n"
+ "STATE=AK; CITY=FAIRBANKS; ZERO=0\n")
.queryContains(
mongoChecker(
"{$project: {CITY: '$city', STATE: '$state'}}",
"{$sort: {STATE: 1, CITY: 1}}",
"{$project: {STATE: 1, CITY: 1, ZERO: {$literal: 0}}}"));
"{$project: {STATE: '$state', CITY: '$city', ZERO: {$literal: 0}}}",
"{$sort: {STATE: 1, CITY: 1}}"));

assertModel(MODEL)
.query("select cast(_MAP['1_minute_aggregation'] as INT) as \"1_minute_aggregation\" "
+ "from \"mongo_raw\".\"datatypes\"")
.queryContains(
mongoChecker("{$project: {'1_minute_aggregation': 1}}"));
}

@Test void testFilter() {
Expand Down

0 comments on commit 1ccd12e

Please sign in to comment.