Skip to content
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

API: meta contains query does not work #638

Closed
QuantumDancer opened this issue Jan 19, 2024 · 1 comment
Closed

API: meta contains query does not work #638

QuantumDancer opened this issue Jan 19, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@QuantumDancer
Copy link
Collaborator

Querying records that contain a given meta value does not work. MWE:

from pyauditor import AuditorClientBuilder, MetaOperator, MetaQuery, QueryBuilder, Record, Meta, Score, Component
import datetime

def add_records(site_id, client):
    for i in range(0, 24):
        record_id = f"record-{i:02d}-{site_id}"

        start = datetime.datetime(2022, 10, 8, i, 0, 0, 0, tzinfo=datetime.timezone.utc)
        stop = datetime.datetime(2022, 10, 9, i, 0, 0, 0, tzinfo=datetime.timezone.utc)
        meta = (
            Meta()
            .insert("site_id", [site_id])
            .insert("group_id", ["group_1"])
            .insert("nodes", ["node1", "node2"])
        )
        score1 = Score("HEPSPEC", 1.0)
        component1 = Component("comp-1", 10).with_score(score1)

        record = (
            Record(record_id, start)
            .with_stop_time(stop)
            .with_meta(meta)
            .with_component(component1)
        )

        client.add(record)


builder = AuditorClientBuilder()
builder = builder.address("127.0.0.1", 8000)
client = builder.build_blocking()

add_records("site_A", client)
add_records("site_B", client)

meta_operator = MetaOperator().contains("site_B")
meta_query = MetaQuery().meta_operator("site_id", meta_operator)
query_string = QueryBuilder().with_meta_query(meta_query).build()
print(query_string)
records = client.advanced_query(query_string)

print(len(records))

This returns 48, but it should return 24.

We didn't catch this in our unit/integration tests, because we only test the meta contains operator only if there is one unique value in the meta key:

Instead, we should create records with different values for a meta entry and then check if we select a subset of records.

Originally reported by @dirksammel

@QuantumDancer
Copy link
Collaborator Author

Closed by #645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants