-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: asynchronous query #123
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
55c0de2
fix: improves merge of flight_client_options, introduces method to pr…
karel-rehor 8e46dd5
feat: (WIP) start query_async() in query_api
karel-rehor 91004b1
chore: clean up flake from last commit
karel-rehor 4d17837
feat: (WIP) adds client.query_async() plus first tests
karel-rehor 99b4721
test: refactor - move arrow flight server mocks to util/mocks.py package
karel-rehor df50bb1
test: adds test of async behavior of query_api.query_async()
karel-rehor 707a83a
test: more relevant assert in new test
karel-rehor 7a80a4e
test: refactor - move asyncio_run helper method to utils/__init__.py
karel-rehor 299bc83
test: adds new unit test for client.query_async()
karel-rehor a436699
test: adds integration test for client.query_async()
karel-rehor 0559be4
test: replace match:case in util, which is supported only in 3.10+
karel-rehor 87f079c
docs: adds code documentation to key public methods
karel-rehor 5e28213
docs: add example
karel-rehor 9706005
docs: update CHANGELOG.md
karel-rehor 5d35da8
chore: replace hard coded version in tests with USER_AGENT
karel-rehor 774885e
docs: add more detail to CHANGELOG.md
karel-rehor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import asyncio | ||
import random | ||
import time | ||
|
||
import pandas | ||
|
||
from influxdb_client_3 import InfluxDBClient3 | ||
|
||
from config import Config | ||
|
||
|
||
async def fibio(iterations, grit=0.5): | ||
""" | ||
example coroutine to run parallel with query_async | ||
:param iterations: | ||
:param grit: | ||
:return: | ||
""" | ||
n0 = 1 | ||
n1 = 1 | ||
vals = [n0, n1] | ||
for _ in range(iterations): | ||
val = n0 + n1 | ||
n0 = n1 | ||
n1 = val | ||
print(val) | ||
vals.append(val) | ||
await asyncio.sleep(grit) | ||
return vals | ||
|
||
|
||
def write_data(client: InfluxDBClient3, measurement): | ||
""" | ||
Synchronous write - only for preparing data | ||
:param client: | ||
:param measurement: | ||
:return: | ||
""" | ||
ids = ['s3b1', 'dq41', 'sgw22'] | ||
lp_template = f"{measurement},id=%s speed=%f,alt=%f,bearing=%f %d" | ||
data_size = 10 | ||
data = [] | ||
interval = 10 * 1_000_000_000 | ||
ts = time.time_ns() - (interval * data_size) | ||
for _ in range(data_size): | ||
data.append(lp_template % (ids[random.randint(0, len(ids) - 1)], | ||
random.random() * 300, | ||
random.random() * 2000, | ||
random.random() * 360, ts)) | ||
ts += interval | ||
|
||
client.write(data) | ||
|
||
|
||
async def query_data(client: InfluxDBClient3, measurement): | ||
""" | ||
Query asynchronously - should not block other coroutines | ||
:param client: | ||
:param measurement: | ||
:return: | ||
""" | ||
query = f"SELECT * FROM \"{measurement}\" WHERE time >= now() - interval '5 minutes' ORDER BY time DESC" | ||
print(f"query start: {pandas.Timestamp(time.time_ns())}") | ||
table = await client.query_async(query) | ||
print(f"query returned: {pandas.Timestamp(time.time_ns())}") | ||
return table.to_pandas() | ||
|
||
|
||
async def main(): | ||
config = Config() | ||
client = InfluxDBClient3( | ||
host=config.host, | ||
token=config.token, | ||
database=config.database, | ||
org=config.org | ||
) | ||
measurement = 'example_uav' | ||
write_data(client, measurement) | ||
|
||
# run both coroutines simultaneously | ||
result = await asyncio.gather(fibio(10, 0.2), query_data(client, measurement)) | ||
print(f"fibio sequence = {result[0]}") | ||
print(f"data set =\n{result[1]}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the CHANGELOG to outline the next steps for achieving full asyncio support—e.g., indicating if the next PR will add async write functionality or something else along those lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated