@@ -35,6 +35,167 @@ 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+ #[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
40+ pub struct OwnedFormatOptions {
41+ /// String representation of null values
42+ pub null : String ,
43+ /// Date format string
44+ pub date_format : Option < String > ,
45+ /// Datetime format string
46+ pub datetime_format : Option < String > ,
47+ /// Timestamp format string
48+ pub timestamp_format : Option < String > ,
49+ /// Timestamp with timezone format string
50+ pub timestamp_tz_format : Option < String > ,
51+ /// Time format string
52+ pub time_format : Option < String > ,
53+ /// Duration format
54+ pub duration_format : DurationFormat ,
55+ /// Include type information in formatted output
56+ pub types_info : bool ,
57+ }
58+
59+ impl OwnedFormatOptions {
60+ /// Create a new `OwnedFormatOptions` with default values.
61+ pub fn new ( ) -> Self {
62+ Self :: default ( )
63+ }
64+
65+ /// Set the null string.
66+ pub fn with_null ( mut self , null : String ) -> Self {
67+ self . null = null;
68+ self
69+ }
70+
71+ /// Set the date format.
72+ pub fn with_date_format ( mut self , date_format : Option < String > ) -> Self {
73+ self . date_format = date_format;
74+ self
75+ }
76+
77+ /// Set the datetime format.
78+ pub fn with_datetime_format ( mut self , datetime_format : Option < String > ) -> Self {
79+ self . datetime_format = datetime_format;
80+ self
81+ }
82+
83+ /// Set the timestamp format.
84+ pub fn with_timestamp_format ( mut self , timestamp_format : Option < String > ) -> Self {
85+ self . timestamp_format = timestamp_format;
86+ self
87+ }
88+
89+ /// Set the timestamp with timezone format.
90+ pub fn with_timestamp_tz_format (
91+ mut self ,
92+ timestamp_tz_format : Option < String > ,
93+ ) -> Self {
94+ self . timestamp_tz_format = timestamp_tz_format;
95+ self
96+ }
97+
98+ /// Set the time format.
99+ pub fn with_time_format ( mut self , time_format : Option < String > ) -> Self {
100+ self . time_format = time_format;
101+ self
102+ }
103+
104+ /// Set the duration format.
105+ pub fn with_duration_format ( mut self , duration_format : DurationFormat ) -> Self {
106+ self . duration_format = duration_format;
107+ self
108+ }
109+
110+ /// Set whether to include type information in formatted output.
111+ pub fn with_types_info ( mut self , types_info : bool ) -> Self {
112+ self . types_info = types_info;
113+ self
114+ }
115+
116+ /// Convert to Arrow's `FormatOptions<'a>` with borrowed references.
117+ pub fn as_arrow_options < ' a > ( & ' a self ) -> FormatOptions < ' a > {
118+ FormatOptions :: new ( )
119+ . with_null ( self . null . as_str ( ) )
120+ . with_date_format ( self . date_format . as_deref ( ) )
121+ . with_datetime_format ( self . datetime_format . as_deref ( ) )
122+ . with_timestamp_format ( self . timestamp_format . as_deref ( ) )
123+ . with_timestamp_tz_format ( self . timestamp_tz_format . as_deref ( ) )
124+ . with_time_format ( self . time_format . as_deref ( ) )
125+ . with_duration_format ( self . duration_format )
126+ . with_display_error ( false )
127+ . with_types_info ( self . types_info )
128+ }
129+ }
130+
131+ impl Default for OwnedFormatOptions {
132+ fn default ( ) -> Self {
133+ Self {
134+ null : "NULL" . to_string ( ) ,
135+ date_format : None ,
136+ datetime_format : None ,
137+ timestamp_format : None ,
138+ timestamp_tz_format : None ,
139+ time_format : None ,
140+ duration_format : DurationFormat :: Pretty ,
141+ types_info : false ,
142+ }
143+ }
144+ }
145+
146+ /// Owned version of Arrow's `CastOptions` with `OwnedFormatOptions`.
147+ #[ derive( Debug , Clone , Default , Eq , PartialEq , Hash ) ]
148+ pub struct OwnedCastOptions {
149+ /// Whether to use safe casting (return errors instead of overflowing)
150+ pub safe : bool ,
151+ /// Format options for string output
152+ pub format_options : OwnedFormatOptions ,
153+ }
154+
155+ impl OwnedCastOptions {
156+ /// Create a new `OwnedCastOptions` with default values.
157+ pub fn new ( safe : bool ) -> Self {
158+ Self {
159+ safe,
160+ format_options : OwnedFormatOptions :: default ( ) ,
161+ }
162+ }
163+
164+ /// Create a new `OwnedCastOptions` from Arrow `CastOptions`.
165+ pub fn from_arrow_options ( options : & CastOptions < ' _ > ) -> Self {
166+ Self {
167+ safe : options. safe ,
168+ format_options : OwnedFormatOptions {
169+ null : options. format_options . null ( ) . to_string ( ) ,
170+ date_format : options. format_options . date_format ( ) . map ( |s| s. to_string ( ) ) ,
171+ datetime_format : options
172+ . format_options
173+ . datetime_format ( )
174+ . map ( |s| s. to_string ( ) ) ,
175+ timestamp_format : options
176+ . format_options
177+ . timestamp_format ( )
178+ . map ( |s| s. to_string ( ) ) ,
179+ timestamp_tz_format : options
180+ . format_options
181+ . timestamp_tz_format ( )
182+ . map ( |s| s. to_string ( ) ) ,
183+ time_format : options. format_options . time_format ( ) . map ( |s| s. to_string ( ) ) ,
184+ duration_format : options. format_options . duration_format ( ) ,
185+ types_info : options. format_options . types_info ( ) ,
186+ } ,
187+ }
188+ }
189+
190+ /// Convert to Arrow's `CastOptions<'a>` with borrowed references.
191+ pub fn as_arrow_options < ' a > ( & ' a self ) -> CastOptions < ' a > {
192+ CastOptions {
193+ safe : self . safe ,
194+ format_options : self . format_options . as_arrow_options ( ) ,
195+ }
196+ }
197+ }
198+
38199/// Output formats for controlling for Explain plans
39200#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
40201pub enum ExplainFormat {
0 commit comments