Class FlightSqlResolver

java.lang.Object
io.deephaven.server.flightsql.FlightSqlResolver
All Implemented Interfaces:
ActionResolver, CommandResolver, TicketResolver

@Singleton public final class FlightSqlResolver extends Object implements ActionResolver, CommandResolver
A Flight SQL resolver. This supports the read-only querying of the global query scope, which is presented simply with the query scope variables names as the table names without a catalog and schema name.

This implementation does not currently follow the Flight SQL protocol to exact specification. Namely, all the returned Flight schemas have nullable fields, and some of the fields on specific commands have different types (see flightInfoFor(SessionState, FlightDescriptor, String) for specifics).

All commands, actions, and resolution must be called by authenticated users.

  • Constructor Details

  • Method Details

    • ticketRoute

      public byte ticketRoute()
      The Flight SQL ticket route, equal to 'q'.
      Specified by:
      ticketRoute in interface TicketResolver
      Returns:
      the Flight SQL ticket route
    • handlesCommand

      public boolean handlesCommand(org.apache.arrow.flight.impl.Flight.FlightDescriptor descriptor)
      Returns true if the given command descriptor appears to be a valid Flight SQL command; that is, it is parsable as an Any protobuf message with the type URL prefixed with "type.googleapis.com/arrow.flight.protocol.sql.Command".
      Specified by:
      handlesCommand in interface CommandResolver
      Parameters:
      descriptor - the descriptor
      Returns:
      true if the given command appears to be a valid Flight SQL command
    • flightInfoFor

      public SessionState.ExportObject<org.apache.arrow.flight.impl.Flight.FlightInfo> flightInfoFor(@Nullable @Nullable SessionState session, org.apache.arrow.flight.impl.Flight.FlightDescriptor descriptor, String logId)
      Executes the given descriptor command. Only supports authenticated access.

      FlightSql.CommandStatementQuery: Executes the given SQL query. The returned Flight info should be promptly resolved, and resolved at most once. Transactions are not currently supported.

      FlightSql.CommandPreparedStatementQuery: Executes the prepared SQL query (must be executed within the scope of a FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT / FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT). The returned Flight info should be promptly resolved, and resolved at most once.

      FlightSql.CommandGetTables: Retrieve the tables authorized for the user. The "table_name", "table_type", and (optional) "table_schema" fields will be out-of-spec as nullable columns (the returned data for these columns will never be null).

      FlightSql.CommandGetCatalogs: Retrieves the catalogs authorized for the user. The "catalog_name" field will be out-of-spec as a nullable column (the returned data for this column will never be null). Currently, always an empty table.

      FlightSql.CommandGetDbSchemas: Retrieves the catalogs and schemas authorized for the user. The "db_schema_name" field will be out-of-spec as a nullable (the returned data for this column will never be null). Currently, always an empty table.

      FlightSql.CommandGetTableTypes: Retrieves the table types authorized for the user. The "table_type" field will be out-of-spec as a nullable (the returned data for this column will never be null). Currently, always a table with a single row with value "TABLE".

      FlightSql.CommandGetPrimaryKeys: Retrieves the primary keys for a table if the user is authorized. If the table does not exist (or the user is not authorized), a Status.Code.NOT_FOUND exception will be thrown. The "table_name", "column_name", and "key_sequence" will be out-of-spec as nullable columns (the returned data for these columns will never be null). Currently, always an empty table.

      FlightSql.CommandGetImportedKeys: Retrieves the imported keys for a table if the user is authorized. If the table does not exist (or the user is not authorized), a Status.Code.NOT_FOUND exception will be thrown. The "pk_table_name", "pk_column_name", "fk_table_name", "fk_column_name", and "key_sequence" will be out-of-spec as nullable columns (the returned data for these columns will never be null). The "update_rule" and "delete_rule" will be out-of-spec as nullable int8 types instead of uint8 (the returned data for these columns will never be null). Currently, always an empty table.

      FlightSql.CommandGetExportedKeys: Retrieves the exported keys for a table if the user is authorized. If the table does not exist (or the user is not authorized), a Status.Code.NOT_FOUND exception will be thrown. The "pk_table_name", "pk_column_name", "fk_table_name", "fk_column_name", and "key_sequence" will be out-of-spec as nullable columns (the returned data for these columns will never be null). The "update_rule" and "delete_rule" will be out-of-spec as nullable int8 types instead of uint8 (the returned data for these columns will never be null). Currently, always an empty table.

      All other commands will throw an Status.Code.UNIMPLEMENTED exception.

      Specified by:
      flightInfoFor in interface TicketResolver
      Parameters:
      session - the session
      descriptor - the flight descriptor to retrieve a ticket for
      logId - an end-user friendly identification of the ticket should an error occur
      Returns:
      the flight info for the given descriptor command
    • resolve

      public <T> SessionState.ExportObject<T> resolve(@Nullable @Nullable SessionState session, ByteBuffer ticket, String logId)
      Only supports authenticated access.
      Specified by:
      resolve in interface TicketResolver
      Type Parameters:
      T - the type, must be Table
      Parameters:
      session - the user session context
      ticket - (as ByteByffer) the ticket to resolve
      logId - an end-user friendly identification of the ticket should an error occur
      Returns:
      the exported table
    • resolve

      public <T> SessionState.ExportObject<T> resolve(@Nullable @Nullable SessionState session, org.apache.arrow.flight.impl.Flight.FlightDescriptor descriptor, String logId)
      Description copied from interface: TicketResolver
      Resolve a flight descriptor to an export object future.
      Specified by:
      resolve in interface TicketResolver
      Type Parameters:
      T - the expected return type of the ticket; this is not validated
      Parameters:
      session - the user session context
      descriptor - the descriptor to resolve
      logId - an end-user friendly identification of the ticket should an error occur
      Returns:
      an export object; see SessionState for lifecycle propagation details
    • listActions

      public void listActions(@Nullable @Nullable SessionState session, Consumer<org.apache.arrow.flight.ActionType> visitor)
      Supports unauthenticated access. When unauthenticated, will not return any actions types. When authenticated, will return the action types the user is authorized to access. Currently, supports FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT and FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.
      Specified by:
      listActions in interface ActionResolver
      Parameters:
      session - the session
      visitor - the visitor
    • handlesActionType

      public boolean handlesActionType(String type)
      Returns true if type is a known Flight SQL action type (even if this implementation does not implement it).
      Specified by:
      handlesActionType in interface ActionResolver
      Parameters:
      type - the action type
      Returns:
      if type is a known Flight SQL action type
    • doAction

      public void doAction(@Nullable @Nullable SessionState session, org.apache.arrow.flight.Action action, io.grpc.stub.StreamObserver<org.apache.arrow.flight.Result> observer)
      Executes the given action. Only supports authenticated access. Currently, supports FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT and FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT; all other action types will throw an Status.Code.UNIMPLEMENTED exception. Transactions are not currently supported.
      Specified by:
      doAction in interface ActionResolver
      Parameters:
      session - the session
      action - the action
      observer - the observer
    • forAllFlightInfo

      public void forAllFlightInfo(@Nullable @Nullable SessionState session, Consumer<org.apache.arrow.flight.impl.Flight.FlightInfo> visitor)
      Supports unauthenticated access. When unauthenticated, will not return any Flight info. When authenticated, this may return Flight info the user is authorized to access. Currently, no Flight info is returned.
      Specified by:
      forAllFlightInfo in interface TicketResolver
      Parameters:
      session - optional session that the resolver can use to filter which flights a visitor sees
      visitor - the callback to invoke per descriptor path
    • publish

      public <T> SessionState.ExportBuilder<T> publish(SessionState session, org.apache.arrow.flight.impl.Flight.FlightDescriptor descriptor, String logId, @Nullable @Nullable Runnable onPublish)
      Publishing to Flight SQL descriptors is not currently supported. Throws a Status.Code.FAILED_PRECONDITION error.
      Specified by:
      publish in interface TicketResolver
      Type Parameters:
      T - the type of the result the export will publish
      Parameters:
      session - the user session context
      descriptor - (as Flight.Descriptor) the descriptor to publish to
      logId - an end-user friendly identification of the ticket should an error occur
      onPublish - an optional callback to invoke when the result is published
      Returns:
      an export object; see SessionState for lifecycle propagation details
    • publish

      public <T> SessionState.ExportBuilder<T> publish(SessionState session, ByteBuffer ticket, String logId, @Nullable @Nullable Runnable onPublish)
      Publishing to Flight SQL tickets is not currently supported. Throws a Status.Code.FAILED_PRECONDITION error.
      Specified by:
      publish in interface TicketResolver
      Type Parameters:
      T - the type of the result the export will publish
      Parameters:
      session - the user session context
      ticket - (as ByteByffer) the ticket to publish to
      logId - an end-user friendly identification of the ticket should an error occur
      onPublish - an optional callback to invoke when the result is published
      Returns:
      an export object; see SessionState for lifecycle propagation details
    • getLogNameFor

      public String getLogNameFor(ByteBuffer ticket, String logId)
      Description copied from interface: TicketResolver
      Create a human readable string to identify this ticket.
      Specified by:
      getLogNameFor in interface TicketResolver
      Parameters:
      ticket - the ticket to parse
      logId - an end-user friendly identification of the ticket should an error occur
      Returns:
      a string that is good for log/error messages