-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for serialization FluxTable into JSON (#320)
- Loading branch information
Showing
7 changed files
with
418 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from influxdb_client import InfluxDBClient, Point | ||
from influxdb_client.client.write_api import SYNCHRONOUS | ||
|
||
with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client: | ||
|
||
""" | ||
Prepare data | ||
""" | ||
_point1 = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3) | ||
_point2 = Point("my_measurement").tag("location", "New York").field("temperature", 24.3) | ||
|
||
client.write_api(write_options=SYNCHRONOUS).write(bucket="my-bucket", record=[_point1, _point2]) | ||
|
||
""" | ||
Query: using Table structure | ||
""" | ||
tables = client.query_api().query('from(bucket:"my-bucket") |> range(start: -10m)') | ||
|
||
""" | ||
Serialize to JSON | ||
""" | ||
import json | ||
from influxdb_client.client.flux_table import FluxStructureEncoder | ||
|
||
output = json.dumps(tables, cls=FluxStructureEncoder, indent=2) | ||
print(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.