Skip to content

Commit

Permalink
Use only integers for timestamps in queries (#73)
Browse files Browse the repository at this point in the history
* fixes for rust implementation

* update CHANGELOG

* fmt
  • Loading branch information
atimin authored May 10, 2023
1 parent bf71697 commit 885db8d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Subscribing to new records, [PR-70](https://github.com/reductstore/reduct-py/pull/70)

### Fixed:

- No int timestamps in queries, [PR-73](https://github.com/reductstore/reduct-py/pull/73)

## [1.3.1] - 2023-01-30

### Fixed:
Expand Down
13 changes: 7 additions & 6 deletions reduct/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Record:
size: int
"""size of data"""
last: bool
"""last record in the query"""
"""last record in the query. Deprecated: doesn't work for some cases"""
content_type: str
"""content type of data"""
read_all: Callable[[None], Awaitable[bytes]]
Expand Down Expand Up @@ -215,7 +215,7 @@ async def read(
>>> async with bucket.read("entry", timestamp=123456789) as record:
>>> data = await record.read_all()
"""
params = {"ts": timestamp} if timestamp else None
params = {"ts": int(timestamp)} if timestamp else None
async with self._http.request(
"GET", f"/b/{self.name}/{entry_name}", params=params
) as resp:
Expand Down Expand Up @@ -256,7 +256,8 @@ async def write(
>>> await bucket.write("entry-1", sender(), content_length=15)
"""
params = {"ts": timestamp if timestamp else time.time_ns() / 1000}
timestamp = timestamp if timestamp else time.time_ns() / 1000
params = {"ts": int(timestamp)}
await self._http.request_all(
"POST",
f"/b/{self.name}/{entry_name}",
Expand Down Expand Up @@ -353,11 +354,11 @@ async def subscribe(
async def _query(self, entry_name, start, stop, ttl, **kwargs):
params = {}
if start:
params["start"] = start
params["start"] = int(start)
if stop:
params["stop"] = stop
params["stop"] = int(stop)
if ttl:
params["ttl"] = ttl
params["ttl"] = int(ttl)

if "include" in kwargs:
for name, value in kwargs["include"].items():
Expand Down
1 change: 0 additions & 1 deletion reduct/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ async def request(
headers=dict(self.headers, **extra_headers),
**kwargs,
) as response:

if response.ok:
yield response
else:
Expand Down
5 changes: 1 addition & 4 deletions tests/bucket_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async def test__write_by_timestamp(bucket_2):
async def test__write_with_current_time(bucket_2):
"""Should write a record with current time"""
belated_timestamp = int(time.time_ns() / 1000)
await asyncio.sleep(0.01)

await bucket_2.write("entry-3", b"test-data")
await bucket_2.write("entry-3", b"old-data", timestamp=belated_timestamp)
Expand Down Expand Up @@ -174,12 +175,10 @@ async def test_query_records(bucket_1):
assert records[0].timestamp == 3000000
assert records[0].size == 11
assert records[0].content_type == "application/octet-stream"
assert not records[0].last

assert records[1].timestamp == 4000000
assert records[1].size == 11
assert records[1].content_type == "application/octet-stream"
assert records[1].last


@pytest.mark.asyncio
Expand Down Expand Up @@ -212,7 +211,6 @@ async def test_query_records_included_labels(bucket_1):

assert len(records) == 1
assert records[0].labels == {"label1": "value1", "label2": "value2"}
assert records[0].last


@pytest.mark.asyncio
Expand All @@ -233,7 +231,6 @@ async def test_query_records_excluded_labels(bucket_2):

assert len(records) == 1
assert records[0].labels == {"label1": "value1", "label2": "value3"}
assert records[0].last


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def test__bad_url_server_exists():

with pytest.raises(ReductError) as reduct_err:
await client.info()
assert str(reduct_err.value) == ("Status 404: Not Found")
assert str(reduct_err.value) == ("Status 404: Not found")


@pytest.mark.asyncio
Expand Down

0 comments on commit 885db8d

Please sign in to comment.