You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/04/06 18:46:52 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #4028: Add RecordBatch::with_schema

tustvold opened a new pull request, #4028:
URL: https://github.com/apache/arrow-rs/pull/4028

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   Provides a cheaper way to override the schema of a `RecordBatch` than reconstructing it from parts. Among other things this allows cheaply adding metadata to a `RecordBatch` created from a `StructArray`.
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
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


[GitHub] [arrow-rs] tustvold merged pull request #4028: Add RecordBatch::with_schema

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4028:
URL: https://github.com/apache/arrow-rs/pull/4028


-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4028: Add RecordBatch::with_schema

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4028:
URL: https://github.com/apache/arrow-rs/pull/4028#discussion_r1160168611


##########
arrow-array/src/record_batch.rs:
##########
@@ -204,6 +204,25 @@ impl RecordBatch {
         })
     }
 
+    /// Override the schema of this [`RecordBatch`]
+    ///
+    /// Returns an error if `schema` is not a superset of the current schema
+    /// as determined by [`Schema::contains`]
+    pub fn with_schema(self, schema: SchemaRef) -> Result<Self, ArrowError> {
+        if !schema.contains(self.schema.as_ref()) {
+            return Err(ArrowError::SchemaError(format!(
+                "{schema} is not a superset of {}",
+                self.schema
+            )));
+        }

Review Comment:
   Okay, I see. This is how `Schema.contains` works and documents, though superset implicitly means possibly additional field.



-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4028: Add RecordBatch::with_schema

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4028:
URL: https://github.com/apache/arrow-rs/pull/4028#discussion_r1160157083


##########
arrow-array/src/record_batch.rs:
##########
@@ -204,6 +204,25 @@ impl RecordBatch {
         })
     }
 
+    /// Override the schema of this [`RecordBatch`]
+    ///
+    /// Returns an error if `schema` is not a superset of the current schema
+    /// as determined by [`Schema::contains`]
+    pub fn with_schema(self, schema: SchemaRef) -> Result<Self, ArrowError> {
+        if !schema.contains(self.schema.as_ref()) {
+            return Err(ArrowError::SchemaError(format!(
+                "{schema} is not a superset of {}",
+                self.schema
+            )));
+        }

Review Comment:
   It looks like this is particular used for metadata only? Although looks like you can override the schema with new field (superset?), but this batch doesn't have it.



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4028: Add RecordBatch::with_schema

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4028:
URL: https://github.com/apache/arrow-rs/pull/4028#discussion_r1160162065


##########
arrow-array/src/record_batch.rs:
##########
@@ -204,6 +204,25 @@ impl RecordBatch {
         })
     }
 
+    /// Override the schema of this [`RecordBatch`]
+    ///
+    /// Returns an error if `schema` is not a superset of the current schema
+    /// as determined by [`Schema::contains`]
+    pub fn with_schema(self, schema: SchemaRef) -> Result<Self, ArrowError> {
+        if !schema.contains(self.schema.as_ref()) {
+            return Err(ArrowError::SchemaError(format!(
+                "{schema} is not a superset of {}",
+                self.schema
+            )));
+        }

Review Comment:
   You can make fields nullable, but you can't add additional fields or reorder them



-- 
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