Skip to content

query-engine: ClickHouse adapter writes GROUP BY columns in alphabetical order, not SELECT order #897

Open

Description

@milindsrivastava1997

clickhouse_http.rs format_success_response writes each row's label values in query_output_labels order, then the value. That list comes from KeyByLabelNames::new, which sorts names alphabetically (key_by_label_names.rs:13), and the SQL GROUP BY labels are kept in a HashSet (sqlhelper.rs:97), so the SELECT order is lost.

ClickHouse returns columns in SELECT order, and TabSeparated has no header. So for SELECT job, instance, SUM(value) ... GROUP BY job, instance, ClickHouse answers job, instance, value but ASAPQuery answers instance, job, value. Queries ASAPQuery forwards to its ClickHouse fallback come back in SELECT order, so one server can return both orders.

Effect: with #896, calculate_fidelity names TSV columns from the SELECT list. When the GROUP BY columns aren't in alphabetical order in the SELECT list, ASAPQuery's series don't match the exact ones and are skipped. When two label columns share values (e.g. srcip/dstip), rows can pair with the wrong labels. Any other client reading the TSV positionally gets the wrong labels too. Answers from the rqe route (#890) carry label names and are unaffected.

Fix: write label columns in the query's SELECT order, e.g. keep the SELECT column order through SQL matching and use it in the adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions