@@ -32,7 +32,7 @@ use object_store::{ObjectMeta, ObjectStore};
3232use vortex:: dtype:: arrow:: FromArrowType ;
3333use vortex:: dtype:: { DType , Nullability , PType } ;
3434use vortex:: error:: { VortexExpect , VortexResult , vortex_err} ;
35- use vortex:: file:: VORTEX_FILE_EXTENSION ;
35+ use vortex:: file:: { VORTEX_FILE_EXTENSION , VortexWriteOptionsFactory } ;
3636use vortex:: metrics:: VortexMetrics ;
3737use vortex:: scalar:: Scalar ;
3838use vortex:: session:: VortexSession ;
@@ -50,6 +50,7 @@ pub struct VortexFormat {
5050 session : Arc < VortexSession > ,
5151 file_cache : VortexFileCache ,
5252 opts : VortexOptions ,
53+ write_options_factory : Arc < VortexWriteOptionsFactory > ,
5354}
5455
5556impl Debug for VortexFormat {
@@ -81,6 +82,7 @@ impl Eq for VortexOptions {}
8182pub struct VortexFormatFactory {
8283 session : Arc < VortexSession > ,
8384 options : Option < VortexOptions > ,
85+ write_options_factory : Option < VortexWriteOptionsFactory > ,
8486}
8587
8688impl GetExt for VortexFormatFactory {
@@ -96,16 +98,7 @@ impl VortexFormatFactory {
9698 Self {
9799 session : Arc :: new ( VortexSession :: default ( ) ) ,
98100 options : None ,
99- }
100- }
101-
102- /// Creates a new instance with customized session and default options for all [`VortexFormat`] instances created from this factory.
103- ///
104- /// The options can be overridden by table-level configuration pass in [`FileFormatFactory::create`].
105- pub fn new_with_options ( session : Arc < VortexSession > , options : VortexOptions ) -> Self {
106- Self {
107- session,
108- options : Some ( options) ,
101+ write_options_factory : None ,
109102 }
110103 }
111104
@@ -121,6 +114,23 @@ impl VortexFormatFactory {
121114 self . options = Some ( options) ;
122115 self
123116 }
117+
118+ /// Override the default write options for this factory.
119+ ////
120+ /// For example:
121+ /// ```rust
122+ /// use vortex_datafusion::VortexFormatFactory;
123+ /// use vortex::file::VortexWriteOptionsFactory;
124+ ///
125+ /// let factory = VortexFormatFactory::new().with_write_options(VortexWriteOptionsFactory::default());
126+ /// ```
127+ pub fn with_write_options_factory (
128+ mut self ,
129+ write_options_factory : VortexWriteOptionsFactory ,
130+ ) -> Self {
131+ self . write_options_factory = Some ( write_options_factory) ;
132+ self
133+ }
124134}
125135
126136impl FileFormatFactory for VortexFormatFactory {
@@ -139,10 +149,13 @@ impl FileFormatFactory for VortexFormatFactory {
139149 }
140150 }
141151
142- Ok ( Arc :: new ( VortexFormat :: new_with_options (
143- self . session . clone ( ) ,
144- opts,
145- ) ) )
152+ let write_opts = self . write_options_factory . clone ( ) . unwrap_or_default ( ) ;
153+
154+ Ok ( Arc :: new (
155+ VortexFormat :: new ( self . session . clone ( ) )
156+ . with_options ( opts)
157+ . with_write_options_factory ( write_opts) ,
158+ ) )
146159 }
147160
148161 fn default ( & self ) -> Arc < dyn FileFormat > {
@@ -163,11 +176,7 @@ impl Default for VortexFormat {
163176impl VortexFormat {
164177 /// Create a new instance with default options.
165178 pub fn new ( session : Arc < VortexSession > ) -> Self {
166- Self :: new_with_options ( session, VortexOptions :: default ( ) )
167- }
168-
169- /// Creates a new instance with configured by a [`VortexOptions`].
170- pub fn new_with_options ( session : Arc < VortexSession > , opts : VortexOptions ) -> Self {
179+ let opts = VortexOptions :: default ( ) ;
171180 Self {
172181 session : session. clone ( ) ,
173182 file_cache : VortexFileCache :: new (
@@ -176,13 +185,48 @@ impl VortexFormat {
176185 session,
177186 ) ,
178187 opts,
188+ write_options_factory : VortexWriteOptionsFactory :: default ( ) . into ( ) ,
179189 }
180190 }
181191
192+ /// Override the default options for this format.
193+ ////
194+ /// For example:
195+ /// ```rust
196+ /// use vortex_datafusion::{VortexFormat, VortexOptions};
197+ ///
198+ /// let format = VortexFormat::default().with_options(VortexOptions::default());
199+ /// ```
200+ pub fn with_options ( mut self , opts : VortexOptions ) -> Self {
201+ self . opts = opts;
202+ self
203+ }
204+
205+ /// Override the default write options for this format.
206+ //// For example:
207+ /// ```rust
208+ /// use vortex_datafusion::VortexFormat;
209+ /// use vortex::file::VortexWriteOptions;
210+ ///
211+ /// let format = VortexFormat::default().with_write_options(VortexWriteOptions::default());
212+ /// ```
213+ pub fn with_write_options_factory (
214+ mut self ,
215+ write_options_factory : impl Into < Arc < VortexWriteOptionsFactory > > ,
216+ ) -> Self {
217+ self . write_options_factory = write_options_factory. into ( ) ;
218+ self
219+ }
220+
182221 /// Return the format specific configuration
183222 pub fn options ( & self ) -> & VortexOptions {
184223 & self . opts
185224 }
225+
226+ /// Return the write options
227+ pub fn write_options_factory ( & self ) -> Arc < VortexWriteOptionsFactory > {
228+ Arc :: clone ( & self . write_options_factory )
229+ }
186230}
187231
188232#[ async_trait]
@@ -395,7 +439,7 @@ impl FileFormat for VortexFormat {
395439 }
396440
397441 let schema = conf. output_schema ( ) . clone ( ) ;
398- let sink = Arc :: new ( VortexSink :: new ( conf, schema) ) ;
442+ let sink = Arc :: new ( VortexSink :: new ( conf, schema, self . write_options_factory ( ) ) ) ;
399443
400444 Ok ( Arc :: new ( DataSinkExec :: new ( input, sink, order_requirements) ) as _ )
401445 }
0 commit comments