You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/06 12:07:43 UTC

[GitHub] [arrow-datafusion] alamb commented on a change in pull request #1914: add metadata to DFSchema, close #1806.

alamb commented on a change in pull request #1914:
URL: https://github.com/apache/arrow-datafusion/pull/1914#discussion_r820224374



##########
File path: datafusion-common/src/dfschema.rs
##########
@@ -36,16 +36,30 @@ pub type DFSchemaRef = Arc<DFSchema>;
 pub struct DFSchema {
     /// Fields
     fields: Vec<DFField>,
+    /// Additional metadata in form of key value pairs
+    metadata: HashMap<String, String>,
 }
 
 impl DFSchema {
     /// Creates an empty `DFSchema`
     pub fn empty() -> Self {
-        Self { fields: vec![] }
+        Self {
+            fields: vec![],
+            metadata: HashMap::new(),
+        }
     }
 
+    #[deprecated(since = "7.0.0", note = "please use `new_with_metadata` instead")]
     /// Create a new `DFSchema`
     pub fn new(fields: Vec<DFField>) -> Result<Self> {
+        Self::new_with_metadata(fields, HashMap::new())
+    }
+
+    /// Create a new `DFSchema`
+    pub fn new_with_metadata(

Review comment:
       What would you think about a more "builder-like" API here that perhaps could remain backwards compatible. 
   
   Something like:
   
   ```rust
   /// Sets the metadata on this DFSchema to `metadata`
   pub fn with_metadata(mut self, metadata: HashMap<String, String>) -> Self {
   ...
   }
   ```
   
   
   And then instead of code like
   
   ```rust
           Schema::new_with_metadata(
               df_schema.fields.iter().map(|f| f.field.clone()).collect(),
               df_schema.metadata.clone(),
           )
   ```
   
   It would look like
   ```rust
           Schema::new(
               df_schema.fields.iter().map(|f| f.field.clone()).collect(),
           )
           .with_metadata(df_schema.metadata.clone()),
   ```




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org