forked from InfluxCommunity/influxdb3-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_type.py
55 lines (42 loc) · 1.41 KB
/
query_type.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import influxdb_client_3 as InfluxDBClient3
client = InfluxDBClient3.InfluxDBClient3(
token="",
host="eu-central-1-1.aws.cloud2.influxdata.com",
org="6a841c0c08328fb1",
database="factory")
# Chunk mode provides a FlightReader object that can be used to read chunks of data.
reader = client.query(
query="SELECT * FROM machine_data WHERE time > now() - 2h",
language="influxql", mode="chunk")
try:
while True:
batch, buff = reader.read_chunk()
print("batch:")
print(batch.to_pandas())
except StopIteration:
print("No more chunks to read")
# Pandas mode provides a Pandas DataFrame object.
df = client.query(
query="SELECT * FROM machine_data WHERE time > now() - 2h",
language="influxql", mode="pandas")
print("pandas:")
print(df)
# All mode provides an Arrow Table object.
table = client.query(
query="SELECT * FROM machine_data WHERE time > now() - 2h",
language="influxql", mode="all")
print("table:")
print(table)
# Print the schema of the table
table = client.query(
query="SELECT * FROM machine_data WHERE time > now() - 2h",
language="influxql", mode="schema")
print("schema:")
print(table)
# Convert this reader into a regular RecordBatchReader
reader = client.query(
query="SELECT * FROM machine_data WHERE time > now() - 2h",
language="influxql", mode="reader")
print("reader:")
for batch in reader:
print(batch.to_pandas())