-
Notifications
You must be signed in to change notification settings - Fork 5
InfluxDB IOx
InfluxDB IOx requires bucket-name
or bucket-id
to be presented as gRPC metadata in Flight SQL requests. When creating a FlightSQLClient
directly this means providing these keys in the metadata
dictionary. When dialing via SQLAlchemy's DSN you will add bucket-name
/bucket-id
as additional query parameters.
from flightsql import FlightSQLClient
client = FlightSQLClient(
host="eu-central-1-1.aws.cloud2.influxdata.com",
token="INFLUXDBTOKEN",
metadata={"bucket-name": "_tasks"},
)
Same as Directly with Client, but passing the client
into connect
.
from flightsql import FlightSQLClient, connect
client = FlightSQLClient(
host="eu-central-1-1.aws.cloud2.influxdata.com",
token="INFLUXDBTOKEN",
metadata={"bucket-name": "_tasks"},
)
conn = connect(client)
import flightsql.sqlalchemy
from sqlalchemy.engine import create_engine
engine = create_engine("datafusion+flightsql://eu-central-1-1.aws.cloud2.influxdata.com:443?token=INFLUXDBTOKEN&bucket-name=_tasks")
It's possible to specify bucket information at multiple points when you are using the FlightSQLClient
directly. Below is an outline of the different strategies.
This is the recommended approach.
Specify a bucket when creating the client, but potentially override it later if you need to query a different bucket.
from flightsql import FlightSQLClient
from flightsql.client import CallOptions
client = FlightSQLClient(
host="eu-central-1-1.aws.cloud2.influxdata.com",
token="INFLUXDBTOKEN",
metadata={"bucket-name": "cool"},
)
# Executed against the `cool` bucket.
info = client.execute("select * from data")
results = client.do_get(info.endpoints[0].ticket)
# Override the bucket to source data from `rad`.
#
# While not strictly necessary to present `call_options` to *both* the `execute`
# and `do_get` calls, it's recommended, because Flight SQL is stateless.
call_options = CallOptions(headers=[(b'bucket-name', b'rad')])
info = client.execute("select * from data", call_options)
results = client.do_get(info.endpoints[0].ticket, call_options)
Omit the bucket information from the client creation entirely and require RPCs to specify the bucket they are speaking about.
from flightsql import FlightSQLClient
from flightsql.client import CallOptions
# Notice we have not specified a bucket here. RPCs without `CallOptions` will fail.
client = FlightSQLClient(
host="eu-central-1-1.aws.cloud2.influxdata.com",
token="INFLUXDBTOKEN",
)
# Executed against the `cool` bucket.
call_options = CallOptions(headers=[(b'bucket-name', b'cool')])
info = client.execute("select * from data", call_options)
results = client.do_get(info.endpoints[0].ticket, call_options)
# Executed against the `rad` bucket.
call_options = CallOptions(headers=[(b'bucket-name', b'rad')])
info = client.execute("select * from data", call_options)
results = client.do_get(info.endpoints[0].ticket, call_options)