Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VL] Add support to write parquet files to GCS #3978

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/velox/benchmarks/ParquetWriteBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class GoogleBenchmarkVeloxParquetWriteCacheScanBenchmark : public GoogleBenchmar
outputPath_ + "/" + fileName,
veloxPool->addAggregateChild("writer_benchmark"),
veloxPool->addLeafChild("s3_sink_pool"),
veloxPool->addLeafChild("gcs_sink_pool"),
localSchema);

veloxParquetDatasource->init(runtime->getConfMap());
Expand Down
5 changes: 3 additions & 2 deletions cpp/velox/compute/VeloxRuntime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,12 @@ std::shared_ptr<Datasource> VeloxRuntime::createDatasource(
std::shared_ptr<arrow::Schema> schema) {
static std::atomic_uint32_t id{0UL};
auto veloxPool = getAggregateVeloxPool(memoryManager)->addAggregateChild("datasource." + std::to_string(id++));
// Pass a dedicate pool for S3 sink as can't share veloxPool
// Pass a dedicate pool for S3 and GCS sinks as can't share veloxPool
// with parquet writer.
auto s3SinkPool = getLeafVeloxPool(memoryManager);
auto gcsSinkPool = getLeafVeloxPool(memoryManager);

return std::make_shared<VeloxParquetDatasource>(filePath, veloxPool, s3SinkPool, schema);
return std::make_shared<VeloxParquetDatasource>(filePath, veloxPool, s3SinkPool, gcsSinkPool, schema);
}

std::shared_ptr<ShuffleReader> VeloxRuntime::createShuffleReader(
Expand Down
10 changes: 10 additions & 0 deletions cpp/velox/operators/writer/VeloxParquetDatasource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ void VeloxParquetDatasource::init(const std::unordered_map<std::string, std::str
#else
throw std::runtime_error(
"The write path is S3 path but the S3 haven't been enabled when writing parquet data in velox runtime!");
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, Let's move the logic to independent file and compile the file depends on compile flag. Let's avoid to use ifdef ENABLE_S3/GCS etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but please read my previous answer.

} else if (strncmp(filePath_.c_str(), "gs:", 3) == 0) {
#ifdef ENABLE_GCS
auto fileSystem = getFileSystem(filePath_, nullptr);
auto* gcsFileSystem = dynamic_cast<filesystems::GCSFileSystem*>(fileSystem.get());
sink_ = std::make_unique<dwio::common::WriteFileSink>(
gcsFileSystem->openFileForWrite(filePath_, {{}, gcsSinkPool_.get()}), filePath_);
#else
throw std::runtime_error(
"The write path is GCS path but the GCS haven't been enabled when writing parquet data in velox runtime!");
#endif
} else if (strncmp(filePath_.c_str(), "hdfs:", 5) == 0) {
#ifdef ENABLE_HDFS
Expand Down
8 changes: 7 additions & 1 deletion cpp/velox/operators/writer/VeloxParquetDatasource.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include "velox/connectors/hive/storage_adapters/s3fs/S3FileSystem.h"
#include "velox/connectors/hive/storage_adapters/s3fs/S3Util.h"
#endif
#ifdef ENABLE_GCS
#include "velox/connectors/hive/storage_adapters/gcs/GCSFileSystem.h"
#endif
#ifdef ENABLE_HDFS
#include "velox/connectors/hive/storage_adapters/hdfs/HdfsFileSystem.h"
#include "velox/connectors/hive/storage_adapters/hdfs/HdfsUtil.h"
Expand All @@ -54,12 +57,14 @@ class VeloxParquetDatasource final : public Datasource {
const std::string& filePath,
std::shared_ptr<facebook::velox::memory::MemoryPool> veloxPool,
std::shared_ptr<facebook::velox::memory::MemoryPool> s3SinkPool,
std::shared_ptr<facebook::velox::memory::MemoryPool> gcsSinkPool,
std::shared_ptr<arrow::Schema> schema)
: Datasource(filePath, schema),
filePath_(filePath),
schema_(schema),
pool_(std::move(veloxPool)),
s3SinkPool_(std::move(s3SinkPool)) {}
s3SinkPool_(std::move(s3SinkPool)),
gcsSinkPool_(std::move(gcsSinkPool)) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extend the class to VeloxParquetDatsourceS3, VeloxParquetDatsourceGCS and VeloxParquetDatsourceABFS, insted of puting all of them in the same file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the class needs a refactor, but that goes out of the scope of this change.
I propose to make the refactor after this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to onboard ABFS write part native support , @FelixYBW / @tigrux , so i make a refactor PR to address this comment #5486


void init(const std::unordered_map<std::string, std::string>& sparkConfs) override;
void inspectSchema(struct ArrowSchema* out) override;
Expand Down Expand Up @@ -92,6 +97,7 @@ class VeloxParquetDatasource final : public Datasource {
std::shared_ptr<facebook::velox::parquet::Writer> parquetWriter_;
std::shared_ptr<facebook::velox::memory::MemoryPool> pool_;
std::shared_ptr<facebook::velox::memory::MemoryPool> s3SinkPool_;
std::shared_ptr<facebook::velox::memory::MemoryPool> gcsSinkPool_;
std::unique_ptr<facebook::velox::dwio::common::FileSink> sink_;
};

Expand Down
Loading