Skip to content

Improve flight sql examples#10432

Merged
alamb merged 3 commits intoapache:mainfrom
lewiszlw:improve-flight-examples
May 10, 2024
Merged

Improve flight sql examples#10432
alamb merged 3 commits intoapache:mainfrom
lewiszlw:improve-flight-examples

Conversation

@lewiszlw
Copy link
Copy Markdown
Member

@lewiszlw lewiszlw commented May 9, 2024

Which issue does this PR close?

Implement get_flight_info_tables and remove unimplemented methods.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

image

Are there any user-facing changes?

@github-actions github-actions bot added the logical-expr Logical plan and expressions label May 9, 2024
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @lewiszlw -- this looks really nice to me

Ok(Response::new(Box::pin(stream)))
}

async fn get_flight_info_statement(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this code means it falls back to the default implementation (which also returns Not implemented)

Seems like a nice change to me 👍

Err(Status::unimplemented("Implement get_flight_info_schemas"))
}

async fn get_flight_info_tables(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let fetch = FetchResults { handle: uuid };
let buf = fetch.as_any().encode_to_vec().into();
let ticket = Ticket { ticket: buf };
let endpoint = FlightEndpoint {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think you can make this code simpler using FlightInfo::new() as shown on the examples in https://docs.rs/arrow-flight/latest/arrow_flight/struct.FlightInfo.html

// Create a new FlightInfo
let flight_info = FlightInfo::new()
  // Encode the Arrow schema
  .try_with_schema(&schema))
  .expect("encoding failed")
  .with_endpoint(
     FlightEndpoint::new()
       .with_ticket(ticket)
     )
   )
  .with_descriptor(FlightDescriptor::new_cmd(Default::default()));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!
.with_descriptor(FlightDescriptor::new_cmd(Default::default())) can not be compiled due to

cannot infer type for type parameter `impl Into<Bytes>` declared on the associated function `new_cmd`

So I changed to

        let info = FlightInfo::new()
            // Encode the Arrow schema
            .try_with_schema(&schema)
            .expect("encoding failed")
            .with_endpoint(FlightEndpoint::new().with_ticket(ticket))
            .with_descriptor(FlightDescriptor {
                r#type: DescriptorType::Cmd.into(),
                cmd: Default::default(),
                path: vec![],
            });

Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks agian @lewiszlw

Err(Status::unimplemented(
"Implement do_put_prepared_statement_query",
))
let info = FlightInfo::new()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

@alamb alamb merged commit fe89d0b into apache:main May 10, 2024
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* Implement get_flight_info_tables

* remove unimplemented methods

* Simplify FlightInfo construction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants