-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: set FlightDescriptor on FlightDataEncoderBuilder #4101
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
Merged
alamb
merged 3 commits into
apache:master
from
Weijun-H:set-FlightDescriptor-on-FlightDataEncoderBuilder
Apr 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
send a separate descriptor message when the descriptor is provided
- Loading branch information
commit c48c00f42777d2e40e78e0ae35e1d1b474d3b5fe
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| use std::{collections::VecDeque, fmt::Debug, pin::Pin, sync::Arc, task::Poll}; | ||
|
|
||
| use crate::{error::Result, FlightData, FlightDescriptor, SchemaAsIpc}; | ||
| use crate::{error::Result, FlightData, FlightDescriptor, IpcMessage, SchemaAsIpc}; | ||
| use arrow_array::{ArrayRef, RecordBatch, RecordBatchOptions}; | ||
| use arrow_ipc::writer::{DictionaryTracker, IpcDataGenerator, IpcWriteOptions}; | ||
| use arrow_schema::{DataType, Field, Fields, Schema, SchemaRef}; | ||
|
|
@@ -173,7 +173,6 @@ impl FlightDataEncoderBuilder { | |
| /// Stream that encodes a stream of record batches to flight data. | ||
| /// | ||
| /// See [`FlightDataEncoderBuilder`] for details and example. | ||
| #[warn(dead_code)] | ||
| pub struct FlightDataEncoder { | ||
| /// Input stream | ||
| inner: BoxStream<'static, Result<RecordBatch>>, | ||
|
|
@@ -211,13 +210,19 @@ impl FlightDataEncoder { | |
| app_metadata: Some(app_metadata), | ||
| queue: VecDeque::new(), | ||
| done: false, | ||
| descriptor, | ||
| 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 { | ||
| encoder.encode_descriptor(&descriptor); | ||
| } | ||
|
|
||
| encoder | ||
| } | ||
|
|
||
|
|
@@ -228,13 +233,7 @@ impl FlightDataEncoder { | |
|
|
||
| /// Place the `FlightData` in the queue to send | ||
| fn queue_messages(&mut self, datas: impl IntoIterator<Item = FlightData>) { | ||
| 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(); | ||
| is_first = !is_first; | ||
| } | ||
| for data in datas { | ||
| self.queue_message(data) | ||
| } | ||
| } | ||
|
|
@@ -257,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()); | ||
|
||
| descriptor | ||
| } | ||
|
|
||
| /// Encodes batch into one or more `FlightData` messages in self.queue | ||
| fn encode_batch(&mut self, batch: RecordBatch) -> Result<()> { | ||
| let schema = match &self.schema { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.descriptorinenqueue_messagesand attach the descriptor there