Skip to content

Commit f6c5dcd

Browse files
vfragarafael-telles
authored andcommitted
Flight SQL Ratification Based On Community Feedback #6 (apache#94)
* Refactored FlightSql Statement Constant names * Defined non-nullable parameters for FlightSql proto * Resolved minimal checkstyle issues * Added further documentation for catalog and schema * Refactored FlightSql proto comments to include more information * Added Field/FieldType notNullable methods * Refactored FlightSqlClient and FlightSqlExample to leverage Field notNullable method * Removed opaque query warning from FlightSql proto * Added the optional tag for the returned schema of getTables to proto
1 parent 1bb2499 commit f6c5dcd

7 files changed

Lines changed: 119 additions & 77 deletions

File tree

format/FlightSql.proto

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ package arrow.flight.protocol.sql;
3131
*
3232
* The returned schema will be:
3333
* <
34-
* info_name: uint32,
34+
* info_name: uint32 not null,
3535
* value: dense_union<string_value: string, int_value: int32, bigint_value: int64, int32_bitmask: int32>
3636
* >
3737
* where there is one row per requested piece of metadata information.
@@ -156,7 +156,7 @@ enum SqlInfo {
156156
*
157157
* The returned schema will be:
158158
* <
159-
* catalog_name: utf8
159+
* catalog_name: utf8 not null
160160
* >
161161
* The returned data should be ordered by catalog_name.
162162
*/
@@ -173,16 +173,17 @@ message CommandGetCatalogs {
173173
* The returned schema will be:
174174
* <
175175
* catalog_name: utf8,
176-
* schema_name: utf8
176+
* schema_name: utf8 not null
177177
* >
178178
* The returned data should be ordered by catalog_name, then schema_name.
179179
*/
180180
message CommandGetSchemas {
181181
option (experimental) = true;
182182

183183
/*
184-
* Specifies the Catalog to search for schemas.
185-
* If omitted, then all catalogs are searched.
184+
* Specifies the Catalog to search for the tables.
185+
* An empty string retrieves those without a catalog.
186+
* If omitted the catalog name should not be used to narrow the search.
186187
*/
187188
google.protobuf.StringValue catalog = 1;
188189

@@ -206,18 +207,20 @@ message CommandGetSchemas {
206207
* <
207208
* catalog_name: utf8,
208209
* schema_name: utf8,
209-
* table_name: utf8,
210-
* table_type: utf8,
211-
* table_schema: bytes (schema of the table as described in Schema.fbs::Schema, it is serialized as an IPC message.)
210+
* table_name: utf8 not null,
211+
* table_type: utf8 not null,
212+
* [optional] table_schema: bytes not null (schema of the table as described in Schema.fbs::Schema,
213+
* it is serialized as an IPC message.)
212214
* >
213-
* The returned data should be ordered by catalog_name, schema_name, table_name, then table_type.
215+
* The returned data should be ordered by catalog_name, schema_name, table_name, then table_type, followed by table_schema if requested.
214216
*/
215217
message CommandGetTables {
216218
option (experimental) = true;
217219

218220
/*
219221
* Specifies the Catalog to search for the tables.
220-
* If omitted, then all catalogs are searched.
222+
* An empty string retrieves those without a catalog.
223+
* If omitted the catalog name should not be used to narrow the search.
221224
*/
222225
google.protobuf.StringValue catalog = 1;
223226

@@ -254,7 +257,7 @@ message CommandGetTables {
254257
*
255258
* The returned schema will be:
256259
* <
257-
* table_type: utf8
260+
* table_type: utf8 not null
258261
* >
259262
* The returned data should be ordered by table_type.
260263
*/
@@ -282,14 +285,22 @@ message CommandGetTableTypes {
282285
message CommandGetPrimaryKeys {
283286
option (experimental) = true;
284287

285-
// Specifies the catalog to search for the table.
288+
/*
289+
* Specifies the catalog to search for the table.
290+
* An empty string retrieves those without a catalog.
291+
* If omitted the catalog name should not be used to narrow the search.
292+
*/
286293
google.protobuf.StringValue catalog = 1;
287294

288-
// Specifies the schema to search for the table.
295+
/*
296+
* Specifies the schema to search for the table.
297+
* An empty string retrieves those without a schema.
298+
* If omitted the schema name should not be used to narrow the search.
299+
*/
289300
google.protobuf.StringValue schema = 2;
290301

291302
// Specifies the table to get the primary keys for.
292-
google.protobuf.StringValue table = 3;
303+
string table = 3;
293304
}
294305

295306
/*
@@ -303,28 +314,36 @@ message CommandGetPrimaryKeys {
303314
* <
304315
* pk_catalog_name: utf8,
305316
* pk_schema_name: utf8,
306-
* pk_table_name: utf8,
307-
* pk_column_name: utf8,
317+
* pk_table_name: utf8 not null,
318+
* pk_column_name: utf8 not null,
308319
* fk_catalog_name: utf8,
309320
* fk_schema_name: utf8,
310-
* fk_table_name: utf8,
311-
* fk_column_name: utf8,
312-
* key_sequence: int,
321+
* fk_table_name: utf8 not null,
322+
* fk_column_name: utf8 not null,
323+
* key_sequence: int not null,
313324
* fk_key_name: utf8,
314325
* pk_key_name: utf8,
315-
* update_rule: uint1,
316-
* delete_rule: uint1
326+
* update_rule: uint1 not null,
327+
* delete_rule: uint1 not null
317328
* >
318329
* The returned data should be ordered by fk_catalog_name, fk_schema_name, fk_table_name, fk_key_name, then key_sequence.
319330
* update_rule and delete_rule returns a byte that is equivalent to actions declared on UpdateDeleteRules enum.
320331
*/
321332
message CommandGetExportedKeys {
322333
option (experimental) = true;
323334

324-
// Specifies the catalog to search for the foreign key table.
335+
/*
336+
* Specifies the catalog to search for the foreign key table.
337+
* An empty string retrieves those without a catalog.
338+
* If omitted the catalog name should not be used to narrow the search.
339+
*/
325340
google.protobuf.StringValue catalog = 1;
326341

327-
// Specifies the schema to search for the foreign key table.
342+
/*
343+
* Specifies the schema to search for the foreign key table.
344+
* An empty string retrieves those without a schema.
345+
* If omitted the schema name should not be used to narrow the search.
346+
*/
328347
google.protobuf.StringValue schema = 2;
329348

330349
// Specifies the foreign key table to get the foreign keys for.
@@ -349,17 +368,17 @@ enum UpdateDeleteRules {
349368
* <
350369
* pk_catalog_name: utf8,
351370
* pk_schema_name: utf8,
352-
* pk_table_name: utf8,
353-
* pk_column_name: utf8,
371+
* pk_table_name: utf8 not null,
372+
* pk_column_name: utf8 not null,
354373
* fk_catalog_name: utf8,
355374
* fk_schema_name: utf8,
356-
* fk_table_name: utf8,
357-
* fk_column_name: utf8,
358-
* key_sequence: int,
375+
* fk_table_name: utf8 not null,
376+
* fk_column_name: utf8 not null,
377+
* key_sequence: int not null,
359378
* fk_key_name: utf8,
360379
* pk_key_name: utf8,
361-
* update_rule: uint1,
362-
* delete_rule: uint1
380+
* update_rule: uint1 not null,
381+
* delete_rule: uint1 not null
363382
* >
364383
* The returned data should be ordered by pk_catalog_name, pk_schema_name, pk_table_name, pk_key_name, then key_sequence.
365384
* update_rule and delete_rule returns a byte that is equivalent to actions:
@@ -372,10 +391,18 @@ enum UpdateDeleteRules {
372391
message CommandGetImportedKeys {
373392
option (experimental) = true;
374393

375-
// Specifies the catalog to search for the primary key table.
394+
/*
395+
* Specifies the catalog to search for the primary key table.
396+
* An empty string retrieves those without a catalog.
397+
* If omitted the catalog name should not be used to narrow the search.
398+
*/
376399
google.protobuf.StringValue catalog = 1;
377400

378-
// Specifies the schema to search for the primary key table.
401+
/*
402+
* Specifies the schema to search for the primary key table.
403+
* An empty string retrieves those without a schema.
404+
* If omitted the schema name should not be used to narrow the search.
405+
*/
379406
google.protobuf.StringValue schema = 2;
380407

381408
// Specifies the primary key table to get the foreign keys for.
@@ -391,12 +418,15 @@ message ActionCreatePreparedStatementRequest {
391418
option (experimental) = true;
392419

393420
// The valid SQL string to create a prepared statement for.
394-
// The query should be treated as an opaque value, that is, clients should not attempt to parse this.
395421
string query = 1;
396422
}
397423

398424
/*
399425
* Wrap the result of a "GetPreparedStatement" action.
426+
*
427+
* The resultant PreparedStatement can be closed either:
428+
* - Manually, through the "ClosePreparedStatement" action;
429+
* - Automatically, by a server timeout.
400430
*/
401431
message ActionCreatePreparedStatementResult {
402432
option (experimental) = true;
@@ -437,7 +467,6 @@ message CommandStatementQuery {
437467
option (experimental) = true;
438468

439469
// The SQL syntax.
440-
// The query should be treated as an opaque value, that is, clients should not attempt to parse this.
441470
string query = 1;
442471
}
443472

@@ -473,7 +502,6 @@ message CommandStatementUpdate {
473502
option (experimental) = true;
474503

475504
// The SQL syntax.
476-
// The query should be treated as an opaque value, that is, clients should not attempt to parse this.
477505
string query = 1;
478506
}
479507

java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ public FlightInfo getPrimaryKeys(final String catalog, final String schema,
266266
builder.setSchema(StringValue.newBuilder().setValue(schema).build());
267267
}
268268

269-
if (table != null) {
270-
builder.setTable(StringValue.newBuilder().setValue(table).build());
271-
}
269+
Objects.requireNonNull(table);
270+
builder.setTable(table).build();
271+
272272
final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray());
273273
return client.getInfo(descriptor, options);
274274
}
@@ -376,7 +376,7 @@ public static class PreparedStatement implements AutoCloseable {
376376
public PreparedStatement(final FlightClient client, final String sql, final CallOption... options) {
377377
this.client = client;
378378
final Action action = new Action(
379-
FlightSqlUtils.FLIGHT_SQL_CREATEPREPAREDSTATEMENT.getType(),
379+
FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT.getType(),
380380
Any.pack(ActionCreatePreparedStatementRequest
381381
.newBuilder()
382382
.setQuery(sql)
@@ -530,7 +530,7 @@ public void close(final CallOption... options) {
530530
}
531531
isClosed = true;
532532
final Action action = new Action(
533-
FlightSqlUtils.FLIGHT_SQL_CLOSEPREPAREDSTATEMENT.getType(),
533+
FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.getType(),
534534
Any.pack(ActionClosePreparedStatementRequest.newBuilder()
535535
.setPreparedStatementHandle(preparedStatementResult.getPreparedStatementHandle())
536536
.build())

java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ default void listActions(CallContext context, StreamListener<ActionType> listene
250250
@Override
251251
default void doAction(CallContext context, Action action, StreamListener<Result> listener) {
252252
final String actionType = action.getType();
253-
if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CREATEPREPAREDSTATEMENT.getType())) {
253+
if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT.getType())) {
254254
final ActionCreatePreparedStatementRequest request = FlightSqlUtils.unpackAndParseOrThrow(action.getBody(),
255255
ActionCreatePreparedStatementRequest.class);
256256
createPreparedStatement(request, context, listener);
257-
} else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CLOSEPREPAREDSTATEMENT.getType())) {
257+
} else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.getType())) {
258258
final ActionClosePreparedStatementRequest request = FlightSqlUtils.unpackAndParseOrThrow(action.getBody(),
259259
ActionClosePreparedStatementRequest.class);
260260
closePreparedStatement(request, context, listener);
@@ -566,38 +566,38 @@ final class Schemas {
566566
public static final Schema GET_TABLES_SCHEMA = new Schema(Arrays.asList(
567567
Field.nullable("catalog_name", MinorType.VARCHAR.getType()),
568568
Field.nullable("schema_name", MinorType.VARCHAR.getType()),
569-
Field.nullable("table_name", MinorType.VARCHAR.getType()),
570-
Field.nullable("table_type", MinorType.VARCHAR.getType()),
571-
Field.nullable("table_schema", MinorType.VARBINARY.getType())));
569+
Field.notNullable("table_name", MinorType.VARCHAR.getType()),
570+
Field.notNullable("table_type", MinorType.VARCHAR.getType()),
571+
Field.notNullable("table_schema", MinorType.VARBINARY.getType())));
572572
public static final Schema GET_TABLES_SCHEMA_NO_SCHEMA = new Schema(Arrays.asList(
573573
Field.nullable("catalog_name", MinorType.VARCHAR.getType()),
574574
Field.nullable("schema_name", MinorType.VARCHAR.getType()),
575-
Field.nullable("table_name", MinorType.VARCHAR.getType()),
576-
Field.nullable("table_type", MinorType.VARCHAR.getType())));
575+
Field.notNullable("table_name", MinorType.VARCHAR.getType()),
576+
Field.notNullable("table_type", MinorType.VARCHAR.getType())));
577577
public static final Schema GET_CATALOGS_SCHEMA = new Schema(
578-
Collections.singletonList(new Field("catalog_name", FieldType.nullable(MinorType.VARCHAR.getType()), null)));
578+
Collections.singletonList(Field.notNullable("catalog_name", MinorType.VARCHAR.getType())));
579579
public static final Schema GET_TABLE_TYPES_SCHEMA =
580-
new Schema(Collections.singletonList(Field.nullable("table_type", MinorType.VARCHAR.getType())));
580+
new Schema(Collections.singletonList(Field.notNullable("table_type", MinorType.VARCHAR.getType())));
581581
public static final Schema GET_SCHEMAS_SCHEMA = new Schema(
582582
Arrays.asList(Field.nullable("catalog_name", MinorType.VARCHAR.getType()),
583-
Field.nullable("schema_name", MinorType.VARCHAR.getType())));
583+
Field.notNullable("schema_name", MinorType.VARCHAR.getType())));
584584
public static final Schema GET_IMPORTED_AND_EXPORTED_KEYS_SCHEMA = new Schema(Arrays.asList(
585585
Field.nullable("pk_catalog_name", MinorType.VARCHAR.getType()),
586586
Field.nullable("pk_schema_name", MinorType.VARCHAR.getType()),
587-
Field.nullable("pk_table_name", MinorType.VARCHAR.getType()),
588-
Field.nullable("pk_column_name", MinorType.VARCHAR.getType()),
587+
Field.notNullable("pk_table_name", MinorType.VARCHAR.getType()),
588+
Field.notNullable("pk_column_name", MinorType.VARCHAR.getType()),
589589
Field.nullable("fk_catalog_name", MinorType.VARCHAR.getType()),
590590
Field.nullable("fk_schema_name", MinorType.VARCHAR.getType()),
591-
Field.nullable("fk_table_name", MinorType.VARCHAR.getType()),
592-
Field.nullable("fk_column_name", MinorType.VARCHAR.getType()),
593-
Field.nullable("key_sequence", MinorType.INT.getType()),
591+
Field.notNullable("fk_table_name", MinorType.VARCHAR.getType()),
592+
Field.notNullable("fk_column_name", MinorType.VARCHAR.getType()),
593+
Field.notNullable("key_sequence", MinorType.INT.getType()),
594594
Field.nullable("fk_key_name", MinorType.VARCHAR.getType()),
595595
Field.nullable("pk_key_name", MinorType.VARCHAR.getType()),
596-
Field.nullable("update_rule", new ArrowType.Int(8, false)),
597-
Field.nullable("delete_rule", new ArrowType.Int(8, false))));
596+
Field.notNullable("update_rule", new ArrowType.Int(8, false)),
597+
Field.notNullable("delete_rule", new ArrowType.Int(8, false))));
598598
public static final Schema GET_SQL_INFO_SCHEMA =
599599
new Schema(Arrays.asList(
600-
Field.nullable("info_name", new ArrowType.Int(32, false)),
600+
Field.notNullable("info_name", new ArrowType.Int(32, false)),
601601
new Field("value",
602602
// dense_union<string_value: string, int_value: int32, bigint_value: int64, int32_bitmask: int32>
603603
new FieldType(true, new Union(UnionMode.Dense, new int[] {0, 1, 2, 3}), /*dictionary=*/null),
@@ -609,9 +609,9 @@ final class Schemas {
609609
public static final Schema GET_PRIMARY_KEYS_SCHEMA = new Schema(Arrays.asList(
610610
Field.nullable("catalog_name", MinorType.VARCHAR.getType()),
611611
Field.nullable("schema_name", MinorType.VARCHAR.getType()),
612-
Field.nullable("table_name", MinorType.VARCHAR.getType()),
613-
Field.nullable("column_name", MinorType.VARCHAR.getType()),
614-
Field.nullable("key_sequence", MinorType.INT.getType()),
612+
Field.notNullable("table_name", MinorType.VARCHAR.getType()),
613+
Field.notNullable("column_name", MinorType.VARCHAR.getType()),
614+
Field.notNullable("key_sequence", MinorType.INT.getType()),
615615
Field.nullable("key_name", MinorType.VARCHAR.getType())));
616616

617617
private Schemas() {

java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131
* Utilities to work with Flight SQL semantics.
3232
*/
3333
public final class FlightSqlUtils {
34-
public static final ActionType FLIGHT_SQL_CREATEPREPAREDSTATEMENT = new ActionType("CreatePreparedStatement",
34+
public static final ActionType FLIGHT_SQL_CREATE_PREPARED_STATEMENT = new ActionType("CreatePreparedStatement",
3535
"Creates a reusable prepared statement resource on the server. \n" +
3636
"Request Message: ActionCreatePreparedStatementRequest\n" +
3737
"Response Message: ActionCreatePreparedStatementResult");
3838

39-
public static final ActionType FLIGHT_SQL_CLOSEPREPAREDSTATEMENT = new ActionType("ClosePreparedStatement",
39+
public static final ActionType FLIGHT_SQL_CLOSE_PREPARED_STATEMENT = new ActionType("ClosePreparedStatement",
4040
"Closes a reusable prepared statement resource on the server. \n" +
4141
"Request Message: ActionClosePreparedStatementRequest\n" +
4242
"Response Message: N/A");
4343

4444
public static final List<ActionType> FLIGHT_SQL_ACTIONS = ImmutableList.of(
45-
FLIGHT_SQL_CREATEPREPAREDSTATEMENT,
46-
FLIGHT_SQL_CLOSEPREPAREDSTATEMENT
45+
FLIGHT_SQL_CREATE_PREPARED_STATEMENT,
46+
FLIGHT_SQL_CLOSE_PREPARED_STATEMENT
4747
);
4848

4949
/**

0 commit comments

Comments
 (0)