Skip to content

Commit 1258c51

Browse files
morningmanclaude
andcommitted
[fix](arrow-flight) Match the common Flight SQL table type names in GetTables
### What problem does this PR solve? Issue Number: None Related PR: #67899 Problem Summary: GetTables now filters the authorized tables by every requested table type with an exact match against Doris's names (BASE TABLE, VIEW, SYSTEM VIEW). Clients do not send those names. Flight SQL leaves the names to the server but calls TABLE, VIEW and SYSTEM TABLE the commonly supported ones, and that is what clients ask for: the ADBC Flight SQL driver sends "table" (Doris's own ADBC catalog lists tables with getObjects(..., {"table"})), JDBC tools send "TABLE". Before the exact filter, Doris only recognised VIEW and answered every other type with all objects, so these requests worked; with it they match nothing. Reproduction: an ADBC catalog whose source is a Doris Arrow Flight SQL endpoint lists no tables, so SHOW TABLES is empty and every query fails with "Unknown table" (all 18 external_table_p0/adbc suites fail in the External pipeline); JDBC getTables(..., {"TABLE"}) returns no rows and {"TABLE", "VIEW"} returns only views. Fix: map each requested type before matching. The comparison ignores case, TABLE selects BASE TABLE and SYSTEM TABLE selects SYSTEM VIEW; any other name still matches only a type of that name, so UNKNOWN still selects nothing. ### Release note None ### Check List (For Author) - Test: Unit Test / Regression test - FlightSqlSchemaHelperTableTypesTest: table, TABLE + VIEW, view, SYSTEM TABLE and mixed-case names, with and without schemas - test_table_types_over_arrow_flight: TABLE, table, table + view through Flight SQL JDBC - external_table_p0/adbc suites against a local cluster - Behavior changed: No (restores the listing these clients got before the multi-type filter) - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2a31c4d commit 1258c51

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/arrowflight/FlightSqlSchemaHelper.java‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import java.util.HashMap;
6666
import java.util.LinkedHashSet;
6767
import java.util.List;
68+
import java.util.Locale;
6869
import java.util.Map;
6970
import java.util.Objects;
7071
import java.util.Set;
@@ -84,7 +85,7 @@ public class FlightSqlSchemaHelper {
8485
private String catalogFilterPattern = null;
8586
private String dbSchemaFilterPattern = null;
8687
private String tableNameFilterPattern = null;
87-
private List<String> tableTypesList = null;
88+
private Set<String> tableTypeFilter = null;
8889

8990
public FlightSqlSchemaHelper(ConnectContext context) {
9091
ctx = context;
@@ -170,7 +171,28 @@ public void setParameterForGetTables(CommandGetTables command) {
170171
catalogFilterPattern = command.hasCatalog() ? command.getCatalog() : "internal";
171172
dbSchemaFilterPattern = command.hasDbSchemaFilterPattern() ? command.getDbSchemaFilterPattern() : null;
172173
tableNameFilterPattern = command.hasTableNameFilterPattern() ? command.getTableNameFilterPattern() : null;
173-
tableTypesList = command.getTableTypesList().isEmpty() ? null : command.getTableTypesList();
174+
tableTypeFilter = command.getTableTypesList().isEmpty() ? null
175+
: command.getTableTypesList().stream().map(FlightSqlSchemaHelper::toDorisTableType)
176+
.collect(Collectors.toSet());
177+
}
178+
179+
/**
180+
* Maps a type a GetTables request filters on to the name GetTableTypes advertises. Flight SQL leaves the
181+
* names to the server but calls TABLE, VIEW and SYSTEM TABLE the commonly supported ones, and clients send
182+
* those in either case: the ADBC Flight SQL driver asks for "table", JDBC tools for "TABLE". So a type
183+
* matches case-insensitively, and TABLE and SYSTEM TABLE select BASE TABLE and SYSTEM VIEW. Any other name
184+
* matches only a type of that name.
185+
*/
186+
private static String toDorisTableType(String requestedType) {
187+
String type = requestedType.toUpperCase(Locale.ROOT);
188+
switch (type) {
189+
case "TABLE":
190+
return "BASE TABLE";
191+
case "SYSTEM TABLE":
192+
return "SYSTEM VIEW";
193+
default:
194+
return type;
195+
}
174196
}
175197

176198
/**
@@ -353,10 +375,10 @@ public void getTables(VectorSchemaRoot vectorSchemaRoot) throws TException {
353375
String dbName = getDbsResult.getDbs().get(dbIndex);
354376
String catalogName = getDbsResult.isSetCatalogs() ? getDbsResult.getCatalogs().get(dbIndex) : "";
355377
List<TTableStatus> tables = listTableStatus(dbName, catalogName).getTables();
356-
if (tableTypesList != null) {
378+
if (tableTypeFilter != null) {
357379
// The service's single-type filter only handles VIEW. Match all requested types here
358380
// against the authorized results, before collecting their optional schemas.
359-
tables = tables.stream().filter(table -> tableTypesList.contains(table.getType()))
381+
tables = tables.stream().filter(table -> tableTypeFilter.contains(table.getType()))
360382
.collect(Collectors.toList());
361383
}
362384
if (tables.isEmpty()) {

‎fe/fe-core/src/test/java/org/apache/doris/arrowflight/FlightSqlSchemaHelperTableTypesTest.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ private static Stream<Arguments> tableFilters() {
6969
Arguments.of(includeSchema, Arrays.asList("SYSTEM VIEW"), Arrays.asList("system")),
7070
Arguments.of(includeSchema, Arrays.asList("VIEW"), Arrays.asList("view")),
7171
Arguments.of(includeSchema, Arrays.asList("UNKNOWN"), Collections.emptyList()),
72-
Arguments.of(includeSchema, Arrays.asList("UNKNOWN", "VIEW", "VIEW"), Arrays.asList("view"))));
72+
Arguments.of(includeSchema, Arrays.asList("UNKNOWN", "VIEW", "VIEW"), Arrays.asList("view")),
73+
// The names Flight SQL calls common, in the spellings clients send: the ADBC Flight SQL
74+
// driver asks for "table", JDBC tools for "TABLE".
75+
Arguments.of(includeSchema, Arrays.asList("table"), Arrays.asList("base")),
76+
Arguments.of(includeSchema, Arrays.asList("TABLE", "VIEW"), Arrays.asList("base", "view")),
77+
Arguments.of(includeSchema, Arrays.asList("view"), Arrays.asList("view")),
78+
Arguments.of(includeSchema, Arrays.asList("SYSTEM TABLE"), Arrays.asList("system")),
79+
Arguments.of(includeSchema, Arrays.asList("base table", "System View"),
80+
Arrays.asList("base", "system"))));
7381
}
7482

7583
@ParameterizedTest

‎regression-test/suites/arrow_flight_sql_p0/test_table_types_over_arrow_flight.groovy‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ suite("test_table_types_over_arrow_flight", "arrow_flight_sql") {
8686
assertEquals([], getTables(["SYSTEM VIEW"]))
8787
assertEquals([], getTables(["UNKNOWN"]))
8888
assertEquals([view], getTables(["UNKNOWN", "VIEW", "VIEW"]))
89+
// Flight SQL calls TABLE, VIEW and SYSTEM TABLE the commonly supported names, and clients send them
90+
// in either case: the ADBC Flight SQL driver asks for "table", JDBC tools for "TABLE".
91+
assertEquals([baseTable], getTables(["TABLE"]))
92+
assertEquals([baseTable], getTables(["table"]))
93+
assertEquals([baseTable, view], getTables(["table", "view"]))
8994

9095
// The same RPCs from a plain Flight SQL client, called repeatedly: GetFlightInfo carries the
9196
// GetTableTypes schema and one endpoint, DoGet returns the same sorted types every time, and

0 commit comments

Comments
 (0)