Skip to content

Commit

Permalink
fix: table read query deduplicates identical rows (#2608)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning authored Oct 7, 2024
1 parent 00e5fa6 commit 483ae68
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/trace/test_table_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,44 @@ def test_table_query_with_duplicate_row_digests(client: WeaveClient):
)

assert len(res.rows) == 3


def test_duplicate_table_with_identical_rows(client: WeaveClient):
data = [{"val": i} for i in range(10)]

res1 = client.server.table_create(
tsi.TableCreateReq(
table=tsi.TableSchemaForInsert(
rows=data,
project_id=client._project_id(),
),
)
)

assert len(res1.row_digests) == 10

# now create the same table with the same data
res2 = client.server.table_create(
tsi.TableCreateReq(
table=tsi.TableSchemaForInsert(
rows=data,
project_id=client._project_id(),
),
)
)

assert len(res2.row_digests) == 10

# this is the same table!
assert res1.digest == res2.digest

res = client.server.table_query(
tsi.TableQueryReq(
project_id=client._project_id(),
digest=res1.digest,
sort_by=[tsi.SortBy(field="val", direction="asc")],
)
)

# this is the same table, so we should get the same number of rows
assert len(res.rows) == 10
2 changes: 2 additions & 0 deletions weave/trace_server/table_query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def make_natural_sort_table_query(
FROM tables
WHERE project_id = {{{project_id_name}: String}}
AND digest = {{{digest_name}: String}}
LIMIT 1
)
ARRAY JOIN row_digests AS row_digest
) AS t ON tr.digest = t.row_digest
Expand Down Expand Up @@ -98,6 +99,7 @@ def make_standard_table_query(
FROM tables
WHERE project_id = {{{project_id_name}: String}}
AND digest = {{{digest_name}: String}}
LIMIT 1
)
ARRAY JOIN row_digests AS row_digest
) AS t ON tr.digest = t.row_digest
Expand Down

0 comments on commit 483ae68

Please sign in to comment.