@@ -121,6 +121,60 @@ impl PartitionSpec {
121121 pub fn to_unbound ( self ) -> UnboundPartitionSpec {
122122 self . into ( )
123123 }
124+
125+ /// Check if this partition spec is compatible with another partition spec.
126+ ///
127+ /// Returns true if the partition spec is equal to the other spec with partition field ids ignored and
128+ /// spec_id ignored. The following must be identical:
129+ /// * The number of fields
130+ /// * Field order
131+ /// * Field names
132+ /// * Source column ids
133+ /// * Transforms
134+ pub fn compatible_with ( & self , other : & UnboundPartitionSpec ) -> bool {
135+ if self . fields . len ( ) != other. fields . len ( ) {
136+ return false ;
137+ }
138+
139+ for ( this_field, other_field) in self . fields . iter ( ) . zip ( & other. fields ) {
140+ if this_field. source_id != other_field. source_id
141+ || this_field. transform != other_field. transform
142+ || this_field. name != other_field. name
143+ {
144+ return false ;
145+ }
146+ }
147+
148+ true
149+ }
150+
151+ /// Check if this partition spec has sequential partition ids.
152+ /// Sequential ids start from 1000 and increment by 1 for each field.
153+ /// This is required for spec version
154+ pub fn has_sequential_ids ( & self ) -> bool {
155+ for ( index, field) in self . fields . iter ( ) . enumerate ( ) {
156+ let expected_id = ( UNPARTITIONED_LAST_ASSIGNED_ID as i64 )
157+ . checked_add ( 1 )
158+ . and_then ( |id| id. checked_add ( index as i64 ) )
159+ . unwrap_or ( i64:: MAX ) ;
160+
161+ if field. field_id as i64 != expected_id {
162+ return false ;
163+ }
164+ }
165+
166+ true
167+ }
168+
169+ /// Get the highest field id in the partition spec.
170+ /// If the partition spec is unpartitioned, it returns the last unpartitioned last assigned id (999).
171+ pub fn highest_field_id ( & self ) -> i32 {
172+ self . fields
173+ . iter ( )
174+ . map ( |f| f. field_id )
175+ . max ( )
176+ . unwrap_or ( UNPARTITIONED_LAST_ASSIGNED_ID )
177+ }
124178}
125179
126180/// Reference to [`UnboundPartitionSpec`].
@@ -1263,4 +1317,7 @@ mod tests {
12631317 } ]
12641318 } ) ;
12651319 }
1320+
1321+ #[ test]
1322+ fn test_has_sequential_ids ( ) { }
12661323}
0 commit comments