Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema-level metadata is not encoded in Flight responses #3779

Closed
stuartcarnie opened this issue Feb 28, 2023 · 3 comments · Fixed by #3811
Closed

Schema-level metadata is not encoded in Flight responses #3779

stuartcarnie opened this issue Feb 28, 2023 · 3 comments · Fixed by #3811
Assignees
Labels
arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate bug

Comments

@stuartcarnie
Copy link
Contributor

Describe the bug

When preparing schema for encoding into a Flight response, the schema-level metadata from the source schema is dropped:

Schema::new(fields)

To Reproduce

Index: arrow-flight/src/encode.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/arrow-flight/src/encode.rs b/arrow-flight/src/encode.rs
--- a/arrow-flight/src/encode.rs	(revision e7eb304dac442a943c434f8ea248de909f82aa88)
+++ b/arrow-flight/src/encode.rs	(date 1677611826249)
@@ -453,6 +453,7 @@
 
 #[cfg(test)]
 mod tests {
+    use std::collections::HashMap;
     use arrow::{
         array::{UInt32Array, UInt8Array},
         compute::concat_batches,
@@ -502,6 +503,16 @@
         );
     }
 
+    #[test]
+    fn test_schema_metadata_encoded() {
+        let schema = Schema::new(vec![
+            Field::new("data", DataType::Int32, false),
+        ]).with_metadata(HashMap::from([("some_key".to_owned(), "some_value".to_owned())]));
+
+        let got = prepare_schema_for_flight(&schema);
+        assert!(got.metadata().contains_key("some_key"));
+    }
+
     #[test]
     fn test_encode_no_column_batch() {
         let batch = RecordBatch::try_new_with_options(

Expected behavior

Schema-level metadata should be included permitting test to pass.

Additional context

@stuartcarnie
Copy link
Contributor Author

@alamb I can confirm that with this patch:

Index: arrow-flight/src/encode.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/arrow-flight/src/encode.rs b/arrow-flight/src/encode.rs
--- a/arrow-flight/src/encode.rs	(revision bbc1469077e13ba2e5a61f130917ad7eccfcb569)
+++ b/arrow-flight/src/encode.rs	(date 1677712010122)
@@ -323,7 +323,7 @@
         })
         .collect();
 
-    Schema::new(fields)
+    Schema::new(fields).with_metadata(schema.metadata().clone())
 }
 
 /// Split [`RecordBatch`] so it hopefully fits into a gRPC response.
@@ -453,6 +453,7 @@
 
 #[cfg(test)]
 mod tests {
+    use std::collections::HashMap;
     use arrow::{
         array::{UInt32Array, UInt8Array},
         compute::concat_batches,
@@ -502,6 +503,16 @@
         );
     }
 
+    #[test]
+    fn test_schema_metadata_encoded() {
+        let schema = Schema::new(vec![
+            Field::new("data", DataType::Int32, false),
+        ]).with_metadata(HashMap::from([("some_key".to_owned(), "some_value".to_owned())]));
+
+        let got = prepare_schema_for_flight(&schema);
+        assert!(got.metadata().contains_key("some_key"));
+    }
+
     #[test]
     fn test_encode_no_column_batch() {
         let batch = RecordBatch::try_new_with_options(

and minor fixes in IOx, the schema metadata propagates across RPC requests

stuartcarnie added a commit to stuartcarnie/arrow-rs that referenced this issue Mar 7, 2023
tustvold pushed a commit that referenced this issue Mar 8, 2023
* fix: Ensure prepared schema includes parent metadata

Closes #3779

* Add a test and run fmt

---------

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@tustvold tustvold added the arrow Changes to the arrow crate label Mar 10, 2023
@tustvold
Copy link
Contributor

label_issue.py automatically added labels {'arrow'} from #3811

@tustvold tustvold added the arrow-flight Changes to the arrow-flight crate label Mar 10, 2023
@tustvold
Copy link
Contributor

label_issue.py automatically added labels {'arrow-flight'} from #3811

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants