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

Improve flight sql examples #10432

Merged
merged 3 commits into from May 10, 2024
Merged

Conversation

lewiszlw
Copy link
Contributor

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

@@ -246,27 +276,6 @@ impl FlightSqlService for FlightSqlServiceImpl {
Ok(Response::new(Box::pin(stream)))
}

async fn get_flight_info_statement(
Copy link
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 👍

info!("get_flight_info_schemas");
Err(Status::unimplemented("Implement get_flight_info_schemas"))
}

async fn get_flight_info_tables(
Copy link
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
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
Contributor 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
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
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
23 checks passed
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.

None yet

2 participants