@@ -85,6 +85,11 @@ impl TableSchema {
8585 /// The table schema is automatically computed by appending the partition columns
8686 /// to the file schema.
8787 ///
88+ /// You should prefer calling this method over
89+ /// chaining [`TableSchema::new_from_file_schema`] and [`TableSchema::with_partition_cols`]
90+ /// if you have both the file schema and partition columns available at construction time
91+ /// since it avoids re-computing the table schema.
92+ ///
8893 /// # Arguments
8994 ///
9095 /// * `file_schema` - Schema of the data files (without partition columns)
@@ -121,6 +126,27 @@ impl TableSchema {
121126 }
122127 }
123128
129+ /// Create a new TableSchema with no partition columns.
130+ ///
131+ /// You should prefer calling [`TableSchema::new`] if you have partition columns at
132+ /// construction time since it avoids re-computing the table schema.
133+ pub fn new_from_file_schema ( file_schema : SchemaRef ) -> Self {
134+ Self :: new ( file_schema, vec ! [ ] )
135+ }
136+
137+ /// Add partition columns to an existing TableSchema, returning a new instance.
138+ ///
139+ /// You should prefer calling [`TableSchema::new`] instead of chaining [`TableSchema::new_from_file_schema`]
140+ /// into [`TableSchema::with_partition_cols`] if you have partition columns at construction time
141+ /// since it avoids re-computing the table schema.
142+ pub fn with_partition_cols ( mut self , partition_cols : Vec < FieldRef > ) -> Self {
143+ self . table_partition_cols = partition_cols;
144+ let mut builder = SchemaBuilder :: from ( self . file_schema . as_ref ( ) ) ;
145+ builder. extend ( self . table_partition_cols . iter ( ) . cloned ( ) ) ;
146+ self . table_schema = Arc :: new ( builder. finish ( ) ) ;
147+ self
148+ }
149+
124150 /// Get the file schema (without partition columns).
125151 ///
126152 /// This is the schema of the actual data files on disk.
0 commit comments