@@ -155,29 +155,13 @@ impl ExecutionPlan for ArrowFlightReadExec {
155155 let channel_resolver = get_distributed_channel_resolver ( context. session_config ( ) ) ?;
156156
157157 // the `ArrowFlightReadExec` node can only be executed in the context of a `StageExec`
158- let stage = context
159- . session_config ( )
160- . get_extension :: < StageExec > ( )
161- . ok_or ( internal_datafusion_err ! (
162- "ArrowFlightReadExec requires an ExecutionStage in the session config"
163- ) ) ?;
158+ let stage = StageExec :: from_ctx ( & context) ?;
164159
165160 // of our child stages find the one that matches the one we are supposed to be
166161 // reading from
167- let child_stage = stage
168- . child_stages_iter ( )
169- . find ( |s| s. num == self_ready. stage_num )
170- . ok_or ( internal_datafusion_err ! (
171- "ArrowFlightReadExec: no child stage with num {}" ,
172- self_ready. stage_num
173- ) ) ?;
174-
175- let flight_metadata = context
176- . session_config ( )
177- . get_extension :: < ContextGrpcMetadata > ( ) ;
162+ let child_stage = stage. child_stage ( self_ready. stage_num ) ?;
178163
179164 let codec = DistributedCodec :: new_combined_with_user ( context. session_config ( ) ) ;
180-
181165 let child_stage_proto = proto_from_stage ( child_stage, & codec) . map_err ( |e| {
182166 internal_datafusion_err ! ( "ArrowFlightReadExec: failed to convert stage to proto: {e}" )
183167 } ) ?;
@@ -186,16 +170,13 @@ impl ExecutionPlan for ArrowFlightReadExec {
186170 let child_stage_num = child_stage. num as u64 ;
187171 let query_id = stage. query_id . to_string ( ) ;
188172
189- let context_headers = flight_metadata
190- . as_ref ( )
191- . map ( |v| v. as_ref ( ) . clone ( ) )
192- . unwrap_or_default ( ) ;
173+ let context_headers = ContextGrpcMetadata :: headers_from_ctx ( & context) ;
193174
194175 let stream = child_stage_tasks. into_iter ( ) . enumerate ( ) . map ( |( i, task) | {
195176 let channel_resolver = Arc :: clone ( & channel_resolver) ;
196177
197178 let ticket = Request :: from_parts (
198- MetadataMap :: from_headers ( context_headers. 0 . clone ( ) ) ,
179+ MetadataMap :: from_headers ( context_headers. clone ( ) ) ,
199180 Extensions :: default ( ) ,
200181 Ticket {
201182 ticket : DoGet {
0 commit comments