|
26 | 26 | #include "utils/ConfigExtractor.h" |
27 | 27 | #include "velox/connectors/hive/iceberg/IcebergDataSink.h" |
28 | 28 | #include "velox/connectors/hive/iceberg/IcebergDeleteFile.h" |
| 29 | +#include "velox/dwio/common/WriterFactory.h" |
| 30 | +#include "velox/dwio/dwrf/writer/Writer.h" |
29 | 31 |
|
30 | 32 | using namespace facebook::velox; |
31 | 33 | using namespace facebook::velox::connector::hive; |
32 | 34 | using namespace facebook::velox::connector::hive::iceberg; |
33 | 35 | namespace { |
34 | 36 |
|
| 37 | +class IcebergOrcWriterFactory final : public dwio::common::WriterFactory { |
| 38 | + public: |
| 39 | + IcebergOrcWriterFactory() : WriterFactory(dwio::common::FileFormat::ORC) {} |
| 40 | + |
| 41 | + std::unique_ptr<dwio::common::Writer> createWriter( |
| 42 | + std::unique_ptr<dwio::common::FileSink> sink, |
| 43 | + const std::shared_ptr<dwio::common::WriterOptions>& options) override { |
| 44 | + auto orcOptions = std::dynamic_pointer_cast<dwrf::WriterOptions>(options); |
| 45 | + VELOX_CHECK_NOT_NULL(orcOptions, "Iceberg ORC writer expected DWRF writer options."); |
| 46 | + VELOX_CHECK_EQ(orcOptions->format, dwrf::DwrfFormat::kOrc); |
| 47 | + return std::make_unique<dwrf::Writer>(std::move(sink), *orcOptions); |
| 48 | + } |
| 49 | + |
| 50 | + std::unique_ptr<dwio::common::WriterOptions> createWriterOptions() override { |
| 51 | + auto options = std::make_unique<dwrf::WriterOptions>(); |
| 52 | + options->format = dwrf::DwrfFormat::kOrc; |
| 53 | + return options; |
| 54 | + } |
| 55 | +}; |
| 56 | + |
35 | 57 | // Custom Iceberg file name generator for Gluten |
36 | 58 | class GlutenIcebergFileNameGenerator : public connector::hive::FileNameGenerator { |
37 | 59 | public: |
@@ -175,6 +197,10 @@ std::shared_ptr<IcebergInsertTableHandle> createIcebergInsertTableHandle( |
175 | 197 | } // namespace |
176 | 198 |
|
177 | 199 | namespace gluten { |
| 200 | +void registerIcebergOrcWriterFactory() { |
| 201 | + dwio::common::registerWriterFactory(std::make_shared<IcebergOrcWriterFactory>()); |
| 202 | +} |
| 203 | + |
178 | 204 | IcebergWriter::IcebergWriter( |
179 | 205 | const RowTypePtr& rowType, |
180 | 206 | int32_t format, |
|
0 commit comments