kazdy commented on code in PR #170:
URL: https://github.com/apache/hudi-rs/pull/170#discussion_r1805125180
##########
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 please take a look and let me know what you think.
Imo this simplifies a lot on hudi-rs side, still pretty ok from the user's
point of view.
Now the other way around it should be easy to generate these filter strings
if required by some engine etc.
--
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]