Class InfluxDBConnectionFactory
- java.lang.Object
-
- com.amazonaws.athena.connectors.influxdb.InfluxDBConnectionFactory
-
public class InfluxDBConnectionFactory extends Object
Creates InfluxDB client connections, resolving the auth token from Secrets Manager. TheINFLUXDB3_AUTH_TOKENenv 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 varINFLUXDB3_AUTH_TOKEN_KEY, defaulttoken).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInfluxDBConnectionFactory.ColumnInfoA table column as reported byinformation_schema.columns: its case-sensitive InfluxDB name and itsdata_typedisplay name.static classInfluxDBConnectionFactory.DatabaseInfostatic interfaceInfluxDBConnectionFactory.InfluxDBQuery<T>A query against anInfluxDBClientthat may fail with an auth error.
-
Constructor Summary
Constructors Constructor Description InfluxDBConnectionFactory(Map<String,String> configOptions, FederationRequestHandler handler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TexecuteWithTokenRetry(String database, InfluxDBConnectionFactory.InfluxDBQuery<T> query)Runsqueryagainst a client fordatabase, underwithCredentialRefresh(com.amazonaws.athena.connectors.influxdb.InfluxDBConnectionFactory.Attempt<T>).com.influxdb.v3.client.InfluxDBClientgetClient(String database)Creates an InfluxDBClient for the given database.List<InfluxDBConnectionFactory.ColumnInfo>listColumns(String resolvedDB, String resolvedTable)Lists the columns of an already-resolved table, in the orderinformation_schema.columnsreturns them.StringresolveDatabase(String schemaName)Resolves a lowercased schema name back to the original database name.StringresolveTableName(String resolvedDB, TableName tableName)Resolves a lowercased table name back to the original case by querying information_schema given an already-resolved database.voidsetHandler(FederationRequestHandler handler)Sets the handler reference for secret resolution.
-
-
-
Constructor Detail
-
InfluxDBConnectionFactory
public InfluxDBConnectionFactory(Map<String,String> configOptions, FederationRequestHandler handler)
-
-
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
Runsqueryagainst a client fordatabase, underwithCredentialRefresh(com.amazonaws.athena.connectors.influxdb.InfluxDBConnectionFactory.Attempt<T>). Client creation happens inside the attempt, so the database-existence check that a cache miss triggers (seeassertDatabaseExists(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 viainfluxdb_database, that database is the only permissible target: any other schema is rejected outright (seeenforceDatabaseScope(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 exampletestdbandTestDB), also throws, rather than reading from whichever one the server lists first.- Throws:
AthenaConnectorException- withACCESS_DENIED_EXCEPTIONif the schema is outside the configured scope,ENTITY_NOT_FOUND_EXCEPTIONif it does not resolve to a database the token can read, orINVALID_INPUT_EXCEPTIONif it matches more than one databaseInterruptedExceptionIOException
-
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 exampleSensorandsensor).- Throws:
AthenaConnectorException- withENTITY_NOT_FOUND_EXCEPTIONif no table matches, orINVALID_INPUT_EXCEPTIONif more than one table matchesException
-
listColumns
public List<InfluxDBConnectionFactory.ColumnInfo> listColumns(String resolvedDB, String resolvedTable) throws Exception
Lists the columns of an already-resolved table, in the orderinformation_schema.columnsreturns 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 tagRegionand a fieldregion) cannot both be exposed. Rather than read one of them in place of the other, this fails closed.- Throws:
AthenaConnectorException- withINVALID_INPUT_EXCEPTIONif two column names differ only by caseException
-
-