From 14106043bda60de3548dff858976e68d11922904 Mon Sep 17 00:00:00 2001 From: victoria de sainte agathe Date: Mon, 11 Sep 2023 10:30:42 +0200 Subject: [PATCH 1/7] ok --- src/data_type/mod.rs | 23 +++++++++++++++++++++++ src/expr/transforms.rs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/data_type/mod.rs b/src/data_type/mod.rs index 6468ae29..c77c0b38 100644 --- a/src/data_type/mod.rs +++ b/src/data_type/mod.rs @@ -3044,6 +3044,29 @@ mod tests { ) } + #[test] + fn test_equalities_union_struct() { + let s1 = DataType::structured([ + ("a", DataType::float()), + ("b", DataType::float()), + ]); + let s2 = DataType::structured([ + ("a", DataType::boolean()), + ("b", DataType::integer()), + ]); + assert!(s1 != s2); + + let u1 = DataType::union([ + ("table1", s1.clone()), + ("table2", s2.clone()), + ]); + let u2 = DataType::union([ + ("table1", s1.clone()), + ("table2", s1.clone()), + ]); + assert!(u1 != u2) + } + #[test] fn test_equalities() { let empty_interval = DataType::from(Intervals::::empty()); diff --git a/src/expr/transforms.rs b/src/expr/transforms.rs index 04e74493..8eee4242 100644 --- a/src/expr/transforms.rs +++ b/src/expr/transforms.rs @@ -6,7 +6,7 @@ use std::f64::consts::PI; impl Expr { /// Gaussian noise based on [Box Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) - pub fn gaussian_noise() -> Self { + pub fn gaussian_noise() -> Self { Expr::multiply( Expr::sqrt(Expr::multiply( Expr::val(-2.0), From 0d9e97ef099a1e570479b90748d28d64c241ebc4 Mon Sep 17 00:00:00 2001 From: victoria de sainte agathe Date: Mon, 11 Sep 2023 16:41:42 +0200 Subject: [PATCH 2/7] fix --- src/data_type/mod.rs | 83 +++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 25 deletions(-) diff --git a/src/data_type/mod.rs b/src/data_type/mod.rs index c77c0b38..2cbdc867 100644 --- a/src/data_type/mod.rs +++ b/src/data_type/mod.rs @@ -1194,6 +1194,22 @@ impl hash::Hash for Union { } } +// impl PartialEq for Union { +// fn eq(&self, other: &Self) -> bool { +// if self.len() == other.len() { +// self.iter().map(|f| f.0.clone()).sorted() +// .zip(other.iter().map(|f| f.0.clone()).sorted()) +// .all(|(s1, s2)| ( +// s1 == s2 && +// self.field(&s1).map(|f| f.1.as_ref()).unwrap_or(&DataType::Any) == other.field(&s1).map(|f| f.1.as_ref()).unwrap_or(&DataType::Any)) +// ) +// } else { +// false +// } + +// } +// } + /// To ease iteration impl Deref for Union { type Target = [(String, Rc)]; @@ -1332,7 +1348,7 @@ impl Variant for Union { && self .fields .iter() - .all(|(f, t)| t.is_subset_of(&self.data_type(f))) + .all(|(f, t)| t.is_subset_of(&other.data_type(f))) } fn super_union(&self, other: &Self) -> Result { @@ -2962,6 +2978,8 @@ mod tests { use statrs::statistics::Data; + use crate::data_type; + use super::*; #[test] @@ -3044,29 +3062,6 @@ mod tests { ) } - #[test] - fn test_equalities_union_struct() { - let s1 = DataType::structured([ - ("a", DataType::float()), - ("b", DataType::float()), - ]); - let s2 = DataType::structured([ - ("a", DataType::boolean()), - ("b", DataType::integer()), - ]); - assert!(s1 != s2); - - let u1 = DataType::union([ - ("table1", s1.clone()), - ("table2", s2.clone()), - ]); - let u2 = DataType::union([ - ("table1", s1.clone()), - ("table2", s1.clone()), - ]); - assert!(u1 != u2) - } - #[test] fn test_equalities() { let empty_interval = DataType::from(Intervals::::empty()); @@ -3096,6 +3091,39 @@ mod tests { ); assert_eq!(empty_interval, DataType::Null); assert_eq!(DataType::Null, empty_interval); + + // structs + let s1 = DataType::structured([ + ("a", DataType::float()), + ("b", DataType::float()), + ]); + let s2 = DataType::structured([ + ("a", DataType::boolean()), + ("b", DataType::integer()), + ]); + assert!(s1 != s2); + + // struct of struct + let ss1 = DataType::structured([ + ("table1", s1.clone()), + ("table2", s2.clone()), + ]); + let ss2 = DataType::structured([ + ("table1", s1.clone()), + ("table2", s1.clone()), + ]); + assert!(ss1 != ss2); + + // union of struct + let ss1 = DataType::union([ + ("table1", s1.clone()), + ("table2", s2.clone()), + ]); + let ss2 = DataType::union([ + ("table1", s1.clone()), + ("table2", s1.clone()), + ]); + assert!(ss1 != ss2); } #[test] @@ -3593,9 +3621,14 @@ mod tests { let union_c = Union::null().or(type_a.clone()).or(type_b.clone()); let union_a = Union::from_field("0", type_a); let union_b = Union::from_field("1", type_b); - println!("a = {}, b = {}, c = {}", &union_a, &union_b, &union_c); + println!("a = {}, b = {}, c = {}\n", &union_a, &union_b, &union_c); assert!(union_a.is_subset_of(&union_c)); assert!(union_b.is_subset_of(&union_c)); + + let union1 = Union::null().or(("a", DataType::float())).or(("b", DataType::float())); + let union2 = Union::null().or(("a", DataType::boolean())).or(("b", DataType::integer())); + assert!(union2.is_subset_of(&union1)); + assert!(! union1.is_subset_of(&union2)); } #[test] From 9f0673eb03074fb8d7bda5cc9b333ca6be18b5e6 Mon Sep 17 00:00:00 2001 From: victoria de sainte agathe Date: Mon, 11 Sep 2023 16:42:53 +0200 Subject: [PATCH 3/7] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d9334e4..9c3aa60d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implemented `least` and `greatest` (support qualified and unqualified columns)[MR102](https://github.com/Qrlew/qrlew/pull/102) ### Fixed - `And` for struct of structs [MR100](https://github.com/Qrlew/qrlew/pull/100) +- `Union::is_subset_of` [MR105](https://github.com/Qrlew/qrlew/pull/105) ### Added - `Hierarchy::get_key_value` [MR103](https://github.com/Qrlew/qrlew/pull/103) From 8eb19cf6321e0a64a9331ba1be0893c3439e127c Mon Sep 17 00:00:00 2001 From: victoria de sainte agathe Date: Mon, 11 Sep 2023 16:44:11 +0200 Subject: [PATCH 4/7] rm comment --- src/data_type/mod.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/data_type/mod.rs b/src/data_type/mod.rs index 2cbdc867..c9b2864c 100644 --- a/src/data_type/mod.rs +++ b/src/data_type/mod.rs @@ -1194,22 +1194,6 @@ impl hash::Hash for Union { } } -// impl PartialEq for Union { -// fn eq(&self, other: &Self) -> bool { -// if self.len() == other.len() { -// self.iter().map(|f| f.0.clone()).sorted() -// .zip(other.iter().map(|f| f.0.clone()).sorted()) -// .all(|(s1, s2)| ( -// s1 == s2 && -// self.field(&s1).map(|f| f.1.as_ref()).unwrap_or(&DataType::Any) == other.field(&s1).map(|f| f.1.as_ref()).unwrap_or(&DataType::Any)) -// ) -// } else { -// false -// } - -// } -// } - /// To ease iteration impl Deref for Union { type Target = [(String, Rc)]; From 482e88c00c5986bf8d3c0a4f6b1fdc1f4c863c93 Mon Sep 17 00:00:00 2001 From: victoria de sainte agathe Date: Mon, 11 Sep 2023 16:45:05 +0200 Subject: [PATCH 5/7] rm useless deps --- src/data_type/mod.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/data_type/mod.rs b/src/data_type/mod.rs index c9b2864c..fb35c49e 100644 --- a/src/data_type/mod.rs +++ b/src/data_type/mod.rs @@ -2959,11 +2959,6 @@ impl<'a> Acceptor<'a> for DataType { #[cfg(test)] mod tests { use std::convert::TryFrom; - - use statrs::statistics::Data; - - use crate::data_type; - use super::*; #[test] From 71592fcd3ce30b1c2103ec98e1e001c8c851436f Mon Sep 17 00:00:00 2001 From: victoria de sainte agathe Date: Mon, 11 Sep 2023 16:45:18 +0200 Subject: [PATCH 6/7] fmt --- src/data_type/mod.rs | 42 ++++++++++++++---------------------------- src/expr/transforms.rs | 2 +- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/data_type/mod.rs b/src/data_type/mod.rs index fb35c49e..4935010c 100644 --- a/src/data_type/mod.rs +++ b/src/data_type/mod.rs @@ -2958,8 +2958,8 @@ impl<'a> Acceptor<'a> for DataType { // TODO Write tests for all types #[cfg(test)] mod tests { - use std::convert::TryFrom; use super::*; + use std::convert::TryFrom; #[test] fn test_null() { @@ -3072,36 +3072,18 @@ mod tests { assert_eq!(DataType::Null, empty_interval); // structs - let s1 = DataType::structured([ - ("a", DataType::float()), - ("b", DataType::float()), - ]); - let s2 = DataType::structured([ - ("a", DataType::boolean()), - ("b", DataType::integer()), - ]); + let s1 = DataType::structured([("a", DataType::float()), ("b", DataType::float())]); + let s2 = DataType::structured([("a", DataType::boolean()), ("b", DataType::integer())]); assert!(s1 != s2); // struct of struct - let ss1 = DataType::structured([ - ("table1", s1.clone()), - ("table2", s2.clone()), - ]); - let ss2 = DataType::structured([ - ("table1", s1.clone()), - ("table2", s1.clone()), - ]); + let ss1 = DataType::structured([("table1", s1.clone()), ("table2", s2.clone())]); + let ss2 = DataType::structured([("table1", s1.clone()), ("table2", s1.clone())]); assert!(ss1 != ss2); // union of struct - let ss1 = DataType::union([ - ("table1", s1.clone()), - ("table2", s2.clone()), - ]); - let ss2 = DataType::union([ - ("table1", s1.clone()), - ("table2", s1.clone()), - ]); + let ss1 = DataType::union([("table1", s1.clone()), ("table2", s2.clone())]); + let ss2 = DataType::union([("table1", s1.clone()), ("table2", s1.clone())]); assert!(ss1 != ss2); } @@ -3604,10 +3586,14 @@ mod tests { assert!(union_a.is_subset_of(&union_c)); assert!(union_b.is_subset_of(&union_c)); - let union1 = Union::null().or(("a", DataType::float())).or(("b", DataType::float())); - let union2 = Union::null().or(("a", DataType::boolean())).or(("b", DataType::integer())); + let union1 = Union::null() + .or(("a", DataType::float())) + .or(("b", DataType::float())); + let union2 = Union::null() + .or(("a", DataType::boolean())) + .or(("b", DataType::integer())); assert!(union2.is_subset_of(&union1)); - assert!(! union1.is_subset_of(&union2)); + assert!(!union1.is_subset_of(&union2)); } #[test] diff --git a/src/expr/transforms.rs b/src/expr/transforms.rs index 8eee4242..04e74493 100644 --- a/src/expr/transforms.rs +++ b/src/expr/transforms.rs @@ -6,7 +6,7 @@ use std::f64::consts::PI; impl Expr { /// Gaussian noise based on [Box Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) - pub fn gaussian_noise() -> Self { + pub fn gaussian_noise() -> Self { Expr::multiply( Expr::sqrt(Expr::multiply( Expr::val(-2.0), From 0b32d719acb56a4655b748c8763916857ff0b365 Mon Sep 17 00:00:00 2001 From: victoria de sainte agathe Date: Mon, 11 Sep 2023 16:50:31 +0200 Subject: [PATCH 7/7] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c3aa60d..abafbe85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- `Union::is_subset_of` [MR106](https://github.com/Qrlew/qrlew/pull/106) ## [0.2.3] - 2023-09-04 ### Changed @@ -15,7 +16,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implemented `least` and `greatest` (support qualified and unqualified columns)[MR102](https://github.com/Qrlew/qrlew/pull/102) ### Fixed - `And` for struct of structs [MR100](https://github.com/Qrlew/qrlew/pull/100) -- `Union::is_subset_of` [MR105](https://github.com/Qrlew/qrlew/pull/105) ### Added - `Hierarchy::get_key_value` [MR103](https://github.com/Qrlew/qrlew/pull/103)