Skip to content

Conversation

@Sicheng-Pan
Copy link
Contributor

@Sicheng-Pan Sicheng-Pan commented Oct 20, 2025

Description of changes

Summarize the changes made by this PR.

  • Improvements & Bug fixes
    • N/A
  • New functionality
    • impl Serialize for Where. Previously it's a todo!
    • Adjust how Filter is serialized

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Migration plan

Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?

Observability plan

What is the plan to instrument and monitor this change?

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the _docs section?_

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@Sicheng-Pan Sicheng-Pan marked this pull request as ready for review October 20, 2025 05:04
@propel-code-bot
Copy link
Contributor

propel-code-bot bot commented Oct 20, 2025

Implement Serialization for Where Clause and Adjust Filter Serialization

This pull request finalizes Rust-side serialization for the Where clause by providing an implementation for impl Serialize for Where in rust/types/src/metadata.rs. Prior to this change, serialization of the Where structure was marked as todo!(); this PR provides a concrete serialization implementation for all Where enum variants (Composite, Document, and Metadata). Additionally, the serialization logic for the Filter struct in rust/types/src/execution/operator.rs is reworked so that its serialized form is now either an empty object, a directly serialized Where clause, or a conjunction when both query_ids and a where_clause are present, matching API requirements.

Key Changes

• Added a full implementation of Serialize for the Where enum in rust/types/src/metadata.rs, serializing all composite, document, and metadata expressions into JSON-compatible structures.
• Reworked how the Filter struct serializes itself in rust/types/src/execution/operator.rs. Serialization now produces an empty object if there are no filters, directly serializes the Where clause if present, or ANDs together query_ids and where_clause filters as needed.
• Made necessary imports (e.g., ser::SerializeMap) to enable custom serialization.
• Removed unused derive macros and serde attributes from Filter initialization, now replaced by explicit serialization logic.

Affected Areas

rust/types/src/metadata.rs
rust/types/src/execution/operator.rs

This summary was automatically generated by @propel-code-bot

Comment on lines +929 to +936
let values_json = match set_value {
MetadataSetValue::Bool(v) => serde_json::to_value(v),
MetadataSetValue::Int(v) => serde_json::to_value(v),
MetadataSetValue::Float(v) => serde_json::to_value(v),
MetadataSetValue::Str(v) => serde_json::to_value(v),
}
.map_err(serde::ser::Error::custom)?;
inner_map.insert(op_key.to_string(), values_json);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BestPractice]

This match statement can be simplified using serde's derive macros. If you add #[derive(Serialize)] and #[serde(untagged)] to the MetadataSetValue enum definition, you can serialize it directly, making the code more concise and idiomatic.

First, modify the MetadataSetValue enum definition:

#[derive(Clone, Debug, PartialEq, Serialize)]
#[cfg_attr(feature = "testing", derive(proptest_derive::Arbitrary))]
#[serde(untagged)]
pub enum MetadataSetValue {
    Bool(Vec<bool>),
    Int(Vec<i64>),
    Float(Vec<f64>),
    Str(Vec<String>),
}

Then you can simplify this block:

Suggested change
let values_json = match set_value {
MetadataSetValue::Bool(v) => serde_json::to_value(v),
MetadataSetValue::Int(v) => serde_json::to_value(v),
MetadataSetValue::Float(v) => serde_json::to_value(v),
MetadataSetValue::Str(v) => serde_json::to_value(v),
}
.map_err(serde::ser::Error::custom)?;
inner_map.insert(op_key.to_string(), values_json);
let values_json =
serde_json::to_value(set_value).map_err(serde::ser::Error::custom)?;

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Context for Agents
[**BestPractice**]

This `match` statement can be simplified using serde's derive macros. If you add `#[derive(Serialize)]` and `#[serde(untagged)]` to the `MetadataSetValue` enum definition, you can serialize it directly, making the code more concise and idiomatic.

First, modify the `MetadataSetValue` enum definition:
```rust
#[derive(Clone, Debug, PartialEq, Serialize)]
#[cfg_attr(feature = "testing", derive(proptest_derive::Arbitrary))]
#[serde(untagged)]
pub enum MetadataSetValue {
    Bool(Vec<bool>),
    Int(Vec<i64>),
    Float(Vec<f64>),
    Str(Vec<String>),
}
```

Then you can simplify this block:

```suggestion
                        let values_json =
                            serde_json::to_value(set_value).map_err(serde::ser::Error::custom)?;
```

⚡ **Committable suggestion**

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

File: rust/types/src/metadata.rs
Line: 936

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could work, but this is fine for now

@Sicheng-Pan Sicheng-Pan force-pushed the 10-19-_enh_serialize_where_clause_in_rust branch from 2775b6e to 6e3aceb Compare October 20, 2025 16:22
@Sicheng-Pan Sicheng-Pan merged commit 9aa36b6 into main Oct 20, 2025
59 of 61 checks passed
@Sicheng-Pan Sicheng-Pan deleted the 10-19-_enh_serialize_where_clause_in_rust branch October 23, 2025 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants