Skip to content

Conversation

@cj-zhukov
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@cj-zhukov
Copy link
Contributor Author

High-level overview

This PR introduces strum to reduce boilerplate and make the example runner code cleaner and easier to maintain. By deriving enum utilities (parsing, iteration, display, variant names), we eliminate manual argument handling and repetitive match logic, resulting in a more concise and robust implementation for datafusion-examples

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.

Looks good to me -- thank you @cj-zhukov

I ran this script locally and it worked great:

./ci/scripts/rust_example.sh

I also spot checked that the other commands work as before

andrewlamb@Andrews-MacBook-Pro-3:~/Software/datafusion2$ cargo run   --example udf adv_udaf
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
     Running `target/debug/examples/udf adv_udaf`
+---------------+
| geo_mean(t.a) |
+---------------+
| 8.0           |
+---------------+
The geometric mean of [2,4,8,64] is 8
+--------------------------+
| simplified_geo_mean(t.a) |
+--------------------------+
| 8.0                      |
+--------------------------+
The geometric mean of [2,4,8,64] is 8

prost = { workspace = true }
rand = { workspace = true }
serde_json = { workspace = true }
strum = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

these are not net new workspace dependencies (see Cargo.lock file) -- we already have them in the workspace. So I think it is ok to add them here

@alamb
Copy link
Contributor

alamb commented Dec 8, 2025

I also ran taplo format and merged in the results

@alamb
Copy link
Contributor

alamb commented Dec 8, 2025

BTW this PR from @geoffreyclaude adds a few new examples that would also benefit from the strum rewrite treatment:

@alamb
Copy link
Contributor

alamb commented Dec 9, 2025

@cj-zhukov is there any chance you can also apply this pattern to the examples from

I don't think it is necessary / we could do it as a follow on PR, but it would be nice to have all the examples consistent

@cj-zhukov
Copy link
Contributor Author

@cj-zhukov is there any chance you can also apply this pattern to the examples from

* [Add relation planner extension support to customize SQL planning #17843](https://github.com/apache/datafusion/pull/17843)

I don't think it is necessary / we could do it as a follow on PR, but it would be nice to have all the examples consistent

sure, let's do it

@cj-zhukov
Copy link
Contributor Author

@alamb I updated relation_planner examples with strum

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 again @cj-zhukov

ExampleKind::TableSample => table_sample::table_sample().await?,
}
}
let example: ExampleKind = std::env::args()
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 added this pull request to the merge queue Dec 9, 2025
Merged via the queue into apache:main with commit dc6a712 Dec 9, 2025
30 checks passed
@cj-zhukov cj-zhukov deleted the cj-zhukov/use-strum-in-the-examples branch December 10, 2025 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants