kazdy commented on code in PR #170:
URL: https://github.com/apache/hudi-rs/pull/170#discussion_r1803657741
##########
crates/core/src/table/partition.rs:
##########
@@ -506,4 +525,75 @@ mod tests {
assert!(pruner.parse_segments("invalid/path").is_err());
}
+
+ #[test]
+ fn test_strip_single_quote_for_date_filter() {
+ for data_type in [DataType::Date32, DataType::Date64] {
+ let schema = Schema::new(vec![Field::new("date",
data_type.clone(), false)]);
+
+ let cast_options = CastOptions {
+ safe: false,
+ format_options: Default::default(),
+ };
+
+ let value = StringArray::from(vec!["2023-01-01"]);
+ let value = cast_with_options(&value, &data_type,
&cast_options).unwrap();
+
+ let filter_str = "date = '2023-01-01'";
+ let filter = PartitionFilter::try_from((filter_str, &schema));
+ assert!(filter.is_ok());
+ let filter = filter.unwrap();
+ assert_eq!(filter.field.name(), "date");
+ assert_eq!(filter.operator, Operator::Eq);
+ assert_eq!(filter.value.get().0.len(), 1);
+ assert_eq!(filter.value.get().0, value.get().0);
+ }
+ }
+
+ #[test]
+ fn test_strip_single_quote_for_string_filter() {
+ for data_type in [DataType::Utf8, DataType::Utf8View,
DataType::LargeUtf8] {
+ let schema = Schema::new(vec![Field::new("category",
data_type.clone(), false)]);
+
+ let cast_options = CastOptions {
+ safe: false,
+ format_options: Default::default(),
+ };
+
+ let value = StringArray::from(vec!["foo"]);
+ let value = cast_with_options(&value, &data_type,
&cast_options).unwrap();
+
+ let filter_str = "category!='foo'";
+ let filter = PartitionFilter::try_from((filter_str, &schema));
+ assert!(filter.is_ok());
+ let filter = filter.unwrap();
+ assert_eq!(filter.field.name(), "category");
+ assert_eq!(filter.operator, Operator::Ne);
+ assert_eq!(filter.value.get().0.len(), 1);
+ assert_eq!(filter.value.get().0, value.get().0)
+ }
+ }
+
+ #[test]
+ fn test_do_not_strip_one_side_single_quoted_value_for_filter() {
+ let data_type = DataType::Utf8;
+ let schema = Schema::new(vec![Field::new("category",
data_type.clone(), false)]);
+
+ let cast_options = CastOptions {
+ safe: false,
+ format_options: Default::default(),
+ };
+
+ let value = StringArray::from(vec!["'foo"]);
Review Comment:
@xushiyan what if we flip it a bit and make
PartitionFilter::try_from() take a 3 element tuple containing key, operator,
value instead?
Then we can (based on the schema) simply assume the type and don't need
worry about the single quotes.
so:
`PartitionFilter::try_from(("part", "=", "A"))`
`PartitionFilter::try_from(("part", "=", "2022-01-01"))`
`PartitionFilter::try_from(("part", "IN", ["2022-01-01", "2023-02-02"]))`
Then we simplify and leave the parsing to the user or system that uses that,
but it's simple enough not to be frustrating to use.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]