Skip to content

Commit

Permalink
Rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Dec 11, 2024
1 parent 08316c9 commit db5c652
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 44 deletions.
3 changes: 2 additions & 1 deletion cpp/core/compute/Runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "utils/Registry.h"

namespace gluten {

namespace {

Registry<Runtime::Factory>& runtimeFactories() {
static Registry<Runtime::Factory> registry;
return registry;
Expand All @@ -29,6 +29,7 @@ Registry<Runtime::Releaser>& runtimeReleasers() {
static Registry<Runtime::Releaser> registry;
return registry;
}

} // namespace

void Runtime::registerFactory(const std::string& kind, Runtime::Factory factory, Runtime::Releaser releaser) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/core/utils/ObjectStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ gluten::ObjectHandle gluten::ObjectStore::save(std::shared_ptr<void> obj) {
return toObjHandle(handle);
}

void gluten::ObjectStore::release0(gluten::ResourceHandle handle) {
void gluten::ObjectStore::releaseInternal(gluten::ResourceHandle handle) {
const std::lock_guard<std::mutex> lock(mtx_);
store_.erase(handle);
aliveObjects_.erase(handle);
Expand Down
8 changes: 4 additions & 4 deletions cpp/core/utils/ObjectStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class ObjectStore {
ResourceHandle storeId = safeCast<ResourceHandle>(handle >> (sizeof(ResourceHandle) * 8));
ResourceHandle resourceId = safeCast<ResourceHandle>(handle & std::numeric_limits<ResourceHandle>::max());
auto store = stores().lookup(storeId);
store->release0(resourceId);
store->releaseInternal(resourceId);
}

template <typename T>
static std::shared_ptr<T> retrieve(ObjectHandle handle) {
ResourceHandle storeId = safeCast<ResourceHandle>(handle >> (sizeof(ResourceHandle) * 8));
ResourceHandle resourceId = safeCast<ResourceHandle>(handle & std::numeric_limits<ResourceHandle>::max());
auto store = stores().lookup(storeId);
return store->retrieve0<T>(resourceId);
return store->retrieveInternal<T>(resourceId);
}

virtual ~ObjectStore();
Expand All @@ -82,15 +82,15 @@ class ObjectStore {
}

template <typename T>
std::shared_ptr<T> retrieve0(ResourceHandle handle) {
std::shared_ptr<T> retrieveInternal(ResourceHandle handle) {
const std::lock_guard<std::mutex> lock(mtx_);
std::shared_ptr<void> object = store_.lookup(handle);
// Programming carefully. This will lead to ub if wrong typename T was passed in.
auto casted = std::static_pointer_cast<T>(object);
return casted;
}

void release0(ResourceHandle handle);
void releaseInternal(ResourceHandle handle);

ObjectStore(StoreHandle storeId) : storeId_(storeId){};
StoreHandle storeId_;
Expand Down
10 changes: 5 additions & 5 deletions cpp/velox/jni/JniFileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class JniReadFile : public facebook::velox::ReadFile {

~JniReadFile() override {
try {
close0();
closeInternal();
JNIEnv* env = nullptr;
attachCurrentThreadAsDaemonOrThrow(vm, &env);
env->DeleteGlobalRef(obj_);
Expand Down Expand Up @@ -130,7 +130,7 @@ class JniReadFile : public facebook::velox::ReadFile {
}

private:
void close0() {
void closeInternal() {
JNIEnv* env = nullptr;
attachCurrentThreadAsDaemonOrThrow(vm, &env);
env->CallVoidMethod(obj_, jniReadFileClose);
Expand All @@ -151,7 +151,7 @@ class JniWriteFile : public facebook::velox::WriteFile {

~JniWriteFile() override {
try {
close0();
closeInternal();
JNIEnv* env = nullptr;
attachCurrentThreadAsDaemonOrThrow(vm, &env);
env->DeleteGlobalRef(obj_);
Expand All @@ -178,7 +178,7 @@ class JniWriteFile : public facebook::velox::WriteFile {
}

void close() override {
close0();
closeInternal();
}

uint64_t size() const override {
Expand All @@ -190,7 +190,7 @@ class JniWriteFile : public facebook::velox::WriteFile {
}

private:
void close0() {
void closeInternal() {
JNIEnv* env = nullptr;
attachCurrentThreadAsDaemonOrThrow(vm, &env);
env->CallVoidMethod(obj_, jniWriteFileClose);
Expand Down
10 changes: 5 additions & 5 deletions cpp/velox/memory/VeloxMemoryManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ListenableArbitrator : public velox::memory::MemoryArbitrator {
}
VELOX_CHECK(pool->root() == candidate, "Illegal state in ListenableArbitrator");

growCapacity0(pool->root(), targetBytes);
growCapacityInternal(pool->root(), targetBytes);
return true;
}

Expand All @@ -133,11 +133,11 @@ class ListenableArbitrator : public velox::memory::MemoryArbitrator {
pool = candidates_.begin()->first;
}
pool->reclaim(targetBytes, memoryReclaimMaxWaitMs_, status); // ignore the output
return shrinkCapacity0(pool, 0);
return shrinkCapacityInternal(pool, 0);
}

uint64_t shrinkCapacity(velox::memory::MemoryPool* pool, uint64_t targetBytes) override {
return shrinkCapacity0(pool, targetBytes);
return shrinkCapacityInternal(pool, targetBytes);
}

Stats stats() const override {
Expand All @@ -150,7 +150,7 @@ class ListenableArbitrator : public velox::memory::MemoryArbitrator {
}

private:
void growCapacity0(velox::memory::MemoryPool* pool, uint64_t bytes) {
void growCapacityInternal(velox::memory::MemoryPool* pool, uint64_t bytes) {
// Since
// https://github.com/facebookincubator/velox/pull/9557/files#diff-436e44b7374032f8f5d7eb45869602add6f955162daa2798d01cc82f8725724dL812-L820,
// We should pass bytes as parameter "reservationBytes" when calling ::grow.
Expand All @@ -172,7 +172,7 @@ class ListenableArbitrator : public velox::memory::MemoryArbitrator {
pool->toString());
}

uint64_t shrinkCapacity0(velox::memory::MemoryPool* pool, uint64_t bytes) {
uint64_t shrinkCapacityInternal(velox::memory::MemoryPool* pool, uint64_t bytes) {
uint64_t freeBytes = shrinkPool(pool, bytes);
listener_->allocationChanged(-freeBytes);
return freeBytes;
Expand Down
8 changes: 4 additions & 4 deletions cpp/velox/shuffle/VeloxSortShuffleWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ arrow::Status VeloxSortShuffleWriter::evictPartition(uint32_t partitionId, size_
size = *(RowSizeType*)addr;
if (offset + size > options_.compressionBufferSize && offset > 0) {
sortTime.stop();
RETURN_NOT_OK(evictPartition0(partitionId, index - begin, rawBuffer_, offset));
RETURN_NOT_OK(evictPartitionInternal(partitionId, index - begin, rawBuffer_, offset));
sortTime.start();
begin = index;
offset = 0;
Expand All @@ -310,7 +310,7 @@ arrow::Status VeloxSortShuffleWriter::evictPartition(uint32_t partitionId, size_
while (bytes < size) {
auto rawLength = std::min<RowSizeType>((uint32_t)options_.compressionBufferSize, size - bytes);
// Use numRows = 0 to represent a part of row.
RETURN_NOT_OK(evictPartition0(partitionId, 0, buffer + bytes, rawLength));
RETURN_NOT_OK(evictPartitionInternal(partitionId, 0, buffer + bytes, rawLength));
bytes += rawLength;
}
begin++;
Expand All @@ -325,14 +325,14 @@ arrow::Status VeloxSortShuffleWriter::evictPartition(uint32_t partitionId, size_
sortTime.stop();
if (offset > 0) {
VELOX_CHECK(index > begin);
RETURN_NOT_OK(evictPartition0(partitionId, index - begin, rawBuffer_, offset));
RETURN_NOT_OK(evictPartitionInternal(partitionId, index - begin, rawBuffer_, offset));
}
sortTime_ += sortTime.realTimeUsed();
return arrow::Status::OK();
}

arrow::Status
VeloxSortShuffleWriter::evictPartition0(uint32_t partitionId, int32_t numRows, uint8_t* buffer, int64_t rawLength) {
VeloxSortShuffleWriter::evictPartitionInternal(uint32_t partitionId, int32_t numRows, uint8_t* buffer, int64_t rawLength) {
VELOX_CHECK(rawLength > 0);
auto payload = std::make_unique<InMemoryPayload>(
numRows,
Expand Down
2 changes: 1 addition & 1 deletion cpp/velox/shuffle/VeloxSortShuffleWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class VeloxSortShuffleWriter final : public VeloxShuffleWriter {

arrow::Status evictPartition(uint32_t partitionId, size_t begin, size_t end);

arrow::Status evictPartition0(uint32_t partitionId, int32_t numRows, uint8_t* buffer, int64_t rawLength);
arrow::Status evictPartitionInternal(uint32_t partitionId, int32_t numRows, uint8_t* buffer, int64_t rawLength);

facebook::velox::vector_size_t maxRowsToInsert(
facebook::velox::vector_size_t offset,
Expand Down
2 changes: 1 addition & 1 deletion cpp/velox/substrait/SubstraitToVeloxPlan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct EmitInfo {
};

/// Helper function to extract the attributes required to create a ProjectNode
/// used for interpretting Substrait Emit.
/// used for interpreting Substrait Emit.
EmitInfo getEmitInfo(const ::substrait::RelCommon& relCommon, const core::PlanNodePtr& node) {
const auto& emit = relCommon.emit();
int emitSize = emit.output_mapping_size();
Expand Down
34 changes: 17 additions & 17 deletions cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool SubstraitToVeloxPlanValidator::parseVeloxType(
return true;
}

bool SubstraitToVeloxPlanValidator::flattenVeloxType1(const TypePtr& type, std::vector<TypePtr>& out) {
bool SubstraitToVeloxPlanValidator::flattenSingleLevel(const TypePtr& type, std::vector<TypePtr>& out) {
if (type->kind() != TypeKind::ROW) {
LOG_VALIDATION_MSG("Type is not a RowType.");
return false;
Expand All @@ -106,7 +106,7 @@ bool SubstraitToVeloxPlanValidator::flattenVeloxType1(const TypePtr& type, std::
return true;
}

bool SubstraitToVeloxPlanValidator::flattenVeloxType2(const TypePtr& type, std::vector<std::vector<TypePtr>>& out) {
bool SubstraitToVeloxPlanValidator::flattenDualLevel(const TypePtr& type, std::vector<std::vector<TypePtr>>& out) {
if (type->kind() != TypeKind::ROW) {
LOG_VALIDATION_MSG("Type is not a RowType.");
return false;
Expand All @@ -118,7 +118,7 @@ bool SubstraitToVeloxPlanValidator::flattenVeloxType2(const TypePtr& type, std::
}
for (const auto& field : rowType->children()) {
std::vector<TypePtr> inner;
if (!flattenVeloxType1(field, inner)) {
if (!flattenSingleLevel(field, inner)) {
return false;
}
out.emplace_back(inner);
Expand Down Expand Up @@ -371,7 +371,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::WriteRel& writeR
std::vector<TypePtr> types;
if (writeRel.has_named_table()) {
const auto& extension = writeRel.named_table().advanced_extension();
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input type validation in WriteRel.");
return false;
}
Expand Down Expand Up @@ -412,7 +412,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::FetchRel& fetchR
const auto& extension = fetchRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Unsupported input types in FetchRel.");
return false;
}
Expand Down Expand Up @@ -440,7 +440,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::TopNRel& topNRel
const auto& extension = topNRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Unsupported input types in TopNRel.");
return false;
}
Expand Down Expand Up @@ -486,7 +486,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::GenerateRel& gen
const auto& extension = generateRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input types in GenerateRel.");
return false;
}
Expand Down Expand Up @@ -517,7 +517,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::ExpandRel& expan
const auto& extension = expandRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Unsupported input types in ExpandRel.");
return false;
}
Expand Down Expand Up @@ -602,7 +602,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::WindowRel& windo
const auto& extension = windowRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input types in WindowRel.");
return false;
}
Expand Down Expand Up @@ -731,7 +731,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::WindowGroupLimit
const auto& extension = windowGroupLimitRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input types in WindowGroupLimitRel.");
return false;
}
Expand Down Expand Up @@ -805,7 +805,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::SetRel& setRel)
const auto& extension = setRel.advanced_extension();
TypePtr inputRowType;
std::vector<std::vector<TypePtr>> childrenTypes;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType2(inputRowType, childrenTypes)) {
if (!parseVeloxType(extension, inputRowType) || !flattenDualLevel(inputRowType, childrenTypes)) {
LOG_VALIDATION_MSG("Validation failed for input types in SetRel.");
return false;
}
Expand Down Expand Up @@ -850,7 +850,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::SortRel& sortRel
const auto& extension = sortRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input types in SortRel.");
return false;
}
Expand Down Expand Up @@ -904,7 +904,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::ProjectRel& proj
const auto& extension = projectRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input types in ProjectRel.");
return false;
}
Expand Down Expand Up @@ -948,7 +948,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::FilterRel& filte
const auto& extension = filterRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input types in FilterRel.");
return false;
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::JoinRel& joinRel
const auto& extension = joinRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
LOG_VALIDATION_MSG("Validation failed for input types in JoinRel.");
return false;
}
Expand Down Expand Up @@ -1076,7 +1076,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::CrossRel& crossR
const auto& extension = crossRel.advanced_extension();
TypePtr inputRowType;
std::vector<TypePtr> types;
if (!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types)) {
if (!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types)) {
logValidateMsg("Native validation failed due to: Validation failed for input types in CrossRel");
return false;
}
Expand Down Expand Up @@ -1160,7 +1160,7 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::AggregateRel& ag
// Aggregate always has advanced extension for streaming aggregate optimization,
// but only some of them have enhancement for validation.
if (extension.has_enhancement() &&
(!parseVeloxType(extension, inputRowType) || !flattenVeloxType1(inputRowType, types))) {
(!parseVeloxType(extension, inputRowType) || !flattenSingleLevel(inputRowType, types))) {
LOG_VALIDATION_MSG("Validation failed for input types in AggregateRel.");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/velox/substrait/SubstraitToVeloxPlanValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class SubstraitToVeloxPlanValidator {
bool parseVeloxType(const ::substrait::extensions::AdvancedExtension& extension, TypePtr& out);

/// Flattens a Velox type with single level of nesting into a std::vector of child types.
bool flattenVeloxType1(const TypePtr& type, std::vector<TypePtr>& out);
bool flattenSingleLevel(const TypePtr& type, std::vector<TypePtr>& out);

/// Flattens a Velox type with two level of nesting into a dual-nested std::vector of child types.
bool flattenVeloxType2(const TypePtr& type, std::vector<std::vector<TypePtr>>& out);
bool flattenDualLevel(const TypePtr& type, std::vector<std::vector<TypePtr>>& out);

/// Validate aggregate rel.
bool validateAggRelFunctionType(const ::substrait::AggregateRel& substraitAgg);
Expand Down
4 changes: 2 additions & 2 deletions cpp/velox/udf/UdfLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ namespace gluten {

void UdfLoader::loadUdfLibraries(const std::string& libPaths) {
const auto& paths = splitPaths(libPaths, /*checkExists=*/true);
loadUdfLibraries0(paths);
loadUdfLibrariesInternal(paths);
}

void UdfLoader::loadUdfLibraries0(const std::vector<std::string>& libPaths) {
void UdfLoader::loadUdfLibrariesInternal(const std::vector<std::string>& libPaths) {
for (const auto& libPath : libPaths) {
if (handles_.find(libPath) == handles_.end()) {
void* handle = dlopen(libPath.c_str(), RTLD_LAZY);
Expand Down
2 changes: 1 addition & 1 deletion cpp/velox/udf/UdfLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class UdfLoader {
void registerUdf();

private:
void loadUdfLibraries0(const std::vector<std::string>& libPaths);
void loadUdfLibrariesInternal(const std::vector<std::string>& libPaths);

std::string toSubstraitTypeStr(const std::string& type);

Expand Down

0 comments on commit db5c652

Please sign in to comment.