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

Bad error message when passing invalid JSON to Aggregation #1485

Closed
PSeitz opened this issue May 18, 2022 · 0 comments · Fixed by quickwit-oss/tantivy#2003
Closed

Bad error message when passing invalid JSON to Aggregation #1485

PSeitz opened this issue May 18, 2022 · 0 comments · Fixed by quickwit-oss/tantivy#2003
Assignees
Labels
enhancement New feature or request

Comments

@PSeitz
Copy link
Contributor

PSeitz commented May 18, 2022

Error messages are like:
"Invalid aggregation request: data did not match any variant of untagged enum
Aggregation at line 18 column 2"

Currently the top level entry for an aggregation request uses #[serde(untagged)], which is trying to deserialize variants until one works. That's why we always get the above error message.

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Aggregation {
    /// Bucket aggregation, see [BucketAggregation] for details.
    Bucket(BucketAggregation),
    /// Metric aggregation, see [MetricAggregation] for details.
    Metric(MetricAggregation),
}

Effectively Aggregations are externally tagged (https://serde.rs/enum-representations.html).

{"terms": {...}}
{"histogram": {...}}

So ideally we would just flatten the buckets and metrics into a single enum, but serde does not support flattening on enums (serde-rs/serde#1402).

I see 3 Options currently:

  • Wait for/Implement flatten on enums in serde
  • Manually flatten the enums to the top-level (Internally that would be just an intermediate struct)
  • Use a custom deserializer (Ideally it would only manually implement the matching on the keys ("terms", "histogram", etc.) and use the defaults for the rest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant