This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 34f53b7c9 feat(rust/core): implement fallible conversions for
`IngestMode` (#4350)
34f53b7c9 is described below
commit 34f53b7c900e0c4e9b7519312622adc549899016
Author: Austin Bonander <[email protected]>
AuthorDate: Mon Jun 1 15:26:05 2026 -0700
feat(rust/core): implement fallible conversions for `IngestMode` (#4350)
Implements `FromStr` and `TryFrom<&OptionValue>` for `IngestMode`.
I was going to end up writing nearly identical code in the ClickHouse
ADBC driver, but it's better just to support it in `adbc_core` as it's
one less thing for each driver to roll individually.
---
rust/core/src/options.rs | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/rust/core/src/options.rs b/rust/core/src/options.rs
index 21906d42c..98bca581f 100644
--- a/rust/core/src/options.rs
+++ b/rust/core/src/options.rs
@@ -564,6 +564,43 @@ impl From<IngestMode> for OptionValue {
}
}
+impl FromStr for IngestMode {
+ type Err = Error;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ constants::ADBC_INGEST_OPTION_MODE_CREATE => Ok(Self::Create),
+ constants::ADBC_INGEST_OPTION_MODE_APPEND => Ok(Self::Append),
+ constants::ADBC_INGEST_OPTION_MODE_REPLACE => Ok(Self::Replace),
+ constants::ADBC_INGEST_OPTION_MODE_CREATE_APPEND =>
Ok(Self::CreateAppend),
+ other => Err(Error::with_message_and_status(
+ format!(
+ "invalid value for option {:?}: {other:?}",
+ constants::ADBC_INGEST_OPTION_MODE
+ ),
+ Status::InvalidArguments,
+ )),
+ }
+ }
+}
+
+impl TryFrom<&OptionValue> for IngestMode {
+ type Error = Error;
+
+ fn try_from(value: &OptionValue) -> Result<Self, Self::Error> {
+ match value {
+ OptionValue::String(s) => s.parse(),
+ other => Err(Error::with_message_and_status(
+ format!(
+ "invalid value type for option {:?}: {other:?}",
+ constants::ADBC_INGEST_OPTION_MODE
+ ),
+ Status::InvalidArguments,
+ )),
+ }
+ }
+}
+
/// Statistics about the data distribution.
#[derive(Debug, Clone)]
pub enum Statistics {