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)