#[non_exhaustive]pub struct ArrowOptions { /* private fields */ }Expand description
Configuration options for Arrow serialization and deserialization with ClickHouse.
The ArrowOptions struct defines settings that control how Apache Arrow data types
are mapped to ClickHouse types during serialization (e.g., inserts), deserialization
(e.g., queries), and schema creation (e.g., DDL operations). These options are used
by [ArrowClient] and set via [ClientBuilder::with_arrow_options] or directly in
ClientOptions.
§Fields
strings_as_strings: Iftrue, mapsClickHouseStringto ArrowUtf8; iffalse, maps toBinary(default).use_date32_for_date: Iftrue, maps ArrowDate32toClickHouseDate32; iffalse, maps toDate(default).strict_schema: Iftrue, enforces strict type mappings during serialization (inserts) and schema creation, causing errors onClickHouseinvariant violations (e.g.,Nullable(LowCardinality(String))); iffalse, attempts to correct violations (e.g., mapping toLowCardinality(Nullable(String))) (default).disable_strict_schema_ddl: Iftrue, prevents automatic strict mode during schema creation (viaArrowOptions::into_strict_ddl); iffalse, schema creation defaults to strict mode (default).nullable_array_default_empty: Iftrue, mapsNullable(Array(...))toArray(...)with[]for nulls during inserts and schema creation (ifdisable_strict_schema_ddl = true); iffalse, errors onNullable(Array(...))(default).
§Notes
- During schema creation, options are converted to strict mode (via
ArrowOptions::into_strict_ddl) unlessdisable_strict_schema_ddlistrue. Strict mode setsstrict_schema = trueand effectively enforcesnullable_array_default_empty = false, ensuring non-nullable arrays. - When
strict_schemaisfalse, violations likeNullable(LowCardinality(String))are corrected, but arrays are handled pernullable_array_default_emptyfor inserts, while nullable arrays are ignored during schema creation. - If
strict_schema = trueandnullable_array_default_empty = true, non-array violations (e.g.,LowCardinality) error, but arrays map to[]for nulls during insert. This is useful in cases where the arrowSchemais used to create the table, but arrays may come from differentRecordBatches. - This struct is
#[non_exhaustive], so future fields may be added (e.g., for newClickHousetypes or serialization options). UseArrowOptions::neworArrowOptions::defaultto construct instances.
§Examples
use clickhouse_arrow::prelude::*;
let arrow_options = ArrowOptions::new()
.with_strings_as_strings(true)
.with_strict_schema(true)
.with_nullable_array_default_empty(false);
let options = ClientOptions {
arrow: Some(arrow_options),
..ClientOptions::default()
};Implementations§
Source§impl ArrowOptions
impl ArrowOptions
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new ArrowOptions instance with default values.
This method is equivalent to ArrowOptions::default, initializing fields for
relaxed type mappings. Use this to start configuring Arrow
serialization/deserialization options for ClickHouse.
§Returns
A new ArrowOptions instance with default settings.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let arrow_options = ArrowOptions::new();
println!("Nullable array default empty: {}", arrow_options.nullable_array_default_empty); // trueSourcepub const fn strict() -> Self
pub const fn strict() -> Self
Creates an ArrowOptions instance with strict type mapping settings.
This method configures options for strict type mappings, where ClickHouse
invariant violations (e.g., Nullable(LowCardinality(String)) or
Nullable(Array(...))) cause errors during serialization (inserts) and schema
creation. It sets strict_schema to true and nullable_array_default_empty to
false, leaving other fields as false. Use this for operations where
ClickHouse invariants must be strictly enforced.
§Returns
An ArrowOptions instance with strict settings.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let arrow_options = ArrowOptions::strict();
println!("Strict schema: {}", arrow_options.strict_schema); // trueSourcepub fn into_strict_ddl(self) -> Self
pub fn into_strict_ddl(self) -> Self
Converts the options to strict mode for schema creation, unless disabled.
This method returns a new ArrowOptions with strict settings (equivalent to
ArrowOptions::strict) unless disable_strict_schema_ddl is true. If
disable_strict_schema_ddl is true, the original options are returned
unchanged. This method is called automatically during schema creation to enforce
ClickHouse invariants, including non-nullable arrays, unless explicitly disabled.
§Returns
A new ArrowOptions instance with strict settings or the original options.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let options_strict_off = ArrowOptions::new()
.with_disable_strict_schema_ddl(true)
.into_strict_ddl();
assert!(!options_strict_off.strict_schema);
assert!(options_strict_off.nullable_array_default_empty);
let options_strict = ArrowOptions::new()
.with_disable_strict_schema_ddl(false) // Default
.into_strict_ddl();
assert!(options_strict.strict_schema);
assert!(!options_strict.nullable_array_default_empty);Sourcepub fn with_strings_as_strings(self, enabled: bool) -> Self
pub fn with_strings_as_strings(self, enabled: bool) -> Self
Sets whether ClickHouse String types are deserialized as Arrow Utf8.
By default, ClickHouse String types map to Arrow Binary. When this option
is enabled (true), they map to Arrow Utf8, which is more suitable for text
data. Use this to control serialization/deserialization behavior for string
columns.
§Parameters
enabled: Iftrue, mapscrate::Type::Stringtoarrow::datatypes::DataType::Utf8; iffalse, maps toarrow::datatypes::DataType::Binary.
§Returns
A new ArrowOptions with the updated setting.
§Examples
use clickhouse_arrow::prelude::*;
let arrow_options = ArrowOptions::new()
.with_strings_as_strings(true);
println!("Strings as strings: {}", arrow_options.strings_as_strings); // trueSourcepub fn with_use_date32_for_date(self, enabled: bool) -> Self
pub fn with_use_date32_for_date(self, enabled: bool) -> Self
Sets whether Arrow Date32 is mapped to ClickHouse Date or Date32.
By default, Arrow Date32 maps to ClickHouse Date (days since 1970-01-01).
When this option is enabled (true), it maps to ClickHouse Date32 (days
since 1900-01-01). Use this to control date serialization/deserialization
behavior.
§Parameters
enabled: Iftrue, mapsDate32toClickHouseDate32; iffalse, maps toDate.
§Returns
A new ArrowOptions with the updated setting.
§Examples
use clickhouse_arrow::prelude::*;
let arrow_options = ArrowOptions::new()
.with_use_date32_for_date(true);
println!("Use Date32 for Date: {}", arrow_options.use_date32_for_date); // trueSourcepub fn with_strict_schema(self, enabled: bool) -> Self
pub fn with_strict_schema(self, enabled: bool) -> Self
Sets whether type mappings are strict during serialization and schema creation.
By default, type mappings are relaxed, allowing ClickHouse invariant violations
(e.g., Nullable(LowCardinality(String))) to be corrected automatically (e.g.,
mapping to LowCardinality(Nullable(String))). When this option is enabled
(true), non-array violations cause errors during serialization (inserts) and
schema creation. Array violations are controlled by
ArrowOptions::with_nullable_array_default_empty. Schema creation defaults to
strict mode unless ArrowOptions::with_disable_strict_schema_ddl is enabled.
§Parameters
enabled: Iftrue, enforces strict type mappings for non-array types; iffalse, allows relaxed corrections.
§Returns
A new ArrowOptions with the updated setting.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let arrow_options = ArrowOptions::new()
.with_strict_schema(true);
println!("Strict schema: {}", arrow_options.strict_schema); // trueSourcepub fn with_disable_strict_schema_ddl(self, enabled: bool) -> Self
pub fn with_disable_strict_schema_ddl(self, enabled: bool) -> Self
Sets whether strict mode is disabled during schema creation.
By default, schema creation (e.g., DDL operations) uses strict type mappings (via
ArrowOptions::into_strict_ddl), enforcing ClickHouse invariants and causing
errors on violations, including Nullable(Array(...)). When this option is
enabled (true), strict mode is disabled for schema creation, using the user’s
strict_schema and nullable_array_default_empty settings.
§Parameters
enabled: Iftrue, disables strict mode for schema creation; iffalse, enables strict mode.
§Returns
A new ArrowOptions with the updated setting.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let arrow_options = ArrowOptions::new()
.with_disable_strict_schema_ddl(true);
assert!(arrow_options.disable_strict_schema_ddl);Sourcepub fn with_nullable_array_default_empty(self, enabled: bool) -> Self
pub fn with_nullable_array_default_empty(self, enabled: bool) -> Self
Sets whether Nullable(Array(...)) types default to empty arrays during inserts and are
coerced to non-nullable during DDL.
By default, Nullable(Array(...)) types are mapped to Array(...) with [] for
nulls during serialization (inserts) and schema creation (if
disable_strict_schema_ddl = true). When this option is disabled (false),
Nullable(Array(...)) causes errors, enforcing non-nullable arrays. Schema
creation defaults to non-nullable arrays unless
ArrowOptions::with_disable_strict_schema_ddl is enabled.
§Parameters
enabled: Iftrue, mapsNullable(Array(...))toArray(...)with[]for nulls; iffalse, errors onNullable(Array(...)).
§Returns
A new ArrowOptions with the updated setting.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let arrow_options = ArrowOptions::new()
.with_nullable_array_default_empty(false);
assert!(!arrow_options.nullable_array_default_empty);Sourcepub fn with_setting(self, name: &str, value: bool) -> Self
pub fn with_setting(self, name: &str, value: bool) -> Self
Sets an Arrow option by name and value.
This method updates a specific option identified by name to the given boolean
value. Currently supported names are:
"strings_as_strings": MapsClickHouseStringto ArrowUtf8."use_date32_for_date": Maps ArrowDate32toClickHouseDate32."strict_schema": Enforces strict type mappings for non-array types."disable_strict_schema_ddl": Disables strict mode for schema creation."nullable_array_default_empty": MapsNullable(Array(...))toArray(...)with[]for nulls.
If an unrecognized name is provided, a warning is logged, and the options are returned unchanged. Use this for dynamic configuration or when options are specified as key-value pairs.
§Parameters
name: The name of the option to set.value: The boolean value to set for the option.
§Returns
A new ArrowOptions with the updated setting.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let arrow_options = ArrowOptions::new()
.with_setting("strings_as_strings", true)
.with_setting("nullable_array_default_empty", false);
assert!(arrow_options.strings_as_strings);
assert!(!arrow_options.nullable_array_default_empty);Trait Implementations§
Source§impl Clone for ArrowOptions
impl Clone for ArrowOptions
Source§fn clone(&self) -> ArrowOptions
fn clone(&self) -> ArrowOptions
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ArrowOptions
impl Debug for ArrowOptions
Source§impl Default for ArrowOptions
impl Default for ArrowOptions
Source§fn default() -> Self
fn default() -> Self
Creates an ArrowOptions instance with default values.
The default configuration uses relaxed type mappings suitable for most
ClickHouse and Arrow use cases:
ClickHouseStringmaps to ArrowBinary.- Arrow
Date32maps toClickHouseDate. - Type mappings are relaxed, correcting
ClickHouseinvariant violations (e.g., mappingNullable(LowCardinality(String))toLowCardinality(Nullable(String))). - Schema creation defaults to strict mode (via
ArrowOptions::into_strict_ddl). Nullable(Array(...))defaults toArray(...)with[]for nulls.
Use this as a starting point and customize with methods like
ArrowOptions::with_strings_as_strings.
§Returns
An ArrowOptions instance with default settings.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let arrow_options = ArrowOptions::default();
println!("Nullable array default empty: {}", arrow_options.nullable_array_default_empty); // trueSource§impl<'de> Deserialize<'de> for ArrowOptions
impl<'de> Deserialize<'de> for ArrowOptions
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a, S, I> From<I> for ArrowOptions
impl<'a, S, I> From<I> for ArrowOptions
Source§fn from(value: I) -> Self
fn from(value: I) -> Self
Creates an ArrowOptions instance from an iterator of key-value pairs.
This method constructs an ArrowOptions by applying settings from an iterator
of (key, value) pairs, where key is a string (e.g., "strict_schema") and
value is a boolean. It uses ArrowOptions::with_setting to apply each
setting. Unrecognized keys trigger a warning but do not cause an error.
See currently supported keys by inspecting ArrowOptions::with_setting.
§Parameters
value: An iterator of(key, value)pairs, wherekeyis a string-like type andvalueis a boolean.
§Returns
An ArrowOptions instance with the applied settings.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let settings = vec![("strings_as_strings", true), ("nullable_array_default_empty", false)];
let arrow_options: ArrowOptions = settings.iter().collect();
assert!(arrow_options.strings_as_strings);
assert!(!arrow_options.nullable_array_default_empty);Source§impl<'a> FromIterator<(&'a str, bool)> for ArrowOptions
impl<'a> FromIterator<(&'a str, bool)> for ArrowOptions
Source§fn from_iter<I: IntoIterator<Item = (&'a str, bool)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (&'a str, bool)>>(iter: I) -> Self
Creates an ArrowOptions instance from an iterator of string-boolean pairs.
This method constructs an ArrowOptions by applying settings from an iterator
of (key, value) pairs, where key is a string slice (e.g., "strict_schema")
and value is a boolean. It uses ArrowOptions::with_setting to apply each
setting. Unrecognized keys trigger a warning but do not cause an error.
See currently supported keys by inspecting ArrowOptions::with_setting.
§Parameters
iter: An iterator of(key, value)pairs, wherekeyis a string slice andvalueis a boolean.
§Returns
An ArrowOptions instance with the applied settings.
§Examples
use clickhouse_arrow::arrow::ArrowOptions;
let settings = vec![("strings_as_strings", true), ("nullable_array_default_empty", false)];
let arrow_options = ArrowOptions::from_iter(settings);
assert!(arrow_options.strings_as_strings);
assert!(!arrow_options.nullable_array_default_empty);Source§impl PartialEq for ArrowOptions
impl PartialEq for ArrowOptions
Source§impl Serialize for ArrowOptions
impl Serialize for ArrowOptions
impl Copy for ArrowOptions
impl Eq for ArrowOptions
impl StructuralPartialEq for ArrowOptions
Auto Trait Implementations§
impl Freeze for ArrowOptions
impl RefUnwindSafe for ArrowOptions
impl Send for ArrowOptions
impl Sync for ArrowOptions
impl Unpin for ArrowOptions
impl UnwindSafe for ArrowOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.