Skip to content

Commit

Permalink
[hotfix] fix table name not escaped during routing (apache#12212)
Browse files Browse the repository at this point in the history
the table name is not escaped during routing entry discovery. this adds a double quote around the table name for dummy query

Co-authored-by: Rong Rong <[email protected]>
  • Loading branch information
walterddr and Rong Rong authored Jan 3, 2024
1 parent f9df57a commit add2236
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private RoutingTable getRoutingTable(String tableName, TableType tableType, long
String tableNameWithType =
TableNameBuilder.forType(tableType).tableNameWithType(TableNameBuilder.extractRawTableName(tableName));
return _routingManager.getRoutingTable(
CalciteSqlCompiler.compileToBrokerRequest("SELECT * FROM " + tableNameWithType), requestId);
CalciteSqlCompiler.compileToBrokerRequest("SELECT * FROM \"" + tableNameWithType + "\""), requestId);
}

// --------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ public void setUp()
factory1.registerTable(SCHEMA_BUILDER.setSchemaName("b").build(), "b_REALTIME");
factory1.registerTable(SCHEMA_BUILDER.setSchemaName("c").build(), "c_OFFLINE");
factory1.registerTable(SCHEMA_BUILDER.setSchemaName("d").build(), "d");
factory1.registerTable(SCHEMA_BUILDER.setSchemaName("tbl-escape.naming").build(), "tbl-escape.naming_OFFLINE");
factory1.addSegment("a_REALTIME", buildRows("a_REALTIME"));
factory1.addSegment("a_REALTIME", buildRows("a_REALTIME"));
factory1.addSegment("b_REALTIME", buildRows("b_REALTIME"));
factory1.addSegment("c_OFFLINE", buildRows("c_OFFLINE"));
factory1.addSegment("d_OFFLINE", buildRows("d_OFFLINE"));
factory1.addSegment("tbl-escape.naming_OFFLINE", buildRows("tbl-escape.naming_OFFLINE"));

MockInstanceDataManagerFactory factory2 = new MockInstanceDataManagerFactory("server2");
factory2.registerTable(SCHEMA_BUILDER.setSchemaName("a").build(), "a_REALTIME");
Expand Down Expand Up @@ -245,22 +247,18 @@ private Object[][] provideTestSqlAndRowCount() {
new Object[]{"SET multiStageLeafLimit = 1; SELECT * FROM a", 2},

// test groups limit in both leaf and intermediate stage
new Object[]{"SET numGroupsLimit = 1; SELECT col1, COUNT(*) FROM a GROUP BY col1", 1}, new Object[]{"SET "
+ "numGroupsLimit = 2; SELECT col1, COUNT(*) FROM a GROUP BY col1", 2}, new Object[]{
"SET numGroupsLimit = 1; "
+ "SELECT a.col2, b.col2, COUNT(*) FROM a JOIN b USING (col1) GROUP BY a.col2, b.col2", 1
}, new Object[]{
"SET numGroupsLimit = 2; "
+ "SELECT a.col2, b.col2, COUNT(*) FROM a JOIN b USING (col1) GROUP BY a.col2, b.col2", 2
},
new Object[]{"SET numGroupsLimit = 1; SELECT col1, COUNT(*) FROM a GROUP BY col1", 1},
new Object[]{"SET " + "numGroupsLimit = 2; SELECT col1, COUNT(*) FROM a GROUP BY col1", 2},
new Object[]{"SET numGroupsLimit = 1; "
+ "SELECT a.col2, b.col2, COUNT(*) FROM a JOIN b USING (col1) GROUP BY a.col2, b.col2", 1},
new Object[]{"SET numGroupsLimit = 2; "
+ "SELECT a.col2, b.col2, COUNT(*) FROM a JOIN b USING (col1) GROUP BY a.col2, b.col2", 2},
// TODO: Consider pushing down hint to the leaf stage
new Object[]{
"SET numGroupsLimit = 2; SELECT /*+ aggOptions(num_groups_limit='1') */ "
+ "col1, COUNT(*) FROM a GROUP BY col1", 2
}, new Object[]{
"SET numGroupsLimit = 2; SELECT /*+ aggOptions(num_groups_limit='1') */ "
+ "a.col2, b.col2, COUNT(*) FROM a JOIN b USING (col1) GROUP BY a.col2, b.col2", 1
}
new Object[]{"SET numGroupsLimit = 2; SELECT /*+ aggOptions(num_groups_limit='1') */ "
+ "col1, COUNT(*) FROM a GROUP BY col1", 2},
new Object[]{"SET numGroupsLimit = 2; SELECT /*+ aggOptions(num_groups_limit='1') */ "
+ "a.col2, b.col2, COUNT(*) FROM a JOIN b USING (col1) GROUP BY a.col2, b.col2", 1},
new Object[]{"SELECT * FROM \"tbl-escape.naming\"", 5}
};
}

Expand Down Expand Up @@ -304,9 +302,8 @@ private Object[][] provideTestSqlWithExecutionException() {
// - checked "Illegal Json Path" as col1 is not actually a json string, but the call is correctly triggered.
new Object[]{"SELECT CAST(jsonExtractScalar(col1, 'path', 'INT') AS INT) FROM a", "Illegal Json Path"},
// - checked function cannot be found b/c there's no intermediate stage impl for json_extract_scalar
// TODO: re-enable this test once we have implemented constructor time error pipe back.
// new Object[]{"SELECT CAST(json_extract_scalar(a.col1, b.col2, 'INT') AS INT)"
// + "FROM a JOIN b ON a.col1 = b.col1", "Cannot find function with Name: json_extract_scalar"},
new Object[]{"SELECT CAST(json_extract_scalar(a.col1, b.col2, 'INT') AS INT)"
+ "FROM a JOIN b ON a.col1 = b.col1", "Cannot find function with name: JSON_EXTRACT_SCALAR"},
};
}
}

0 comments on commit add2236

Please sign in to comment.