You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Weijun-H (via GitHub)" <gi...@apache.org> on 2023/04/19 22:31:48 UTC

[GitHub] [arrow-rs] Weijun-H opened a new pull request, #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

Weijun-H opened a new pull request, #4101:
URL: https://github.com/apache/arrow-rs/pull/4101

   # 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 #3855
   
   # 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.
   -->
   
   # 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] alamb merged pull request #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


-- 
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 #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


##########
arrow-flight/src/encode.rs:
##########
@@ -153,13 +165,15 @@ impl FlightDataEncoderBuilder {
             max_flight_data_size,
             options,
             app_metadata,
+            descriptor,
         )
     }
 }
 
 /// Stream that encodes a stream of record batches to flight data.
 ///
 /// See [`FlightDataEncoderBuilder`] for details and example.
+#[warn(dead_code)]

Review Comment:
   Why this change?



-- 
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] alamb commented on a diff in pull request #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


##########
arrow-flight/src/encode.rs:
##########
@@ -134,6 +137,14 @@ impl FlightDataEncoderBuilder {
         self
     }
 
+    pub fn with_flight_descriptor(

Review Comment:
   Can you please add doc strings to explain how this function works, to keep in line with the rest of the functions on this struct?
   
   Specifically that it is sent on the first FlightData as described in https://arrow.apache.org/docs/format/Flight.html#uploading-data



##########
arrow-flight/src/encode.rs:
##########
@@ -233,6 +256,24 @@ impl FlightDataEncoder {
         schema
     }
 
+    /// Encodes descriptor as a [`FlightData`] in self.queue.
+    /// Updates `self.descriptor` and returns the new descriptor
+    fn encode_descriptor(&mut self, descriptor: &FlightDescriptor) -> FlightDescriptor {
+        // The first message is the descriptor message, and all
+        // batches have the same descriptor
+        let descriptor = descriptor.clone();
+        let descriptor_flight_data = FlightData::new(
+            Some(descriptor.clone()),
+            IpcMessage(Bytes::new()),
+            vec![],
+            vec![],
+        );
+        self.queue_message(descriptor_flight_data);
+        // remember descriptor
+        self.descriptor = Some(descriptor.clone());

Review Comment:
   Why is the descriptor remembered?



##########
arrow-flight/src/encode.rs:
##########
@@ -194,12 +210,19 @@ impl FlightDataEncoder {
             app_metadata: Some(app_metadata),
             queue: VecDeque::new(),
             done: false,
+            descriptor: None,
         };
 
         // If schema is known up front, enqueue it immediately
         if let Some(schema) = schema {
             encoder.encode_schema(&schema);
         }
+
+        // If descriptor is known up front, enqueue it immediately
+        if let Some(descriptor) = descriptor {

Review Comment:
   As I understand the intent, the idea is that the descriptor is set on the first message that is sent this code will potentially send a separate message after the schema message, if the schema is known up front.
   
   Perhaps you could check  `self.descriptor` in `enqueue_messages` and attach the descriptor there



##########
arrow-flight/src/encode.rs:
##########
@@ -176,6 +189,8 @@ pub struct FlightDataEncoder {
     queue: VecDeque<FlightData>,
     /// Is this stream done (inner is empty or errored)
     done: bool,
+    /// descriptor, set after the first batch

Review Comment:
   What does "set after the first batch" mean? 
   
   I guess I expect this to be something more like "cleared after the first FlightData message"



-- 
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] alamb commented on a diff in pull request #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


##########
arrow-flight/src/encode.rs:
##########
@@ -134,6 +137,14 @@ impl FlightDataEncoderBuilder {
         self
     }
 
+    pub fn with_flight_descriptor(

Review Comment:
   If the encoder would not have sent any `FlightData` if no `FlightDescriptor` is provided, then I don't think a `FlightData` should be sent if a `FlightDescriptor` is sent)



-- 
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 #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


##########
arrow-flight/src/encode.rs:
##########
@@ -210,7 +228,13 @@ impl FlightDataEncoder {
 
     /// Place the `FlightData` in the queue to send
     fn queue_messages(&mut self, datas: impl IntoIterator<Item = FlightData>) {
-        for data in datas {
+        let mut is_first = true;
+        for mut data in datas {
+            // The first message is the schema message need to set the descriptor
+            if is_first {
+                data.flight_descriptor = self.descriptor.clone();

Review Comment:
   I think the ticket calls for sending a separate descriptor message, not overriding the first message



-- 
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] Weijun-H commented on a diff in pull request #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


##########
arrow-flight/src/encode.rs:
##########
@@ -134,6 +137,14 @@ impl FlightDataEncoderBuilder {
         self
     }
 
+    pub fn with_flight_descriptor(

Review Comment:
   I am not sure if the data is empty, should we also need to send a seperate empty FligtData with the descriptor.



-- 
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] alamb commented on a diff in pull request #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


##########
arrow-flight/src/encode.rs:
##########
@@ -194,17 +211,28 @@ impl FlightDataEncoder {
             app_metadata: Some(app_metadata),
             queue: VecDeque::new(),
             done: false,
+            descriptor: None,
         };
 
         // If schema is known up front, enqueue it immediately
         if let Some(schema) = schema {
             encoder.encode_schema(&schema);
         }
+
+        encoder.descriptor = descriptor;

Review Comment:
   I think this should be set before calling `encoder.encode_schema()` so it is included on the first Schema message, if provided



##########
arrow-flight/tests/encode_decode.rs:
##########
@@ -136,6 +138,31 @@ async fn test_zero_batches_schema_specified() {
     assert_eq!(decoder.schema(), Some(&schema));
 }
 
+#[tokio::test]
+async fn test_with_flight_descriptor() {
+    let stream = futures::stream::iter(vec![Ok(make_dictionary_batch(5))]);
+    let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Utf8, true)]));
+
+    let descriptor = Some(FlightDescriptor {
+        r#type: DescriptorType::Path.into(),
+        path: vec!["table_name".to_string()],
+        cmd: Bytes::default(),
+    });
+
+    let encoder = FlightDataEncoderBuilder::default()
+        .with_schema(schema.clone())
+        .with_flight_descriptor(descriptor.clone());
+
+    let mut encoder = encoder.build(stream);
+
+    // First batch should be the schema
+    encoder.next().await.unwrap().unwrap();

Review Comment:
   My understanding of https://arrow.apache.org/docs/format/Flight.html#uploading-data was that the first `FlightData` should have the `descriptor`, not the second 🤔 



##########
arrow-flight/src/encode.rs:
##########
@@ -194,17 +211,28 @@ impl FlightDataEncoder {
             app_metadata: Some(app_metadata),
             queue: VecDeque::new(),
             done: false,
+            descriptor: None,
         };
 
         // If schema is known up front, enqueue it immediately
         if let Some(schema) = schema {
             encoder.encode_schema(&schema);
         }
+
+        encoder.descriptor = descriptor;
+
         encoder
     }
 
     /// Place the `FlightData` in the queue to send
     fn queue_message(&mut self, data: FlightData) {
+        if let Some(descriptor) = &self.descriptor {
+            let mut data = data;
+            data.flight_descriptor = Some(descriptor.clone());
+            self.descriptor = None;
+            self.queue.push_back(data);
+            return;
+        }
         self.queue.push_back(data);
     }

Review Comment:
   FWIW I think you can write this using `take()` a bit more concisely like:
   
   ```suggestion
       fn queue_message(&mut self, mut data: FlightData) {
           if let Some(descriptor) = self.descriptor.take() {
               data.flight_descriptor = Some(descriptor.clone());
           }
           self.queue.push_back(data);
       }
   ```



-- 
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] Weijun-H commented on a diff in pull request #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

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


##########
arrow-flight/tests/encode_decode.rs:
##########
@@ -136,6 +138,31 @@ async fn test_zero_batches_schema_specified() {
     assert_eq!(decoder.schema(), Some(&schema));
 }
 
+#[tokio::test]
+async fn test_with_flight_descriptor() {
+    let stream = futures::stream::iter(vec![Ok(make_dictionary_batch(5))]);
+    let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Utf8, true)]));
+
+    let descriptor = Some(FlightDescriptor {
+        r#type: DescriptorType::Path.into(),
+        path: vec!["table_name".to_string()],
+        cmd: Bytes::default(),
+    });
+
+    let encoder = FlightDataEncoderBuilder::default()
+        .with_schema(schema.clone())
+        .with_flight_descriptor(descriptor.clone());
+
+    let mut encoder = encoder.build(stream);
+
+    // First batch should be the schema
+    encoder.next().await.unwrap().unwrap();

Review Comment:
   Yes, you are right. I completely misunderstood 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] Weijun-H commented on pull request #4101: feat: set FlightDescriptor on FlightDataEncoderBuilder

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on PR #4101:
URL: https://github.com/apache/arrow-rs/pull/4101#issuecomment-1516947960

   Error happened, but not by my pr
   ```
   Run cargo fmt --all -- --check
   Diff in /__w/arrow-rs/arrow-rs/arrow-string/src/like.rs at line 1244:
                "ffkoß",
                "😃sadlksFFkoSSsh😃klF", // Original was case insensitive "😃sadlksffkosSsh😃klF"
                "😱slgFFkoSSsh😃klF",    // Original was case insensitive "😱slgffkosSsh😃klF"
   -            "FFkoSS",                    // "FFKoSS"
   +            "FFkoSS",                // "FFKoSS"
            ],
            "FFkoSS",
            contains_utf[8](https://github.com/apache/arrow-rs/actions/runs/4758784682/jobs/8457275692?pr=4101#step:6:9)_scalar,
   ```


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