martin-g commented on code in PR #18946:
URL: https://github.com/apache/datafusion/pull/18946#discussion_r2567476581
##########
datafusion-examples/examples/proto/main.rs:
##########
@@ -50,19 +53,35 @@ impl FromStr for ExampleKind {
fn from_str(s: &str) -> Result<Self> {
match s {
+ "all" => Ok(Self::All),
"composed_extension_codec" => Ok(Self::ComposedExtensionCodec),
_ => Err(DataFusionError::Execution(format!("Unknown example:
{s}"))),
}
}
}
impl ExampleKind {
- const ALL: [Self; 1] = [Self::ComposedExtensionCodec];
+ const ALL_VARIANTS: [Self; 2] = [Self::All, Self::ComposedExtensionCodec];
+
+ const RUNNABLE_VARIANTS: [Self; 1] = [Self::ComposedExtensionCodec];
const EXAMPLE_NAME: &str = "proto";
fn variants() -> Vec<&'static str> {
- Self::ALL.iter().map(|x| x.as_ref()).collect()
+ Self::ALL_VARIANTS
+ .iter()
+ .map(|example| example.as_ref())
+ .collect()
+ }
+
+ async fn run(&self) -> Result<()> {
+ match self {
+ ExampleKind::ComposedExtensionCodec => {
+ composed_extension_codec::composed_extension_codec().await?
+ }
+ ExampleKind::All => unreachable!("`All` should be handled in
main"),
Review Comment:
I'd move the logic from line
https://github.com/apache/datafusion/pull/18946/files/60c2a9e6a991efde6b04fc14ef88dc64d7fc632b#diff-8e66baa781bf741371e4d4011550f74c14490472cd2191fe305a0313e1da9231R102
to run(). This way there won't be a need of panicking/returning errors at all.
I.e. just call `example.run()` and handle all possible variants, including
ALL, inside run(). ALL will iterate over the variants and call .run()
recursively.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]