@@ -36,35 +36,31 @@ pub enum Constraint {
3636}
3737
3838/// This object encapsulates a list of functional constraints:
39- #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Hash ) ]
39+ #[ derive( Clone , Debug , Default , Eq , Hash , PartialEq , PartialOrd ) ]
4040pub struct Constraints {
4141 inner : Vec < Constraint > ,
4242}
4343
4444impl Constraints {
45- /// Create empty constraints
46- pub fn empty ( ) -> Self {
47- Constraints :: new_unverified ( vec ! [ ] )
48- }
49-
5045 /// Create a new [`Constraints`] object from the given `constraints`.
51- /// Users should use the [`Constraints::empty`] or [`SqlToRel::new_constraint_from_table_constraints`] functions
52- /// for constructing [`Constraints`]. This constructor is for internal
53- /// purposes only and does not check whether the argument is valid. The user
54- /// is responsible for supplying a valid vector of [`Constraint`] objects.
46+ /// Users should use the [`Constraints::default`] or [`SqlToRel::new_constraint_from_table_constraints`]
47+ /// functions for constructing [`Constraints`] instances. This constructor
48+ /// is for internal purposes only and does not check whether the argument
49+ /// is valid. The user is responsible for supplying a valid vector of
50+ /// [`Constraint`] objects.
5551 ///
5652 /// [`SqlToRel::new_constraint_from_table_constraints`]: https://docs.rs/datafusion/latest/datafusion/sql/planner/struct.SqlToRel.html#method.new_constraint_from_table_constraints
5753 pub fn new_unverified ( constraints : Vec < Constraint > ) -> Self {
5854 Self { inner : constraints }
5955 }
6056
61- /// Check whether constraints is empty
62- pub fn is_empty ( & self ) -> bool {
63- self . inner . is_empty ( )
57+ /// Extends the current constraints with the given `other` constraints.
58+ pub fn extend ( & mut self , other : Constraints ) {
59+ self . inner . extend ( other . inner ) ;
6460 }
6561
66- /// Projects constraints using the given projection indices.
67- /// Returns None if any of the constraint columns are not included in the projection.
62+ /// Projects constraints using the given projection indices. Returns `None`
63+ /// if any of the constraint columns are not included in the projection.
6864 pub fn project ( & self , proj_indices : & [ usize ] ) -> Option < Self > {
6965 let projected = self
7066 . inner
@@ -74,14 +70,14 @@ impl Constraints {
7470 Constraint :: PrimaryKey ( indices) => {
7571 let new_indices =
7672 update_elements_with_matching_indices ( indices, proj_indices) ;
77- // Only keep constraint if all columns are preserved
73+ // Only keep the constraint if all columns are preserved:
7874 ( new_indices. len ( ) == indices. len ( ) )
7975 . then_some ( Constraint :: PrimaryKey ( new_indices) )
8076 }
8177 Constraint :: Unique ( indices) => {
8278 let new_indices =
8379 update_elements_with_matching_indices ( indices, proj_indices) ;
84- // Only keep constraint if all columns are preserved
80+ // Only keep the constraint if all columns are preserved:
8581 ( new_indices. len ( ) == indices. len ( ) )
8682 . then_some ( Constraint :: Unique ( new_indices) )
8783 }
@@ -93,15 +89,9 @@ impl Constraints {
9389 }
9490}
9591
96- impl Default for Constraints {
97- fn default ( ) -> Self {
98- Constraints :: empty ( )
99- }
100- }
101-
10292impl IntoIterator for Constraints {
10393 type Item = Constraint ;
104- type IntoIter = IntoIter < Constraint > ;
94+ type IntoIter = IntoIter < Self :: Item > ;
10595
10696 fn into_iter ( self ) -> Self :: IntoIter {
10797 self . inner . into_iter ( )
0 commit comments