lidavidm commented on a change in pull request #9368:
URL: https://github.com/apache/arrow/pull/9368#discussion_r572929697



##########
File path: format/FlightSQL.proto
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+option java_package = "org.apache.arrow.flight.sql.impl";
+package arrow.flight.protocol.sql;
+
+/*
+ * Wrapper for the result of a "GetSQLInfo" action.
+ */
+message ActionGetSQLInfoResult {
+  /*
+   * Values are modelled after ODBC's SQLGetInfo() function. This information 
is intended to provide
+   * Flight SQL clients with basic, SQL syntax and SQL functions related 
information.
+   * More information types can be added in future releases.
+   * E.g. more SQL syntax support types, scalar functions support, type 
conversion support etc.
+   *
+   * Initially, Flight SQL will support the following information types:
+   * - Server Information
+   * -
+   *
+   * 1. Server Information: Provides basic information about the Flight SQL 
Server.
+   *
+   * The name of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_NAME
+   *
+   * The native version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_VERSION
+   *
+   * The Arrow version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_ARROW_VERSION
+   *
+   * Indicates whether the Flight SQL Server is read only.
+   * FLIGHT_SQL_SERVER_READ_ONLY
+   *
+   * Indicates whether the Flight SQL Server supports both read and write.
+   * FLIGHT_SQL_SERVER_READ_WRITE

Review comment:
       These two seem redundant.

##########
File path: format/FlightSQL.proto
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+option java_package = "org.apache.arrow.flight.sql.impl";
+package arrow.flight.protocol.sql;
+
+/*
+ * Wrapper for the result of a "GetSQLInfo" action.
+ */
+message ActionGetSQLInfoResult {
+  /*
+   * Values are modelled after ODBC's SQLGetInfo() function. This information 
is intended to provide
+   * Flight SQL clients with basic, SQL syntax and SQL functions related 
information.
+   * More information types can be added in future releases.
+   * E.g. more SQL syntax support types, scalar functions support, type 
conversion support etc.
+   *
+   * Initially, Flight SQL will support the following information types:
+   * - Server Information
+   * -
+   *
+   * 1. Server Information: Provides basic information about the Flight SQL 
Server.
+   *
+   * The name of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_NAME
+   *
+   * The native version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_VERSION
+   *
+   * The Arrow version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_ARROW_VERSION
+   *
+   * Indicates whether the Flight SQL Server is read only.
+   * FLIGHT_SQL_SERVER_READ_ONLY
+   *
+   * Indicates whether the Flight SQL Server supports both read and write.
+   * FLIGHT_SQL_SERVER_READ_WRITE
+   *
+   * 2. SQL Syntax Information: provides information about SQL syntax 
supported by the Flight SQL Server.
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
catalogs.
+   * In a SQL environment, a catalog is a collection of schemas.
+   * SQL_DDL_CATALOG
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
schemas.
+   * In a SQL environment, a catalog is a collection of tables, views, indexes 
etc.
+   * SQL_DDL_SCHEMA
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
tables.
+   * In a SQL environment, a table is a collection of rows of information. 
Each row of information
+   * may have one or more columns of data.
+   * SQL_DDL_TABLE
+   *
+   * Indicates the case sensitivity of catalog, table and schema names.
+   * SQL_IDENTIFIER_CASE
+   *
+   * Indicates the supported character(s) used to surround a delimited 
identifier.
+   * SQL_IDENTIFIER_QUOTE_CHAR
+   *
+   * Indicates case sensitivity of quoted identifiers.
+   * SQL_QUOTED_IDENTIFIER_CASE
+   *
+   */
+  map<string, GetSQLInfoValue> flight_sql_info = 1;
+
+  // Implementation specific custom SQLInfo values.
+  map<string, GetSQLInfoValue> custom_info = 2;
+}
+
+/*
+ * Wrapper for values returned in ActionGetSQLInfoResult.
+ */
+message GetSQLInfoValue {
+  oneof value {
+    string string_value = 1;
+    int32 integer_value = 2;
+    int32 integer_bitmask = 3;
+    int32 integer_flag = 4;
+    bytes binary_value = 5;
+    int64 long_value = 6;
+  }
+}
+
+/*
+ * Request message for the "GetCatalogs" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of catalogs available in the server.
+ */
+message ActionGetCatalogsRequest {
+  /*
+   * Specifies the order of result values.
+   */ 
+  ResultsOrder order = 1;
+}
+
+/*
+ * Wrap the result of a "GetCatalogs" action.
+ */
+message ActionGetCatalogsResult {
+  repeated string catalog = 1;
+}
+
+/*
+ * Request message for the "GetSchemas" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of schemas available in the server.
+ */
+message ActionGetSchemasRequest {
+  /*
+   * Specifies the order of result values with precedence:
+   *  - catalog
+   *  - schema
+   */
+  ResultsOrder order = 1;
+
+  /*
+   * Specifies the Catalog to search for schemas.
+   * If omitted, then schemas for all catalogs are searched.
+   */ 
+  string catalog = 2;
+
+  /*
+   * Specifies a filter pattern for schemas to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.

Review comment:
       Where does this syntax come from? (If it's a particular vendor, can we 
avoid it in favor of more standard glob or SQL LIKE expressions?)

##########
File path: java/flight/flight-sql/src/test/protobuf/flightSQLExample.proto
##########
@@ -0,0 +1,26 @@
+/*

Review comment:
       Additionally shouldn't Protobuf file names be in snake_case? See 
https://developers.google.com/protocol-buffers/docs/style#file_structure

##########
File path: java/flight/flight-sql/src/test/protobuf/flightSQLExample.proto
##########
@@ -0,0 +1,26 @@
+/*

Review comment:
       I guess Flight.proto itself is already an exception...we should be 
consistent with what we have, though, yes (so `FlightSQLExample.proto` or 
preferably `FlightSql.proto` and `FlightSqlExample.proto`)

##########
File path: 
java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSQLUtils.java
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.flight.sql;
+
+import java.sql.Types;
+import java.util.List;
+
+import org.apache.arrow.flight.ActionType;
+import org.apache.arrow.vector.types.DateUnit;
+import org.apache.arrow.vector.types.FloatingPointPrecision;
+import org.apache.arrow.vector.types.TimeUnit;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+
+import com.google.common.collect.ImmutableList;
+import com.google.protobuf.Any;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.Message;
+
+/**
+ * Utilities to work with Flight SQL semantics.
+ */
+public final class FlightSQLUtils {
+
+  private static final int BIT_WIDTH8 = 8;
+  private static final int BIT_WIDTH_16 = 16;
+  private static final int BIT_WIDTH_32 = 32;
+  private static final int BIT_WIDTH_64 = 64;
+  private static final boolean IS_SIGNED_FALSE = false;
+  private static final boolean IS_SIGNED_TRUE = true;
+
+  public static final ActionType FLIGHT_SQL_GETSQLINFO = new 
ActionType("GetSQLINFO",

Review comment:
       nit: GetSqlInfo?

##########
File path: format/FlightSQL.proto
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+option java_package = "org.apache.arrow.flight.sql.impl";
+package arrow.flight.protocol.sql;
+
+/*
+ * Wrapper for the result of a "GetSQLInfo" action.
+ */
+message ActionGetSQLInfoResult {
+  /*
+   * Values are modelled after ODBC's SQLGetInfo() function. This information 
is intended to provide
+   * Flight SQL clients with basic, SQL syntax and SQL functions related 
information.
+   * More information types can be added in future releases.
+   * E.g. more SQL syntax support types, scalar functions support, type 
conversion support etc.
+   *
+   * Initially, Flight SQL will support the following information types:
+   * - Server Information
+   * -
+   *
+   * 1. Server Information: Provides basic information about the Flight SQL 
Server.
+   *
+   * The name of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_NAME
+   *
+   * The native version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_VERSION
+   *
+   * The Arrow version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_ARROW_VERSION
+   *
+   * Indicates whether the Flight SQL Server is read only.
+   * FLIGHT_SQL_SERVER_READ_ONLY
+   *
+   * Indicates whether the Flight SQL Server supports both read and write.
+   * FLIGHT_SQL_SERVER_READ_WRITE
+   *
+   * 2. SQL Syntax Information: provides information about SQL syntax 
supported by the Flight SQL Server.
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
catalogs.
+   * In a SQL environment, a catalog is a collection of schemas.
+   * SQL_DDL_CATALOG
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
schemas.
+   * In a SQL environment, a catalog is a collection of tables, views, indexes 
etc.
+   * SQL_DDL_SCHEMA
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
tables.
+   * In a SQL environment, a table is a collection of rows of information. 
Each row of information
+   * may have one or more columns of data.
+   * SQL_DDL_TABLE
+   *
+   * Indicates the case sensitivity of catalog, table and schema names.
+   * SQL_IDENTIFIER_CASE
+   *
+   * Indicates the supported character(s) used to surround a delimited 
identifier.
+   * SQL_IDENTIFIER_QUOTE_CHAR
+   *
+   * Indicates case sensitivity of quoted identifiers.
+   * SQL_QUOTED_IDENTIFIER_CASE
+   *
+   */
+  map<string, GetSQLInfoValue> flight_sql_info = 1;
+
+  // Implementation specific custom SQLInfo values.
+  map<string, GetSQLInfoValue> custom_info = 2;
+}
+
+/*
+ * Wrapper for values returned in ActionGetSQLInfoResult.
+ */
+message GetSQLInfoValue {
+  oneof value {
+    string string_value = 1;
+    int32 integer_value = 2;
+    int32 integer_bitmask = 3;
+    int32 integer_flag = 4;
+    bytes binary_value = 5;
+    int64 long_value = 6;
+  }
+}
+
+/*
+ * Request message for the "GetCatalogs" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of catalogs available in the server.
+ */
+message ActionGetCatalogsRequest {
+  /*
+   * Specifies the order of result values.
+   */ 
+  ResultsOrder order = 1;
+}
+
+/*
+ * Wrap the result of a "GetCatalogs" action.
+ */
+message ActionGetCatalogsResult {
+  repeated string catalog = 1;
+}
+
+/*
+ * Request message for the "GetSchemas" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of schemas available in the server.
+ */
+message ActionGetSchemasRequest {
+  /*
+   * Specifies the order of result values with precedence:
+   *  - catalog
+   *  - schema
+   */
+  ResultsOrder order = 1;
+
+  /*
+   * Specifies the Catalog to search for schemas.
+   * If omitted, then schemas for all catalogs are searched.
+   */ 
+  string catalog = 2;
+
+  /*
+   * Specifies a filter pattern for schemas to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string schema_filter_pattern = 3;
+}
+
+/*
+ * Wrap the result of a "GetSchemas" action.
+ */
+message ActionGetSchemasResult {
+  string catalog = 1;
+  string schema = 2;
+}
+
+/*
+ * Request message for the "GetTables" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of tables available in the server.
+ */
+message ActionGetTablesRequest {
+  /*
+   * Specifies the order of result values with prescendence:
+   *  - catalog
+   *  - schema
+   *  - table_type
+   *  - table
+   */
+  ResultsOrder order = 1;
+
+  // Specifies the Catalog to search for schemas.
+  string catalog = 2;
+
+  /* Specifies a filter pattern for schemas to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string schema_filter_pattern = 3;
+
+  /* Specifies a filter pattern for tables to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string table_name_filter_pattern = 4;
+
+  // Specifies a filter of table types which must match.
+  repeated string table_types = 5;
+
+  // Specifies if the schema should be returned for found tables.
+  bool include_schema = 6; 
+}
+
+/*
+ * Wrap the result of a "GetTables" action.
+ */
+message ActionGetTablesResult {
+  string catalog = 1;
+  string schema = 2;
+  string table = 3;
+  string table_type = 4;
+
+  /*
+   * Schema of the dataset as described in Schema.fbs::Schema, it is 
serialized as an IPC message.
+   * Null if include_schema on request is false.
+   */
+  bytes arrow_metadata = 5; 
+}
+
+/*
+ * Wrap the result of a "GetTableTypes" action.
+ */
+message ActionGetTableTypesResult {
+  /*
+   * Indicates the type of the table. E.g. table (regular data table) , view, 
system table etc.
+   */
+  string table_type = 1;
+}
+
+// SQL Execution Action Messages
+
+/*
+ * Request message for the "GetPreparedStatement" action on a 
+ * Flight SQL enabled backend.
+ */
+message ActionGetPreparedStatementRequest {
+  // The valid SQL string to get a prepared statement for.
+  string query = 1;
+}
+
+/*
+ * Wrap the result of a "GetPreparedStatement" action.
+ */
+message ActionGetPreparedStatementResult {
+
+  // Opaque handle for the prepared statement on the server.
+  bytes prepared_statement_handle = 1;
+
+  // If a result set generating query was provided, dataset_schema contains 
the 
+  // schema of the dataset as described in Schema.fbs::Schema, it is 
serialized as an IPC message.
+  bytes dataset_schema = 2;
+
+  // If the query provided contained parameters, parameter_schema contains the 
+  // Schema of the expected parameters as described in Schema.fbs::Schema.
+  bytes parameter_schema = 3;
+}
+
+/*
+ * Request message for the "ClosePreparedStatement" action on a 
+ * Flight SQL enabled backend. 
+ * Closes server resources associated with the prepared statement handle.
+ */
+message ActionClosePreparedStatementRequest {
+  // Opaque handle for the prepared statement on the server.
+  string prepared_statement_handle = 1;
+}
+
+
+// SQL Execution Messages.
+
+/*
+ * Represents a SQL query. Used in the command member of FlightDescriptor
+ * for the following RPC calls:
+ *  - GetSchema: return the schema of the query.
+ *  - GetFlightInfo: execute the query.
+ */
+message CommandStatementQuery {
+  // The SQL syntax.
+  string query = 1;
+}
+
+/*
+ * Represents an instance of executing a prepared statement. Used in the 
+ * command member of FlightDescriptor for the following RPC calls:
+ * TODO: Is the idea that a Put with parameter values would execute multiple 
bound versions of the prepared statement

Review comment:
       Just a thought: you could use DoExchange to combine the steps of 
providing parameter values and retrieving the results.

##########
File path: format/FlightSQL.proto
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+option java_package = "org.apache.arrow.flight.sql.impl";
+package arrow.flight.protocol.sql;
+
+/*
+ * Wrapper for the result of a "GetSQLInfo" action.
+ */
+message ActionGetSQLInfoResult {
+  /*
+   * Values are modelled after ODBC's SQLGetInfo() function. This information 
is intended to provide
+   * Flight SQL clients with basic, SQL syntax and SQL functions related 
information.
+   * More information types can be added in future releases.
+   * E.g. more SQL syntax support types, scalar functions support, type 
conversion support etc.
+   *
+   * Initially, Flight SQL will support the following information types:
+   * - Server Information
+   * -
+   *
+   * 1. Server Information: Provides basic information about the Flight SQL 
Server.
+   *
+   * The name of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_NAME
+   *
+   * The native version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_VERSION
+   *
+   * The Arrow version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_ARROW_VERSION

Review comment:
       Library version? Or format version?

##########
File path: 
java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSQLProducer.java
##########
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.flight.sql;
+
+import static org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_ACTIONS;
+import static 
org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_CLOSEPREPAREDSTATEMENT;
+import static 
org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_GETCATALOGS;
+import static 
org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_GETPREPAREDSTATEMENT;
+import static org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_GETSCHEMAS;
+import static org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_GETSQLINFO;
+import static org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_GETTABLES;
+import static 
org.apache.arrow.flight.sql.FlightSQLUtils.FLIGHT_SQL_GETTABLETYPES;
+
+import org.apache.arrow.flight.Action;
+import org.apache.arrow.flight.ActionType;
+import org.apache.arrow.flight.FlightDescriptor;
+import org.apache.arrow.flight.FlightInfo;
+import org.apache.arrow.flight.FlightProducer;
+import org.apache.arrow.flight.FlightStream;
+import org.apache.arrow.flight.PutResult;
+import org.apache.arrow.flight.Result;
+import org.apache.arrow.flight.SchemaResult;
+import org.apache.arrow.flight.Ticket;
+import 
org.apache.arrow.flight.sql.impl.FlightSQL.ActionClosePreparedStatementRequest;
+import org.apache.arrow.flight.sql.impl.FlightSQL.ActionGetCatalogsRequest;
+import 
org.apache.arrow.flight.sql.impl.FlightSQL.ActionGetPreparedStatementRequest;
+import org.apache.arrow.flight.sql.impl.FlightSQL.ActionGetSchemasRequest;
+import org.apache.arrow.flight.sql.impl.FlightSQL.ActionGetTablesRequest;
+import 
org.apache.arrow.flight.sql.impl.FlightSQL.CommandPreparedStatementQuery;
+import 
org.apache.arrow.flight.sql.impl.FlightSQL.CommandPreparedStatementUpdate;
+import org.apache.arrow.flight.sql.impl.FlightSQL.CommandStatementQuery;
+import org.apache.arrow.flight.sql.impl.FlightSQL.CommandStatementUpdate;
+
+import com.google.protobuf.Any;
+import com.google.protobuf.InvalidProtocolBufferException;
+
+import io.grpc.Status;
+
+/**
+ * API to Implement an Arrow Flight SQL producer.
+ */
+public abstract class FlightSQLProducer implements FlightProducer, 
AutoCloseable {
+  /**
+   * Depending on the provided command, method either:
+   * 1. Return information about a SQL query, or
+   * 2. Return information about a prepared statement. In this case, 
parameters binding is allowed.
+   *
+   * @param context Per-call context.
+   * @param descriptor The descriptor identifying the data stream.
+   * @return information about the given SQL query, or the given prepared 
statement.
+   */
+  @Override
+  public FlightInfo getFlightInfo(CallContext context, FlightDescriptor 
descriptor) {
+    final Any command = FlightSQLUtils.parseOrThrow(descriptor.getCommand());

Review comment:
       Instead of Any.pack above, what if we define an explicit top-level 
message that has the possible messages in a oneof?

##########
File path: format/FlightSQL.proto
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+option java_package = "org.apache.arrow.flight.sql.impl";
+package arrow.flight.protocol.sql;
+
+/*
+ * Wrapper for the result of a "GetSQLInfo" action.
+ */
+message ActionGetSQLInfoResult {
+  /*
+   * Values are modelled after ODBC's SQLGetInfo() function. This information 
is intended to provide
+   * Flight SQL clients with basic, SQL syntax and SQL functions related 
information.
+   * More information types can be added in future releases.
+   * E.g. more SQL syntax support types, scalar functions support, type 
conversion support etc.
+   *
+   * Initially, Flight SQL will support the following information types:
+   * - Server Information
+   * -
+   *
+   * 1. Server Information: Provides basic information about the Flight SQL 
Server.
+   *
+   * The name of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_NAME
+   *
+   * The native version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_VERSION
+   *
+   * The Arrow version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_ARROW_VERSION
+   *
+   * Indicates whether the Flight SQL Server is read only.
+   * FLIGHT_SQL_SERVER_READ_ONLY
+   *
+   * Indicates whether the Flight SQL Server supports both read and write.
+   * FLIGHT_SQL_SERVER_READ_WRITE
+   *
+   * 2. SQL Syntax Information: provides information about SQL syntax 
supported by the Flight SQL Server.
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
catalogs.
+   * In a SQL environment, a catalog is a collection of schemas.
+   * SQL_DDL_CATALOG
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
schemas.
+   * In a SQL environment, a catalog is a collection of tables, views, indexes 
etc.
+   * SQL_DDL_SCHEMA
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
tables.
+   * In a SQL environment, a table is a collection of rows of information. 
Each row of information
+   * may have one or more columns of data.
+   * SQL_DDL_TABLE
+   *
+   * Indicates the case sensitivity of catalog, table and schema names.
+   * SQL_IDENTIFIER_CASE
+   *
+   * Indicates the supported character(s) used to surround a delimited 
identifier.
+   * SQL_IDENTIFIER_QUOTE_CHAR
+   *
+   * Indicates case sensitivity of quoted identifiers.
+   * SQL_QUOTED_IDENTIFIER_CASE
+   *
+   */
+  map<string, GetSQLInfoValue> flight_sql_info = 1;
+
+  // Implementation specific custom SQLInfo values.
+  map<string, GetSQLInfoValue> custom_info = 2;
+}
+
+/*
+ * Wrapper for values returned in ActionGetSQLInfoResult.
+ */
+message GetSQLInfoValue {
+  oneof value {
+    string string_value = 1;
+    int32 integer_value = 2;
+    int32 integer_bitmask = 3;
+    int32 integer_flag = 4;
+    bytes binary_value = 5;
+    int64 long_value = 6;
+  }
+}
+
+/*
+ * Request message for the "GetCatalogs" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of catalogs available in the server.
+ */
+message ActionGetCatalogsRequest {
+  /*
+   * Specifies the order of result values.
+   */ 
+  ResultsOrder order = 1;
+}
+
+/*
+ * Wrap the result of a "GetCatalogs" action.
+ */
+message ActionGetCatalogsResult {
+  repeated string catalog = 1;
+}
+
+/*
+ * Request message for the "GetSchemas" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of schemas available in the server.
+ */
+message ActionGetSchemasRequest {
+  /*
+   * Specifies the order of result values with precedence:
+   *  - catalog
+   *  - schema
+   */
+  ResultsOrder order = 1;
+
+  /*
+   * Specifies the Catalog to search for schemas.
+   * If omitted, then schemas for all catalogs are searched.
+   */ 
+  string catalog = 2;
+
+  /*
+   * Specifies a filter pattern for schemas to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string schema_filter_pattern = 3;
+}
+
+/*
+ * Wrap the result of a "GetSchemas" action.
+ */
+message ActionGetSchemasResult {
+  string catalog = 1;
+  string schema = 2;
+}
+
+/*
+ * Request message for the "GetTables" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of tables available in the server.
+ */
+message ActionGetTablesRequest {
+  /*
+   * Specifies the order of result values with prescendence:
+   *  - catalog
+   *  - schema
+   *  - table_type
+   *  - table
+   */
+  ResultsOrder order = 1;
+
+  // Specifies the Catalog to search for schemas.
+  string catalog = 2;
+
+  /* Specifies a filter pattern for schemas to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string schema_filter_pattern = 3;
+
+  /* Specifies a filter pattern for tables to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string table_name_filter_pattern = 4;
+
+  // Specifies a filter of table types which must match.
+  repeated string table_types = 5;

Review comment:
       Is this an AND or an OR? Are these filters matched by substring or with 
the pattern syntax above?

##########
File path: format/FlightSQL.proto
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+option java_package = "org.apache.arrow.flight.sql.impl";
+package arrow.flight.protocol.sql;
+
+/*
+ * Wrapper for the result of a "GetSQLInfo" action.
+ */
+message ActionGetSQLInfoResult {
+  /*
+   * Values are modelled after ODBC's SQLGetInfo() function. This information 
is intended to provide
+   * Flight SQL clients with basic, SQL syntax and SQL functions related 
information.
+   * More information types can be added in future releases.
+   * E.g. more SQL syntax support types, scalar functions support, type 
conversion support etc.
+   *
+   * Initially, Flight SQL will support the following information types:
+   * - Server Information
+   * -
+   *
+   * 1. Server Information: Provides basic information about the Flight SQL 
Server.
+   *
+   * The name of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_NAME
+   *
+   * The native version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_VERSION
+   *
+   * The Arrow version of the Flight SQL Server.
+   * FLIGHT_SQL_SERVER_ARROW_VERSION
+   *
+   * Indicates whether the Flight SQL Server is read only.
+   * FLIGHT_SQL_SERVER_READ_ONLY
+   *
+   * Indicates whether the Flight SQL Server supports both read and write.
+   * FLIGHT_SQL_SERVER_READ_WRITE
+   *
+   * 2. SQL Syntax Information: provides information about SQL syntax 
supported by the Flight SQL Server.
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
catalogs.
+   * In a SQL environment, a catalog is a collection of schemas.
+   * SQL_DDL_CATALOG
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
schemas.
+   * In a SQL environment, a catalog is a collection of tables, views, indexes 
etc.
+   * SQL_DDL_SCHEMA
+   *
+   * Indicates whether the Flight SQL Server supports CREATE and DROP of 
tables.
+   * In a SQL environment, a table is a collection of rows of information. 
Each row of information
+   * may have one or more columns of data.
+   * SQL_DDL_TABLE
+   *
+   * Indicates the case sensitivity of catalog, table and schema names.
+   * SQL_IDENTIFIER_CASE
+   *
+   * Indicates the supported character(s) used to surround a delimited 
identifier.
+   * SQL_IDENTIFIER_QUOTE_CHAR
+   *
+   * Indicates case sensitivity of quoted identifiers.
+   * SQL_QUOTED_IDENTIFIER_CASE
+   *
+   */
+  map<string, GetSQLInfoValue> flight_sql_info = 1;
+
+  // Implementation specific custom SQLInfo values.
+  map<string, GetSQLInfoValue> custom_info = 2;
+}
+
+/*
+ * Wrapper for values returned in ActionGetSQLInfoResult.
+ */
+message GetSQLInfoValue {
+  oneof value {
+    string string_value = 1;
+    int32 integer_value = 2;
+    int32 integer_bitmask = 3;
+    int32 integer_flag = 4;
+    bytes binary_value = 5;
+    int64 long_value = 6;
+  }
+}
+
+/*
+ * Request message for the "GetCatalogs" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of catalogs available in the server.
+ */
+message ActionGetCatalogsRequest {
+  /*
+   * Specifies the order of result values.
+   */ 
+  ResultsOrder order = 1;
+}
+
+/*
+ * Wrap the result of a "GetCatalogs" action.
+ */
+message ActionGetCatalogsResult {
+  repeated string catalog = 1;
+}
+
+/*
+ * Request message for the "GetSchemas" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of schemas available in the server.
+ */
+message ActionGetSchemasRequest {
+  /*
+   * Specifies the order of result values with precedence:
+   *  - catalog
+   *  - schema
+   */
+  ResultsOrder order = 1;
+
+  /*
+   * Specifies the Catalog to search for schemas.
+   * If omitted, then schemas for all catalogs are searched.
+   */ 
+  string catalog = 2;
+
+  /*
+   * Specifies a filter pattern for schemas to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string schema_filter_pattern = 3;
+}
+
+/*
+ * Wrap the result of a "GetSchemas" action.
+ */
+message ActionGetSchemasResult {
+  string catalog = 1;
+  string schema = 2;
+}
+
+/*
+ * Request message for the "GetTables" action on a 
+ * Flight SQL enabled backend. 
+ * Requests a list of tables available in the server.
+ */
+message ActionGetTablesRequest {
+  /*
+   * Specifies the order of result values with prescendence:
+   *  - catalog
+   *  - schema
+   *  - table_type
+   *  - table
+   */
+  ResultsOrder order = 1;
+
+  // Specifies the Catalog to search for schemas.
+  string catalog = 2;
+
+  /* Specifies a filter pattern for schemas to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string schema_filter_pattern = 3;
+
+  /* Specifies a filter pattern for tables to search for.
+   * When no schema_filter_pattern is provided, the pattern will not be used 
to narrow the search.
+   * In the pattern string, two special characters can be used to denote 
matching rules:
+   *    - "%" means to match any substring with 0 or more characters.
+   *    - "_" means to match any one character.
+   */
+  string table_name_filter_pattern = 4;
+
+  // Specifies a filter of table types which must match.
+  repeated string table_types = 5;
+
+  // Specifies if the schema should be returned for found tables.
+  bool include_schema = 6; 
+}
+
+/*
+ * Wrap the result of a "GetTables" action.
+ */
+message ActionGetTablesResult {
+  string catalog = 1;
+  string schema = 2;
+  string table = 3;
+  string table_type = 4;
+
+  /*
+   * Schema of the dataset as described in Schema.fbs::Schema, it is 
serialized as an IPC message.
+   * Null if include_schema on request is false.
+   */
+  bytes arrow_metadata = 5; 
+}
+
+/*
+ * Wrap the result of a "GetTableTypes" action.
+ */
+message ActionGetTableTypesResult {
+  /*
+   * Indicates the type of the table. E.g. table (regular data table) , view, 
system table etc.
+   */
+  string table_type = 1;
+}
+
+// SQL Execution Action Messages
+
+/*
+ * Request message for the "GetPreparedStatement" action on a 
+ * Flight SQL enabled backend.
+ */
+message ActionGetPreparedStatementRequest {
+  // The valid SQL string to get a prepared statement for.
+  string query = 1;
+}
+
+/*
+ * Wrap the result of a "GetPreparedStatement" action.
+ */
+message ActionGetPreparedStatementResult {
+
+  // Opaque handle for the prepared statement on the server.
+  bytes prepared_statement_handle = 1;
+
+  // If a result set generating query was provided, dataset_schema contains 
the 
+  // schema of the dataset as described in Schema.fbs::Schema, it is 
serialized as an IPC message.
+  bytes dataset_schema = 2;
+
+  // If the query provided contained parameters, parameter_schema contains the 
+  // Schema of the expected parameters as described in Schema.fbs::Schema.
+  bytes parameter_schema = 3;
+}
+
+/*
+ * Request message for the "ClosePreparedStatement" action on a 
+ * Flight SQL enabled backend. 
+ * Closes server resources associated with the prepared statement handle.
+ */
+message ActionClosePreparedStatementRequest {
+  // Opaque handle for the prepared statement on the server.
+  string prepared_statement_handle = 1;
+}
+
+
+// SQL Execution Messages.
+
+/*
+ * Represents a SQL query. Used in the command member of FlightDescriptor
+ * for the following RPC calls:
+ *  - GetSchema: return the schema of the query.
+ *  - GetFlightInfo: execute the query.
+ */
+message CommandStatementQuery {
+  // The SQL syntax.
+  string query = 1;
+}
+
+/*
+ * Represents an instance of executing a prepared statement. Used in the 
+ * command member of FlightDescriptor for the following RPC calls:
+ * TODO: Is the idea that a Put with parameter values would execute multiple 
bound versions of the prepared statement
+ * TODO: (one for each row)? Seems like that will work ok for Insert 
statements, but what about other kinds of prepared statements?
+ *  - DoPut: bind parameter values.
+ *  - GetFlightInfo: execute the prepared statement instance.
+ */
+message CommandPreparedStatementQuery {
+  // Unique identifier for the instance of the prepared statement to execute.
+  bytes client_execution_handle = 1; 
+  // Opaque handle for the prepared statement on the server.
+  bytes prepared_statement_handle = 2;
+}
+
+/*
+ * Represents a SQL update query. Used in the command member of 
FlightDescriptor
+ * for the the RPC call DoPut to cause the server to execute the included 
+ * SQL update.
+ */
+message CommandStatementUpdate {
+  // The SQL syntax.
+  string query = 1;
+}
+
+/*
+ * Represents a SQL update query. Used in the command member of 
FlightDescriptor
+ * for the the RPC call DoPut to cause the server to execute the included 
+ * prepared statement handle as an update.
+ */
+message CommandPreparedStatementUpdate {
+  // Unique identifier for the instance of the prepared statement to execute.
+  bytes client_execution_handle = 1; 
+  // Opaque handle for the prepared statement on the server.
+  bytes prepared_statement_handle = 2;
+}
+
+/*
+ * Returned from the RPC call DoPut when a CommandStatementUpdate
+ * CommandPreparedStatementUpdate was in the request, containing
+ * results from the update. 
+ */
+message DoPutUpdateResult {
+  // The number of records updated. A return value of -1 represents 
+  // an unknown updated record count.
+  int64 record_count = 1; 
+}
+
+message ResultsOrder {

Review comment:
       Shouldn't this message have a field?
   
   Alternatively, if you wanted a top-level enum, you could just have
   ```
   enum ResultsOrder {
       RESULTS_ORDER_UNKNOWN = 0;
       // ...
   }
   ```
   I would also suggest prefixing enum variants with the enum name since 
Protobuf enums aren't namespaced.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to