Copilot commented on code in PR #18178:
URL: https://github.com/apache/datafusion/pull/18178#discussion_r2445331508
##########
datafusion/common/src/dfschema.rs:
##########
@@ -1323,6 +1323,51 @@ impl SchemaExt for Schema {
}
}
+/// Helper to hold table schema information.
+///
+/// A table schema consists of:
+/// - file schema: the schema of the data files
+/// - table partition columns: the columns used for partitioning the table
+///
+/// This struct also holds a full table schema to be able to cheaply hand out
+/// references to any one of the representations without needing to
reconstruct them.
+#[derive(Debug, Clone)]
+pub struct TableSchema {
+ file_schema: SchemaRef,
+ table_partition_cols: Vec<FieldRef>,
+ table_schema: SchemaRef,
+}
+
+impl TableSchema {
+ /// Create a new TableSchema
+ pub fn new(file_schema: SchemaRef, table_partition_cols: Vec<FieldRef>) ->
Self {
+ let mut builder = SchemaBuilder::from(file_schema.as_ref());
+ for field in &table_partition_cols {
+ builder.push(Arc::clone(field));
+ }
+ Self {
+ file_schema,
+ table_partition_cols,
+ table_schema: Arc::new(builder.finish()),
+ }
+ }
Review Comment:
The loop cloning Arc fields could be simplified using `builder.extend()`
which accepts an iterator. Replace lines 1344-1346 with
`builder.extend(table_partition_cols.iter().cloned());` for clearer code.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]