From d91c54becac87bdb3706abf041e52a0b1aae9974 Mon Sep 17 00:00:00 2001 From: brayo Date: Thu, 4 Jul 2024 12:50:39 +0300 Subject: [PATCH] feat: updates to use tuple timeperiods --- src/examples/query_client.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/examples/query_client.py b/src/examples/query_client.py index 6a378fe..cdf530e 100755 --- a/src/examples/query_client.py +++ b/src/examples/query_client.py @@ -13,7 +13,12 @@ start = now query = "RETURN=0;" -res = client.query(query, "1970-01-01", "2100-01-01") +start_date = datetime(1970, 1, 1, tzinfo=timezone.utc) +end_date = datetime(2100, 1, 1, tzinfo=timezone.utc) + +# Note that the timeperiods are a list of tuples +timeperiods = [(start_date, end_date)] +res = client.query(query, timeperiods=timeperiods) print(res) # Should print 0 bucket_id = "{}_{}".format("test-client-bucket", client.client_hostname) @@ -33,22 +38,23 @@ def insert_events(label: str, count: int): insert_events("a", 5) -query = "RETURN = query_bucket('{}');".format(bucket_id) +query = 'RETURN = query_bucket("{}");'.format(bucket_id) -res = client.query(query, "1970", "2100") +res = client.query(query,timeperiods=timeperiods) print(res) # Should print the last 5 events -res = client.query(query, start + timedelta(seconds=1), now - timedelta(seconds=2)) +timeperiods_2 = [(start+timedelta(seconds=1), now-timedelta(seconds=2))] +res = client.query(query, timeperiods=timeperiods_2) print(res) # Should print three events insert_events("b", 10) query = """ -events = query_bucket('{}'); -merged_events = merge_events_by_keys(events, 'label'); +events = query_bucket("{}"); +merged_events = merge_events_by_keys(events, ["label"]); RETURN=merged_events; """.format(bucket_id) -res = client.query(query, "1970", "2100") +res = client.query(query, timeperiods=timeperiods) # Should print two merged events # Event "a" with a duration of 5s and event "b" with a duration of 10s print(res)