Skip to content

Conversation

bitner
Copy link
Contributor

@bitner bitner commented Dec 12, 2024

This PR adds a reduce and match function to Expr. Both functions take an optional json argument that will be used to get the values of any properties to compare against.

expr.reduce(json) will attempt to solve any operations. If there is no json, this will reduce the expression by evaluating any operations that use constants. If there is a json passed in, it will pull any properties from that json and turn them into constants before trying to reduce.

expr.matches(json) will attempt to reduce the expression and if that expression gets reduced to just a single Expr::Bool, it will return that value.

  • Arithmetic Operators
  • Comparison Operators for Number
  • Comparison Operators for Boolean
  • Comparison Operators for Text
  • Spatial Operators
  • Temporal Operators
  • Testing Framework for Reduce
  • Implement Array Operators
  • Implement Like
  • Implement In
  • Implement Not
  • Implement Between
  • Implement Cast from BBox to geos geometry

@bitner
Copy link
Contributor Author

bitner commented Dec 12, 2024

So, trying to set this up so that the reduce function can actually be used for any CQL2 expression to collapse things that don't need to go through to the base data. So say you had a CQL2 query like foo = 2 +7, you could use reduce to convert that to foo = 9 . To do that, I'll need to make the json input an option, if it can look up a property in the json, it will replace it with the value in that json. The matches function just looks to see if running reduce has boiled the entire expression down into an Expr::Bool and if so returns that value, if it couldn't reduce it all the way it returns an error.

Copy link
Member

@kylebarron kylebarron left a comment

Choose a reason for hiding this comment

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

I don't really know CQL so I didn't look too closely at the body of reduce (yet)

@bitner bitner marked this pull request as ready for review January 21, 2025 17:35
@bitner bitner requested review from gadomski and alukach January 21, 2025 17:35
src/geometry.rs Outdated

impl PartialEq for Geometry {
fn eq(&self, other: &Self) -> bool {
self.to_wkt().unwrap() == other.to_wkt().unwrap()
Copy link
Collaborator

@gadomski gadomski Jan 21, 2025

Choose a reason for hiding this comment

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

Should probably just return false if to_wkt fails, not unwrap

@bitner bitner requested a review from gadomski January 27, 2025 19:59
@bitner bitner merged commit 3e980e3 into main Jan 27, 2025
1 check passed
@bitner bitner deleted the jsonmatch branch January 27, 2025 22:39
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