From bc52f9f0e582474501e92e6a281f0110754a8af1 Mon Sep 17 00:00:00 2001 From: David Li
Should be identical to {@link FlightSqlProducer.Schemas#GET_CATALOGS_SCHEMA}. + */ + public SchemaResult getCatalogsSchema(final CallOption... options) { + final CommandGetCatalogs command = CommandGetCatalogs.getDefaultInstance(); + final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray()); + return client.getSchema(descriptor, options); + } + /** * Request a list of schemas. * @@ -160,6 +181,17 @@ public FlightInfo getSchemas(final String catalog, final String dbSchemaFilterPa return client.getInfo(descriptor, options); } + /** + * Get the schema of {@link #getSchemas(String, String, CallOption...)} from the server. + * + *
Should be identical to {@link FlightSqlProducer.Schemas#GET_SCHEMAS_SCHEMA}.
+ */
+ public SchemaResult getSchemasSchema(final CallOption... options) {
+ final CommandGetDbSchemas command = CommandGetDbSchemas.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Get schema for a stream.
*
@@ -231,6 +263,17 @@ public FlightInfo getSqlInfo(final Iterable Should be identical to {@link FlightSqlProducer.Schemas#GET_SQL_INFO_SCHEMA}.
+ */
+ public SchemaResult getSqlInfoSchema(final CallOption... options) {
+ final CommandGetSqlInfo command = CommandGetSqlInfo.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Request the information about the data types supported related to
* a filter data type.
@@ -261,6 +304,17 @@ public FlightInfo getXdbcTypeInfo(final CallOption... options) {
return client.getInfo(descriptor, options);
}
+ /**
+ * Get the schema of {@link #getXdbcTypeInfo(CallOption...)} from the server.
+ *
+ * Should be identical to {@link FlightSqlProducer.Schemas#GET_TYPE_INFO_SCHEMA}.
+ */
+ public SchemaResult getXdbcTypeInfoSchema(final CallOption... options) {
+ final CommandGetXdbcTypeInfo command = CommandGetXdbcTypeInfo.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Request a list of tables.
*
@@ -298,6 +352,18 @@ public FlightInfo getTables(final String catalog, final String dbSchemaFilterPat
return client.getInfo(descriptor, options);
}
+ /**
+ * Get the schema of {@link #getTables(String, String, String, List, boolean, CallOption...)} from the server.
+ *
+ * Should be identical to {@link FlightSqlProducer.Schemas#GET_TABLES_SCHEMA} or
+ * {@link FlightSqlProducer.Schemas#GET_TABLES_SCHEMA_NO_SCHEMA}.
+ */
+ public SchemaResult getTablesSchema(boolean includeSchema, final CallOption... options) {
+ final CommandGetTables command = CommandGetTables.newBuilder().setIncludeSchema(includeSchema).build();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Request the primary keys for a table.
*
@@ -323,6 +389,17 @@ public FlightInfo getPrimaryKeys(final TableRef tableRef, final CallOption... op
return client.getInfo(descriptor, options);
}
+ /**
+ * Get the schema of {@link #getPrimaryKeys(TableRef, CallOption...)} from the server.
+ *
+ * Should be identical to {@link FlightSqlProducer.Schemas#GET_PRIMARY_KEYS_SCHEMA}.
+ */
+ public SchemaResult getPrimaryKeysSchema(final CallOption... options) {
+ final CommandGetPrimaryKeys command = CommandGetPrimaryKeys.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Retrieves a description about the foreign key columns that reference the primary key columns of the given table.
*
@@ -350,6 +427,17 @@ public FlightInfo getExportedKeys(final TableRef tableRef, final CallOption... o
return client.getInfo(descriptor, options);
}
+ /**
+ * Get the schema of {@link #getExportedKeys(TableRef, CallOption...)} from the server.
+ *
+ * Should be identical to {@link FlightSqlProducer.Schemas#GET_EXPORTED_KEYS_SCHEMA}.
+ */
+ public SchemaResult getExportedKeysSchema(final CallOption... options) {
+ final CommandGetExportedKeys command = CommandGetExportedKeys.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Retrieves the foreign key columns for the given table.
*
@@ -378,6 +466,17 @@ public FlightInfo getImportedKeys(final TableRef tableRef,
return client.getInfo(descriptor, options);
}
+ /**
+ * Get the schema of {@link #getImportedKeys(TableRef, CallOption...)} from the server.
+ *
+ * Should be identical to {@link FlightSqlProducer.Schemas#GET_IMPORTED_KEYS_SCHEMA}.
+ */
+ public SchemaResult getImportedKeysSchema(final CallOption... options) {
+ final CommandGetImportedKeys command = CommandGetImportedKeys.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Retrieves a description of the foreign key columns that reference the given table's
* primary key columns (the foreign keys exported by a table).
@@ -417,6 +516,17 @@ public FlightInfo getCrossReference(final TableRef pkTableRef,
return client.getInfo(descriptor, options);
}
+ /**
+ * Get the schema of {@link #getCrossReference(TableRef, TableRef, CallOption...)} from the server.
+ *
+ * Should be identical to {@link FlightSqlProducer.Schemas#GET_CROSS_REFERENCE_SCHEMA}.
+ */
+ public SchemaResult getCrossReferenceSchema(final CallOption... options) {
+ final CommandGetCrossReference command = CommandGetCrossReference.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Request a list of table types.
*
@@ -429,6 +539,17 @@ public FlightInfo getTableTypes(final CallOption... options) {
return client.getInfo(descriptor, options);
}
+ /**
+ * Get the schema of {@link #getTableTypes(CallOption...)} from the server.
+ *
+ * Should be identical to {@link FlightSqlProducer.Schemas#GET_TABLE_TYPES_SCHEMA}.
+ */
+ public SchemaResult getTableTypesSchema(final CallOption... options) {
+ final CommandGetTableTypes command = CommandGetTableTypes.getDefaultInstance();
+ final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
/**
* Create a prepared statement on the server.
*
@@ -534,6 +655,20 @@ public Schema getParameterSchema() {
return parameterSchema;
}
+ /**
+ * Get the schema of the result set (should be identical to {@link #getResultSetSchema()}).
+ */
+ public SchemaResult fetchSchema(CallOption... options) {
+ checkOpen();
+
+ final FlightDescriptor descriptor = FlightDescriptor
+ .command(Any.pack(CommandPreparedStatementQuery.newBuilder()
+ .setPreparedStatementHandle(preparedStatementResult.getPreparedStatementHandle())
+ .build())
+ .toByteArray());
+ return client.getSchema(descriptor, options);
+ }
+
private Schema deserializeSchema(final ByteString bytes) {
try {
return bytes.isEmpty() ?
diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java
index c617c6a03eec9..4226ec9e228cf 100644
--- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java
+++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java
@@ -147,26 +147,32 @@ default SchemaResult getSchema(CallContext context, FlightDescriptor descriptor)
if (command.is(CommandStatementQuery.class)) {
return getSchemaStatement(
FlightSqlUtils.unpackOrThrow(command, CommandStatementQuery.class), context, descriptor);
+ } else if (command.is(CommandPreparedStatementQuery.class)) {
+ return getSchemaPreparedStatement(
+ FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class), context, descriptor);
} else if (command.is(CommandGetCatalogs.class)) {
return new SchemaResult(Schemas.GET_CATALOGS_SCHEMA);
+ } else if (command.is(CommandGetCrossReference.class)) {
+ return new SchemaResult(Schemas.GET_CROSS_REFERENCE_SCHEMA);
} else if (command.is(CommandGetDbSchemas.class)) {
return new SchemaResult(Schemas.GET_SCHEMAS_SCHEMA);
+ } else if (command.is(CommandGetExportedKeys.class)) {
+ return new SchemaResult(Schemas.GET_EXPORTED_KEYS_SCHEMA);
+ } else if (command.is(CommandGetImportedKeys.class)) {
+ return new SchemaResult(Schemas.GET_IMPORTED_KEYS_SCHEMA);
+ } else if (command.is(CommandGetPrimaryKeys.class)) {
+ return new SchemaResult(Schemas.GET_PRIMARY_KEYS_SCHEMA);
} else if (command.is(CommandGetTables.class)) {
- return new SchemaResult(Schemas.GET_TABLES_SCHEMA);
+ if (FlightSqlUtils.unpackOrThrow(command, CommandGetTables.class).getIncludeSchema()) {
+ return new SchemaResult(Schemas.GET_TABLES_SCHEMA);
+ }
+ return new SchemaResult(Schemas.GET_TABLES_SCHEMA_NO_SCHEMA);
} else if (command.is(CommandGetTableTypes.class)) {
return new SchemaResult(Schemas.GET_TABLE_TYPES_SCHEMA);
} else if (command.is(CommandGetSqlInfo.class)) {
return new SchemaResult(Schemas.GET_SQL_INFO_SCHEMA);
} else if (command.is(CommandGetXdbcTypeInfo.class)) {
return new SchemaResult(Schemas.GET_TYPE_INFO_SCHEMA);
- } else if (command.is(CommandGetPrimaryKeys.class)) {
- return new SchemaResult(Schemas.GET_PRIMARY_KEYS_SCHEMA);
- } else if (command.is(CommandGetImportedKeys.class)) {
- return new SchemaResult(Schemas.GET_IMPORTED_KEYS_SCHEMA);
- } else if (command.is(CommandGetExportedKeys.class)) {
- return new SchemaResult(Schemas.GET_EXPORTED_KEYS_SCHEMA);
- } else if (command.is(CommandGetCrossReference.class)) {
- return new SchemaResult(Schemas.GET_CROSS_REFERENCE_SCHEMA);
}
throw CallStatus.INVALID_ARGUMENT.withDescription("Invalid command provided.").toRuntimeException();
@@ -336,16 +342,31 @@ FlightInfo getFlightInfoPreparedStatement(CommandPreparedStatementQuery command,
CallContext context, FlightDescriptor descriptor);
/**
- * Gets schema about a particular SQL query based data stream.
+ * Get the schema of the result set of a query.
*
- * @param command The sql command to generate the data stream.
+ * @param command The SQL query.
* @param context Per-call context.
* @param descriptor The descriptor identifying the data stream.
- * @return Schema for the stream.
+ * @return the schema of the result set.
*/
SchemaResult getSchemaStatement(CommandStatementQuery command, CallContext context,
FlightDescriptor descriptor);
+ /**
+ * Get the schema of the result set of a prepared statement.
+ *
+ * @param command The prepared statement handle.
+ * @param context Per-call context.
+ * @param descriptor The descriptor identifying the data stream.
+ * @return the schema of the result set.
+ */
+ default SchemaResult getSchemaPreparedStatement(CommandPreparedStatementQuery command, CallContext context,
+ FlightDescriptor descriptor) {
+ throw CallStatus.UNIMPLEMENTED
+ .withDescription("GetSchema with CommandPreparedStatementQuery is not implemented")
+ .toRuntimeException();
+ }
+
/**
* Returns data for a SQL query based data stream.
* @param ticket Ticket message containing the statement handle.
diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java
index 25affa8f08aaa..e461515c40ecd 100644
--- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java
+++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java
@@ -76,7 +76,7 @@ public static