Class InfluxDBConnectionFactory


  • public class InfluxDBConnectionFactory
    extends Object
    Creates InfluxDB client connections, resolving the auth token from Secrets Manager. The INFLUXDB3_AUTH_TOKEN env var must be a Secrets Manager reference of the form ${secret_name}; a literal token is rejected so the token is never stored in the Lambda configuration. The secret value may be a plain string (the entire value is the token) or a JSON object (the token is read from a configurable key, env var INFLUXDB3_AUTH_TOKEN_KEY, default token).
    • Method Detail

      • setHandler

        public void setHandler​(FederationRequestHandler handler)
        Sets the handler reference for secret resolution. Used when the handler cannot be passed at construction time (e.g., RecordHandler passes itself after super() completes).
      • getClient

        public com.influxdb.v3.client.InfluxDBClient getClient​(String database)
        Creates an InfluxDBClient for the given database.
        Parameters:
        database - the database to connect to, or null to use the configured default
      • executeWithTokenRetry

        public <T> T executeWithTokenRetry​(String database,
                                           InfluxDBConnectionFactory.InfluxDBQuery<T> query)
                                    throws Exception
        Runs query against a client for database, under withCredentialRefresh(com.amazonaws.athena.connectors.influxdb.InfluxDBConnectionFactory.Attempt<T>). Client creation happens inside the attempt, so the database-existence check that a cache miss triggers (see assertDatabaseExists(java.lang.String)) shares this operation's single retry budget. It never starts a second, nested retry loop. Auth errors occur at Flight stream initiation, before any rows are emitted, so retrying a query that streams into a spiller does not risk duplicate output.
        Throws:
        Exception
      • resolveDatabase

        public String resolveDatabase​(String schemaName)
                               throws IOException,
                                      InterruptedException
        Resolves a lowercased schema name back to the original database name. Athena lowercases all identifiers, but InfluxDB is case-sensitive. When scoped to a single database via influxdb_database, that database is the only permissible target: any other schema is rejected outright (see enforceDatabaseScope(java.lang.String)) rather than being resolved against the full set of token-reachable databases. Otherwise fails closed: if the schema is not among the databases discoverable on the server, throws instead of returning the requested name unchanged. Returning the unverified name would let a caller-supplied schema masquerade as a real database and defer a guaranteed failure to a later stage. If more than one database matches case-insensitively (for example testdb and TestDB), also throws, rather than reading from whichever one the server lists first.
        Throws:
        AthenaConnectorException - with ACCESS_DENIED_EXCEPTION if the schema is outside the configured scope, ENTITY_NOT_FOUND_EXCEPTION if it does not resolve to a database the token can read, or INVALID_INPUT_EXCEPTION if it matches more than one database
        InterruptedException
        IOException
      • resolveTableName

        public String resolveTableName​(String resolvedDB,
                                       TableName tableName)
                                throws Exception
        Resolves a lowercased table name back to the original case by querying information_schema given an already-resolved database. Throws if no matching table exists — there is no correct-case name to fall back to, and proceeding with the lowercased name would only defer a guaranteed failure to the read stage. Also throws if more than one table matches case-insensitively (for example Sensor and sensor).
        Throws:
        AthenaConnectorException - with ENTITY_NOT_FOUND_EXCEPTION if no table matches, or INVALID_INPUT_EXCEPTION if more than one table matches
        Exception
      • listColumns

        public List<InfluxDBConnectionFactory.ColumnInfo> listColumns​(String resolvedDB,
                                                                      String resolvedTable)
                                                               throws Exception
        Lists the columns of an already-resolved table, in the order information_schema.columns returns them. The table is matched by its exact, case-sensitive name. Athena lowercases column names, so two columns whose names differ only by case (for example a tag Region and a field region) cannot both be exposed. Rather than read one of them in place of the other, this fails closed.
        Throws:
        AthenaConnectorException - with INVALID_INPUT_EXCEPTION if two column names differ only by case
        Exception