Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <fmt/format.h>
#include <folly/Uri.h>

#include "presto_cpp/main/common/Configs.h"
#include "presto_cpp/main/operators/BroadcastExchangeSource.h"

using namespace facebook::velox;
Expand Down Expand Up @@ -133,12 +132,14 @@ BroadcastExchangeSource::createExchangeSource(
VELOX_USER_FAIL("BroadcastInfo deserialization failed: {}", e.what());
}

auto fileSystemBroadcast = BroadcastFactory(broadcastFileInfo->filePath_);
auto fileSystem =
velox::filesystems::getFileSystem(broadcastFileInfo->filePath_, nullptr);
return std::make_shared<BroadcastExchangeSource>(
uri.host(),
destination,
queue,
fileSystemBroadcast.createReader(std::move(broadcastFileInfo), pool),
std::make_shared<BroadcastFileReader>(
broadcastFileInfo, fileSystem, pool),
pool);
}
} // namespace facebook::presto::operators
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
*/
#pragma once

#include "presto_cpp/main/operators/BroadcastFactory.h"
#include "velox/core/PlanNode.h"
#include "velox/exec/Exchange.h"
#include "velox/exec/Operator.h"
#include "presto_cpp/main/operators/BroadcastFile.h"
#include "velox/exec/ExchangeQueue.h"
#include "velox/exec/ExchangeSource.h"

namespace facebook::presto::operators {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "presto_cpp/main/operators/BroadcastFactory.h"
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "presto_cpp/main/operators/BroadcastFile.h"
#include "presto_cpp/external/json/nlohmann/json.hpp"
#include "presto_cpp/main/common/Exception.h"
#include "presto_cpp/main/thrift/ThriftIO.h"
Expand All @@ -39,40 +36,6 @@ namespace facebook::presto::operators {
"{}", \
errorMessage);

namespace {
std::string makeUuid() {
return boost::lexical_cast<std::string>(boost::uuids::random_generator()());
}
} // namespace

BroadcastFactory::BroadcastFactory(const std::string& basePath)
: basePath_(basePath) {
VELOX_CHECK(!basePath.empty(), "Base path for broadcast files is empty!");
fileSystem_ = velox::filesystems::getFileSystem(basePath, nullptr);
}

std::unique_ptr<BroadcastFileWriter> BroadcastFactory::createWriter(
uint64_t writeBufferSize,
uint64_t maxBroadcastBytes,
velox::memory::MemoryPool* pool,
std::unique_ptr<VectorSerde::Options> serdeOptions) {
fileSystem_->mkdir(basePath_);
return std::make_unique<BroadcastFileWriter>(
fmt::format("{}/file_broadcast_{}", basePath_, makeUuid()),
maxBroadcastBytes,
writeBufferSize,
std::move(serdeOptions),
pool);
}

std::shared_ptr<BroadcastFileReader> BroadcastFactory::createReader(
std::unique_ptr<BroadcastFileInfo> fileInfo,
velox::memory::MemoryPool* pool) {
auto broadcastFileReader =
std::make_shared<BroadcastFileReader>(fileInfo, fileSystem_, pool);
return broadcastFileReader;
}

// static
std::unique_ptr<BroadcastFileInfo> BroadcastFileInfo::deserialize(
const std::string& info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,4 @@ class BroadcastFileReader {
uint32_t numPagesRead_{0};
std::vector<int64_t> pageSizes_;
};

/// Factory to create Writers & Reader for file based broadcast.
class BroadcastFactory {
public:
/// Create FileBroadcast to write files under specified basePath.
BroadcastFactory(const std::string& basePath);

virtual ~BroadcastFactory() = default;

std::unique_ptr<BroadcastFileWriter> createWriter(
uint64_t writeBufferSize,
uint64_t maxBroadcastBytes,
velox::memory::MemoryPool* pool,
std::unique_ptr<velox::VectorSerde::Options> serdeOptions);

std::shared_ptr<BroadcastFileReader> createReader(
const std::unique_ptr<BroadcastFileInfo> fileInfo,
velox::memory::MemoryPool* pool);

private:
const std::string basePath_;
std::shared_ptr<velox::filesystems::FileSystem> fileSystem_;
};
} // namespace facebook::presto::operators
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
* limitations under the License.
*/
#include "presto_cpp/main/operators/BroadcastWrite.h"
#include "presto_cpp/main/common/Configs.h"
#include "presto_cpp/main/operators/BroadcastFactory.h"
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "presto_cpp/main/operators/BroadcastFile.h"
#include "velox/common/file/FileSystems.h"

using namespace facebook::velox::exec;
using namespace facebook::velox;

namespace facebook::presto::operators {
namespace {
std::string makeUuid() {
return boost::lexical_cast<std::string>(boost::uuids::random_generator()());
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be placed in a utility class?

}

velox::core::PlanNodeId deserializePlanNodeId(const folly::dynamic& obj) {
return obj["id"].asString();
}
Expand Down Expand Up @@ -58,12 +65,16 @@ class BroadcastWriteOperator : public Operator {
planNode->serdeRowType(),
planNode->serdeRowType())),
maxBroadcastBytes_(planNode->maxBroadcastBytes()) {
auto fileBroadcast = BroadcastFactory(planNode->basePath());
fileBroadcastWriter_ = fileBroadcast.createWriter(
8 << 20,
const auto& basePath = planNode->basePath();
VELOX_CHECK(!basePath.empty(), "Base path for broadcast files is empty!");
auto fileSystem = velox::filesystems::getFileSystem(basePath, nullptr);
fileSystem->mkdir(basePath);
fileBroadcastWriter_ = std::make_unique<BroadcastFileWriter>(
fmt::format("{}/file_broadcast_{}", basePath, makeUuid()),
planNode->maxBroadcastBytes(),
operatorCtx_->pool(),
getVectorSerdeOptions(ctx->queryConfig(), VectorSerde::Kind::kPresto));
8 << 20,
getVectorSerdeOptions(ctx->queryConfig(), VectorSerde::Kind::kPresto),
operatorCtx_->pool());
}

bool needsInput() const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add_library(
ShuffleWrite.cpp
LocalShuffle.cpp
BroadcastWrite.cpp
BroadcastFactory.cpp
BroadcastFile.cpp
BroadcastExchangeSource.cpp
BinarySortableSerializer.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
#include <folly/Uri.h>
#include "presto_cpp/main/common/Exception.h"
#include "presto_cpp/main/operators/BroadcastExchangeSource.h"
#include "presto_cpp/main/operators/BroadcastFile.h"
#include "presto_cpp/main/operators/BroadcastWrite.h"
#include "presto_cpp/main/operators/tests/PlanBuilder.h"
#include "velox/buffer/Buffer.h"
#include "velox/common/base/tests/GTestUtils.h"
#include "velox/common/compression/Compression.h"
#include "velox/common/file/FileSystems.h"
#include "velox/core/QueryConfig.h"
#include "velox/exec/Exchange.h"
#include "velox/exec/ExchangeSource.h"
#include "velox/exec/tests/utils/OperatorTestBase.h"
#include "velox/exec/tests/utils/PlanBuilder.h"
#include "velox/exec/tests/utils/QueryAssertions.h"
Expand Down
Loading