You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "cj-zhukov (via GitHub)" <gi...@apache.org> on 2025/11/21 06:27:06 UTC
[PR] Consolidate dataframe examples (#18142) [datafusion]
cj-zhukov opened a new pull request, #18862:
URL: https://github.com/apache/datafusion/pull/18862
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- part of #https://github.com/apache/datafusion/issues/18142.
## Rationale for this change
This PR is for consolidating all the `dataframe` examples (dataframe, default_column_values, deserialize_to_struct) into a single example binary. We are agreed on the pattern and we can apply it to the remaining examples
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#discussion_r2553120326
##########
datafusion-examples/examples/dataframe/main.rs:
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! # These are core DataFrame API usage
+//!
+//! These examples demonstrate core DataFrame API usage.
+//!
+//! ## Usage
+//! ```bash
+//! cargo run --example dataframe -- [dataframe|default_column_values|deserialize_to_struct]
+//! ```
+//!
+//! Each subcommand runs a corresponding example:
+//! - `dataframe` — run a query using a DataFrame API against parquet files, csv files, and in-memory data, including multiple subqueries
+//! - `default_column_values` — implement custom default value handling for missing columns using field metadata and PhysicalExprAdapter
+//! - `deserialize_to_struct` — convert query results (Arrow ArrayRefs) into Rust structs
+
+mod dataframe;
+mod default_column_values;
+mod deserialize_to_struct;
+
+use std::str::FromStr;
+
+use datafusion::error::{DataFusionError, Result};
+
+enum ExampleKind {
+ Dataframe,
+ DefaultColumnValues,
+ DeserializeToStruct,
+}
+
+impl AsRef<str> for ExampleKind {
+ fn as_ref(&self) -> &str {
+ match self {
+ Self::Dataframe => "dataframe",
+ Self::DefaultColumnValues => "default_column_values",
+ Self::DeserializeToStruct => "deserialize_to_struct",
+ }
+ }
+}
+
+impl FromStr for ExampleKind {
+ type Err = DataFusionError;
+
+ fn from_str(s: &str) -> Result<Self> {
+ match s {
+ "dataframe" => Ok(Self::Dataframe),
+ "default_column_values" => Ok(Self::DefaultColumnValues),
+ "deserialize_to_struct" => Ok(Self::DeserializeToStruct),
+ _ => Err(DataFusionError::Execution(format!("Unknown example: {s}"))),
+ }
+ }
+}
+
+impl ExampleKind {
+ const ALL: [Self; 3] = [
+ Self::Dataframe,
+ Self::DefaultColumnValues,
+ Self::DeserializeToStruct,
+ ];
+
+ const EXAMPLE_NAME: &str = "dataframe";
+
+ fn variants() -> Vec<&'static str> {
+ Self::ALL.iter().map(|x| x.as_ref()).collect()
+ }
+}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let usage = format!(
+ "Usage: cargo run --example {} -- [{}]",
+ ExampleKind::EXAMPLE_NAME,
+ ExampleKind::variants().join("|")
Review Comment:
I think I just missed the options in my haste. Maybe we can improve the formatting for these errors as some follow on PR
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#discussion_r2550886143
##########
datafusion-examples/examples/dataframe/main.rs:
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! # These are core DataFrame API usage
+//!
+//! These examples demonstrate core DataFrame API usage.
+//!
+//! ## Usage
+//! ```bash
+//! cargo run --example dataframe -- [dataframe|default_column_values|deserialize_to_struct]
+//! ```
+//!
+//! Each subcommand runs a corresponding example:
+//! - `dataframe` — run a query using a DataFrame API against parquet files, csv files, and in-memory data, including multiple subqueries
+//! - `default_column_values` — implement custom default value handling for missing columns using field metadata and PhysicalExprAdapter
+//! - `deserialize_to_struct` — convert query results (Arrow ArrayRefs) into Rust structs
+
+mod dataframe;
+mod default_column_values;
+mod deserialize_to_struct;
+
+use std::str::FromStr;
+
+use datafusion::error::{DataFusionError, Result};
+
+enum ExampleKind {
+ Dataframe,
+ DefaultColumnValues,
+ DeserializeToStruct,
+}
+
+impl AsRef<str> for ExampleKind {
+ fn as_ref(&self) -> &str {
+ match self {
+ Self::Dataframe => "dataframe",
+ Self::DefaultColumnValues => "default_column_values",
+ Self::DeserializeToStruct => "deserialize_to_struct",
+ }
+ }
+}
+
+impl FromStr for ExampleKind {
+ type Err = DataFusionError;
+
+ fn from_str(s: &str) -> Result<Self> {
+ match s {
+ "dataframe" => Ok(Self::Dataframe),
+ "default_column_values" => Ok(Self::DefaultColumnValues),
+ "deserialize_to_struct" => Ok(Self::DeserializeToStruct),
+ _ => Err(DataFusionError::Execution(format!("Unknown example: {s}"))),
+ }
+ }
+}
+
+impl ExampleKind {
+ const ALL: [Self; 3] = [
+ Self::Dataframe,
+ Self::DefaultColumnValues,
+ Self::DeserializeToStruct,
+ ];
+
+ const EXAMPLE_NAME: &str = "dataframe";
+
+ fn variants() -> Vec<&'static str> {
+ Self::ALL.iter().map(|x| x.as_ref()).collect()
+ }
+}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let usage = format!(
+ "Usage: cargo run --example {} -- [{}]",
+ ExampleKind::EXAMPLE_NAME,
+ ExampleKind::variants().join("|")
Review Comment:
BTW for some reason
```shell
cargo run --example dataframe
```
doesn't show me the valid options, it only tells me the argument is missing 🤔
```
Usage: cargo run --example dataframe -- [dataframe|default_column_values|deserialize_to_struct]
Error: Execution("Missing argument")
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "cj-zhukov (via GitHub)" <gi...@apache.org>.
cj-zhukov commented on code in PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#discussion_r2552263952
##########
datafusion-examples/examples/dataframe/default_column_values.rs:
##########
@@ -52,25 +54,23 @@ use object_store::{ObjectStore, PutPayload};
// Metadata key for storing default values in field metadata
const DEFAULT_VALUE_METADATA_KEY: &str = "example.default_value";
-// Example showing how to implement custom default value handling for missing columns
-// using field metadata and PhysicalExprAdapter.
-//
-// This example demonstrates how to:
-// 1. Store default values in field metadata using a constant key
-// 2. Create a custom PhysicalExprAdapter that reads these defaults
-// 3. Inject default values for missing columns in filter predicates
-// 4. Use the DefaultPhysicalExprAdapter as a fallback for standard schema adaptation
-// 5. Wrap string default values in cast expressions for proper type conversion
-//
-// Important: PhysicalExprAdapter is specifically designed for rewriting filter predicates
-// that get pushed down to file scans. For handling missing columns in projections,
-// other mechanisms in DataFusion are used (like SchemaAdapter).
-//
-// The metadata-based approach provides a flexible way to store default values as strings
-// and cast them to the appropriate types at query time.
-
-#[tokio::main]
-async fn main() -> Result<()> {
+/// Example showing how to implement custom default value handling for missing columns
+/// using field metadata and PhysicalExprAdapter.
+///
+/// This example demonstrates how to:
+/// 1. Store default values in field metadata using a constant key
+/// 2. Create a custom PhysicalExprAdapter that reads these defaults
+/// 3. Inject default values for missing columns in filter predicates
+/// 4. Use the DefaultPhysicalExprAdapter as a fallback for standard schema adaptation
+/// 5. Wrap string default values in cast expressions for proper type conversion
+///
+/// Important: PhysicalExprAdapter is specifically designed for rewriting filter predicates
+/// that get pushed down to file scans. For handling missing columns in projections,
+/// other mechanisms in DataFusion are used (like SchemaAdapter).
+///
+/// The metadata-based approach provides a flexible way to store default values as strings
+/// and cast them to the appropriate types at query time.
+pub async fn default_column_values() -> Result<()> {
Review Comment:
Agree with you, let's move the example
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#discussion_r2551142640
##########
datafusion-examples/examples/dataframe/main.rs:
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! # These are core DataFrame API usage
+//!
+//! These examples demonstrate core DataFrame API usage.
+//!
+//! ## Usage
+//! ```bash
+//! cargo run --example dataframe -- [dataframe|default_column_values|deserialize_to_struct]
+//! ```
+//!
+//! Each subcommand runs a corresponding example:
+//! - `dataframe` — run a query using a DataFrame API against parquet files, csv files, and in-memory data, including multiple subqueries
+//! - `default_column_values` — implement custom default value handling for missing columns using field metadata and PhysicalExprAdapter
+//! - `deserialize_to_struct` — convert query results (Arrow ArrayRefs) into Rust structs
+
+mod dataframe;
+mod default_column_values;
+mod deserialize_to_struct;
+
+use std::str::FromStr;
+
+use datafusion::error::{DataFusionError, Result};
+
+enum ExampleKind {
+ Dataframe,
+ DefaultColumnValues,
+ DeserializeToStruct,
+}
+
+impl AsRef<str> for ExampleKind {
+ fn as_ref(&self) -> &str {
+ match self {
+ Self::Dataframe => "dataframe",
+ Self::DefaultColumnValues => "default_column_values",
+ Self::DeserializeToStruct => "deserialize_to_struct",
+ }
+ }
+}
+
+impl FromStr for ExampleKind {
+ type Err = DataFusionError;
+
+ fn from_str(s: &str) -> Result<Self> {
+ match s {
+ "dataframe" => Ok(Self::Dataframe),
+ "default_column_values" => Ok(Self::DefaultColumnValues),
+ "deserialize_to_struct" => Ok(Self::DeserializeToStruct),
+ _ => Err(DataFusionError::Execution(format!("Unknown example: {s}"))),
+ }
+ }
+}
+
+impl ExampleKind {
+ const ALL: [Self; 3] = [
+ Self::Dataframe,
+ Self::DefaultColumnValues,
+ Self::DeserializeToStruct,
+ ];
+
+ const EXAMPLE_NAME: &str = "dataframe";
+
+ fn variants() -> Vec<&'static str> {
+ Self::ALL.iter().map(|x| x.as_ref()).collect()
+ }
+}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let usage = format!(
+ "Usage: cargo run --example {} -- [{}]",
+ ExampleKind::EXAMPLE_NAME,
+ ExampleKind::variants().join("|")
Review Comment:
The options are listed here: '-- [dataframe|default_column_values|deserialize_to_struct]'
Maybe another format should be used...
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #18862:
URL: https://github.com/apache/datafusion/pull/18862
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "cj-zhukov (via GitHub)" <gi...@apache.org>.
cj-zhukov commented on PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#issuecomment-3561598057
### High-Level Overview
This PR consolidates all `dataframe` examples (dataframe, default_column_values, deserialize_to_struct) into a single example binary.
Previously, each example had its own file, but now they can be executed via subcommands using:
```bash
cargo run --example dataframe -- [dataframe|default_column_values|deserialize_to_struct]
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#issuecomment-3568015584
Thanks again @cj-zhukov and @martin-g
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#discussion_r2550881730
##########
datafusion-examples/examples/dataframe/default_column_values.rs:
##########
@@ -52,25 +54,23 @@ use object_store::{ObjectStore, PutPayload};
// Metadata key for storing default values in field metadata
const DEFAULT_VALUE_METADATA_KEY: &str = "example.default_value";
-// Example showing how to implement custom default value handling for missing columns
-// using field metadata and PhysicalExprAdapter.
-//
-// This example demonstrates how to:
-// 1. Store default values in field metadata using a constant key
-// 2. Create a custom PhysicalExprAdapter that reads these defaults
-// 3. Inject default values for missing columns in filter predicates
-// 4. Use the DefaultPhysicalExprAdapter as a fallback for standard schema adaptation
-// 5. Wrap string default values in cast expressions for proper type conversion
-//
-// Important: PhysicalExprAdapter is specifically designed for rewriting filter predicates
-// that get pushed down to file scans. For handling missing columns in projections,
-// other mechanisms in DataFusion are used (like SchemaAdapter).
-//
-// The metadata-based approach provides a flexible way to store default values as strings
-// and cast them to the appropriate types at query time.
-
-#[tokio::main]
-async fn main() -> Result<()> {
+/// Example showing how to implement custom default value handling for missing columns
+/// using field metadata and PhysicalExprAdapter.
+///
+/// This example demonstrates how to:
+/// 1. Store default values in field metadata using a constant key
+/// 2. Create a custom PhysicalExprAdapter that reads these defaults
+/// 3. Inject default values for missing columns in filter predicates
+/// 4. Use the DefaultPhysicalExprAdapter as a fallback for standard schema adaptation
+/// 5. Wrap string default values in cast expressions for proper type conversion
+///
+/// Important: PhysicalExprAdapter is specifically designed for rewriting filter predicates
+/// that get pushed down to file scans. For handling missing columns in projections,
+/// other mechanisms in DataFusion are used (like SchemaAdapter).
+///
+/// The metadata-based approach provides a flexible way to store default values as strings
+/// and cast them to the appropriate types at query time.
+pub async fn default_column_values() -> Result<()> {
Review Comment:
I am not quite sure that this is a "dataframe" example -- it does use the DataFrame API but I think it is really illustrating how to provide a custom data source that fills in default column values
I suggest we move it to https://github.com/apache/datafusion/tree/main/datafusion-examples/examples/custom_data_source instead
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Consolidate dataframe examples (#18142) [datafusion]
Posted by "cj-zhukov (via GitHub)" <gi...@apache.org>.
cj-zhukov commented on code in PR #18862:
URL: https://github.com/apache/datafusion/pull/18862#discussion_r2552292873
##########
datafusion-examples/examples/dataframe/main.rs:
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! # These are core DataFrame API usage
+//!
+//! These examples demonstrate core DataFrame API usage.
+//!
+//! ## Usage
+//! ```bash
+//! cargo run --example dataframe -- [dataframe|default_column_values|deserialize_to_struct]
+//! ```
+//!
+//! Each subcommand runs a corresponding example:
+//! - `dataframe` — run a query using a DataFrame API against parquet files, csv files, and in-memory data, including multiple subqueries
+//! - `default_column_values` — implement custom default value handling for missing columns using field metadata and PhysicalExprAdapter
+//! - `deserialize_to_struct` — convert query results (Arrow ArrayRefs) into Rust structs
+
+mod dataframe;
+mod default_column_values;
+mod deserialize_to_struct;
+
+use std::str::FromStr;
+
+use datafusion::error::{DataFusionError, Result};
+
+enum ExampleKind {
+ Dataframe,
+ DefaultColumnValues,
+ DeserializeToStruct,
+}
+
+impl AsRef<str> for ExampleKind {
+ fn as_ref(&self) -> &str {
+ match self {
+ Self::Dataframe => "dataframe",
+ Self::DefaultColumnValues => "default_column_values",
+ Self::DeserializeToStruct => "deserialize_to_struct",
+ }
+ }
+}
+
+impl FromStr for ExampleKind {
+ type Err = DataFusionError;
+
+ fn from_str(s: &str) -> Result<Self> {
+ match s {
+ "dataframe" => Ok(Self::Dataframe),
+ "default_column_values" => Ok(Self::DefaultColumnValues),
+ "deserialize_to_struct" => Ok(Self::DeserializeToStruct),
+ _ => Err(DataFusionError::Execution(format!("Unknown example: {s}"))),
+ }
+ }
+}
+
+impl ExampleKind {
+ const ALL: [Self; 3] = [
+ Self::Dataframe,
+ Self::DefaultColumnValues,
+ Self::DeserializeToStruct,
+ ];
+
+ const EXAMPLE_NAME: &str = "dataframe";
+
+ fn variants() -> Vec<&'static str> {
+ Self::ALL.iter().map(|x| x.as_ref()).collect()
+ }
+}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let usage = format!(
+ "Usage: cargo run --example {} -- [{}]",
+ ExampleKind::EXAMPLE_NAME,
+ ExampleKind::variants().join("|")
Review Comment:
Thanks! I see what you mean - while the valid options are included in the usage line, they are not very visible, especially since they appear only after the “Missing argument” error.
I agree the formatting could be improved to make the valid options clearer. We could print them separately (as a list) or improve the usage string so it’s easier to read.
I'm happy to adjust the formatting if you have a preferred style, or I can propose one:
```bash
Usage:
cargo run --example dataframe <EXAMPLE>
Examples:
dataframe
default_column_values
deserialize_to_struct
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org