@@ -35,206 +35,6 @@ pub const DEFAULT_CAST_OPTIONS: CastOptions<'static> = CastOptions {
3535 format_options : DEFAULT_FORMAT_OPTIONS ,
3636} ;
3737
38- /// Owned version of Arrow's `FormatOptions` with all `String` values instead of `&str`.
39- ///
40- /// While Arrow's `FormatOptions<'a>` accepts generic lifetimes, the default constants and
41- /// public APIs are designed around `'static` strings (e.g., hardcoded format strings).
42- /// This struct uses `String` values, allowing format options to be created and owned at
43- /// runtime without lifetime constraints.
44- ///
45- /// # Conversion to Arrow Types
46- ///
47- /// Use the `as_arrow_options()` method to temporarily convert to `FormatOptions<'a>`
48- /// with borrowed references for passing to Arrow compute kernels:
49- ///
50- /// ```ignore
51- /// let owned_options = OwnedFormatOptions::default();
52- /// let arrow_options = owned_options.as_arrow_options(); // borrows owned strings
53- /// ```
54- #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
55- pub struct OwnedFormatOptions {
56- /// String representation of null values
57- pub null : String ,
58- /// Date format string
59- pub date_format : Option < String > ,
60- /// Datetime format string
61- pub datetime_format : Option < String > ,
62- /// Timestamp format string
63- pub timestamp_format : Option < String > ,
64- /// Timestamp with timezone format string
65- pub timestamp_tz_format : Option < String > ,
66- /// Time format string
67- pub time_format : Option < String > ,
68- /// Duration format (owned, since DurationFormat is a simple enum)
69- pub duration_format : DurationFormat ,
70- /// Include type information in formatted output
71- pub types_info : bool ,
72- }
73-
74- impl OwnedFormatOptions {
75- /// Create a new `OwnedFormatOptions` with default values.
76- pub fn new ( ) -> Self {
77- Self :: default ( )
78- }
79-
80- /// Set the null string.
81- pub fn with_null ( mut self , null : String ) -> Self {
82- self . null = null;
83- self
84- }
85-
86- /// Set the date format.
87- pub fn with_date_format ( mut self , date_format : Option < String > ) -> Self {
88- self . date_format = date_format;
89- self
90- }
91-
92- /// Set the datetime format.
93- pub fn with_datetime_format ( mut self , datetime_format : Option < String > ) -> Self {
94- self . datetime_format = datetime_format;
95- self
96- }
97-
98- /// Set the timestamp format.
99- pub fn with_timestamp_format ( mut self , timestamp_format : Option < String > ) -> Self {
100- self . timestamp_format = timestamp_format;
101- self
102- }
103-
104- /// Set the timestamp with timezone format.
105- pub fn with_timestamp_tz_format (
106- mut self ,
107- timestamp_tz_format : Option < String > ,
108- ) -> Self {
109- self . timestamp_tz_format = timestamp_tz_format;
110- self
111- }
112-
113- /// Set the time format.
114- pub fn with_time_format ( mut self , time_format : Option < String > ) -> Self {
115- self . time_format = time_format;
116- self
117- }
118-
119- /// Set the duration format.
120- pub fn with_duration_format ( mut self , duration_format : DurationFormat ) -> Self {
121- self . duration_format = duration_format;
122- self
123- }
124-
125- /// Set whether to include type information in formatted output.
126- pub fn with_types_info ( mut self , types_info : bool ) -> Self {
127- self . types_info = types_info;
128- self
129- }
130-
131- /// Convert to Arrow's `FormatOptions<'a>` with borrowed references.
132- ///
133- /// This creates a temporary `FormatOptions` with borrowed `&str` references
134- /// to the owned strings. The returned options can be passed to Arrow compute
135- /// kernels. The borrowed references are valid only as long as `self` is alive.
136- pub fn as_arrow_options < ' a > ( & ' a self ) -> FormatOptions < ' a > {
137- FormatOptions :: new ( )
138- . with_null ( self . null . as_str ( ) )
139- . with_date_format ( self . date_format . as_deref ( ) )
140- . with_datetime_format ( self . datetime_format . as_deref ( ) )
141- . with_timestamp_format ( self . timestamp_format . as_deref ( ) )
142- . with_timestamp_tz_format ( self . timestamp_tz_format . as_deref ( ) )
143- . with_time_format ( self . time_format . as_deref ( ) )
144- . with_duration_format ( self . duration_format )
145- . with_display_error ( false )
146- . with_types_info ( self . types_info )
147- }
148- }
149-
150- impl Default for OwnedFormatOptions {
151- fn default ( ) -> Self {
152- Self {
153- null : "NULL" . to_string ( ) ,
154- date_format : None ,
155- datetime_format : None ,
156- timestamp_format : None ,
157- timestamp_tz_format : None ,
158- time_format : None ,
159- duration_format : DurationFormat :: Pretty ,
160- types_info : false ,
161- }
162- }
163- }
164-
165- /// Owned version of Arrow's `CastOptions` with `OwnedFormatOptions` instead of `FormatOptions<'a>`.
166- ///
167- /// While Arrow's `CastOptions<'a>` accepts generic lifetimes, the default constants and
168- /// public APIs are designed around `'static` strings (e.g., hardcoded format strings).
169- /// This struct uses `OwnedFormatOptions` with `String` values, allowing dynamic cast options
170- /// to be created and owned at runtime without lifetime constraints.
171- ///
172- /// # Conversion to Arrow Types
173- ///
174- /// Use the `as_arrow_options()` method to temporarily convert to `CastOptions<'a>`
175- /// with borrowed references for passing to Arrow compute kernels:
176- ///
177- /// ```ignore
178- /// let owned_options = OwnedCastOptions { ... };
179- /// let arrow_options = owned_options.as_arrow_options(); // borrows owned strings
180- /// arrow::compute::cast(&array, &data_type, Some(&arrow_options))?;
181- /// ```
182- #[ derive( Debug , Clone , Default , Eq , PartialEq , Hash ) ]
183- pub struct OwnedCastOptions {
184- /// Whether to use safe casting (return errors instead of overflowing)
185- pub safe : bool ,
186- /// Format options for string output
187- pub format_options : OwnedFormatOptions ,
188- }
189-
190- impl OwnedCastOptions {
191- /// Create a new `OwnedCastOptions` with default values.
192- pub fn new ( safe : bool ) -> Self {
193- Self {
194- safe,
195- format_options : OwnedFormatOptions :: default ( ) ,
196- }
197- }
198-
199- /// Create a new `OwnedCastOptions` from an Arrow `CastOptions`.
200- pub fn from_arrow_options ( options : & CastOptions < ' _ > ) -> Self {
201- Self {
202- safe : options. safe ,
203- format_options : OwnedFormatOptions {
204- null : options. format_options . null ( ) . to_string ( ) ,
205- date_format : options. format_options . date_format ( ) . map ( |s| s. to_string ( ) ) ,
206- datetime_format : options
207- . format_options
208- . datetime_format ( )
209- . map ( |s| s. to_string ( ) ) ,
210- timestamp_format : options
211- . format_options
212- . timestamp_format ( )
213- . map ( |s| s. to_string ( ) ) ,
214- timestamp_tz_format : options
215- . format_options
216- . timestamp_tz_format ( )
217- . map ( |s| s. to_string ( ) ) ,
218- time_format : options. format_options . time_format ( ) . map ( |s| s. to_string ( ) ) ,
219- duration_format : options. format_options . duration_format ( ) ,
220- types_info : options. format_options . types_info ( ) ,
221- } ,
222- }
223- }
224-
225- /// Convert to Arrow's `CastOptions<'a>` with borrowed references.
226- ///
227- /// This creates a temporary `CastOptions` with borrowed `&str` references
228- /// to the owned strings. The returned options can be passed to Arrow compute
229- /// kernels. The borrowed references are valid only as long as `self` is alive.
230- pub fn as_arrow_options < ' a > ( & ' a self ) -> CastOptions < ' a > {
231- CastOptions {
232- safe : self . safe ,
233- format_options : self . format_options . as_arrow_options ( ) ,
234- }
235- }
236- }
237-
23838/// Output formats for controlling for Explain plans
23939#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
24040pub enum ExplainFormat {
0 commit comments