2020
2121namespace csp ::adapters::parquet
2222{
23+
2324namespace
2425{
2526
@@ -70,7 +71,7 @@ std::shared_ptr<::arrow::io::OutputStream> openOutputStream( const std::string &
7071}
7172
7273FileWriter makeParquetFileWriter ( const std::string & path, const std::shared_ptr<::arrow::Schema> & schema,
73- const std::string & compression, bool allowOverwrite )
74+ const std::string & compression, bool allowOverwrite, bool useDictionary )
7475{
7576 auto stream = openOutputStream ( path, allowOverwrite );
7677
@@ -80,6 +81,11 @@ FileWriter makeParquetFileWriter( const std::string & path, const std::shared_pt
8081 // Arrow 6.0) is always present, so there is no need to gate on the Arrow version or fall back to
8182 // the deprecated PARQUET_2_0.
8283 props.version ( ::parquet::ParquetVersion::PARQUET_2_6 );
84+ // Dictionary encoding is on by default. For high-cardinality numeric columns it is a large write-time
85+ // cost (hash table build) and can even grow files; allow it to be turned off (trading file size for
86+ // write throughput). Low-cardinality columns still benefit from leaving it on (the default).
87+ if ( !useDictionary )
88+ props.disable_dictionary ();
8389 ::parquet::ArrowWriterProperties::Builder arrowProps;
8490 arrowProps.store_schema (); // preserve arrow (file/column) schema metadata in the parquet file
8591
@@ -204,16 +210,17 @@ FileWriter makeSplitWriter( const std::string & dir, const std::shared_ptr<::arr
204210
205211RecordBatchSink makeFileSink ( bool writeArrowBinary, bool splitColumns,
206212 const std::string & compression, bool allowOverwrite,
207- std::function<void ( const std::string & )> fileVisitor )
213+ std::function<void ( const std::string & )> fileVisitor,
214+ bool useDictionary )
208215{
209216 const std::string extension = writeArrowBinary ? " .arrow" : " .parquet" ;
210217
211218 // Per-file factory: format choice is the only difference.
212219 FileWriterFactory perFile =
213- [writeArrowBinary, compression, allowOverwrite]( const std::string & path, const std::shared_ptr<::arrow::Schema> & schema )
220+ [writeArrowBinary, compression, allowOverwrite, useDictionary ]( const std::string & path, const std::shared_ptr<::arrow::Schema> & schema )
214221 {
215222 return writeArrowBinary ? makeIpcFileWriter ( path, schema, compression, allowOverwrite )
216- : makeParquetFileWriter ( path, schema, compression, allowOverwrite );
223+ : makeParquetFileWriter ( path, schema, compression, allowOverwrite, useDictionary );
217224 };
218225
219226 // Layout choice: single file vs. one file per column.
0 commit comments