-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add integer range condition and integer start_from
to interface
#3574
Conversation
Update: merge conflicts have been solved |
@@ -59,6 +59,34 @@ impl DateTimeWrapper { | |||
} | |||
} | |||
|
|||
impl FromStr for DateTimePayloadType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was just moved closer to the definition of DateTimeWrapper
impl ValueChecker for Range<FloatPayloadType> { | ||
fn check_match(&self, payload: &Value) -> bool { | ||
payload | ||
.as_number() | ||
.and_then(|x| x.as_f64().or_else(|| x.as_i64().map(|x| x as f64))) | ||
.map_or(false, |x| self.check_range(x)) | ||
} | ||
} | ||
|
||
impl ValueChecker for Range<IntPayloadType> { | ||
fn check_match(&self, payload: &Value) -> bool { | ||
payload | ||
.as_number() | ||
.and_then(|x| x.as_i64().or_else(|| x.as_f64().map(|x| x as i64))) | ||
.map_or(false, |x| self.check_range(x)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For unindexed fields, we now try to convert into the type of the range to do the checks
pub fn get_int_range_checkers( | ||
index: &FieldIndex, | ||
range: Range<IntPayloadType>, | ||
) -> Option<ConditionCheckerFn> { | ||
match index { | ||
FieldIndex::IntIndex(num_index) => Some(Box::new(move |point_id: PointOffsetType| { | ||
num_index | ||
.get_values(point_id) | ||
.is_some_and(|values| values.iter().copied().any(|i| range.check_range(i))) | ||
})), | ||
FieldIndex::FloatIndex(num_index) => { | ||
let range = range.map(|i| i as FloatPayloadType); | ||
Some(Box::new(move |point_id: PointOffsetType| { | ||
num_index | ||
.get_values(point_id) | ||
.is_some_and(|values| values.iter().copied().any(|f| range.check_range(f))) | ||
})) | ||
} | ||
_ => None, | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For indexed fields, we follow same approach as before, converting the range into the type of the index
In the meantime, I'll draft this PR to avoid merging just yet. Edit: this is no longer an issue with pydantic >= 2, which uses smart union matching. Undrafting |
Dismissing the review to avoid merging yet. The current approach is problematic with client generation. Specifically when deciding if a range is represented as all int or all float, a better approach might be to allow this flexibility at the comparator level. E.g gt: IntOrFloat
Please feel free to make another iteration, once we will have a better idea of how integrate it into the client |
To finish taking advantage of the newly added range interface. This adds:
Range<IntPayloadType>
toRangeInterface
StartFrom::Int(IntPayloadType)
variant for order-byscroll
requests.All Submissions:
dev
branch. Did you create your branch fromdev
?New Feature Submissions:
cargo +nightly fmt --all
command prior to submission?cargo clippy --all --all-features
command?Changes to Core Features: