Skip to content

Commit

Permalink
[POAE7-1497] The TypeConvetor of Substrait utils code refactor (faceb…
Browse files Browse the repository at this point in the history
…ookincubator#7)

* Pass project Tests for round-trip trans when batchSize=1

* clean some debug info

* change code style and using log instead of cout

* Pass project Tests for round-trip plan transform

* use full names for more readable in tests

* Pass FilterNode Tests for round-trip plan transform

* [POAE7-1448] Add AggregateNode, nullValue APIs and pass six tests about transform from velox to substrait

* address the comments

* [POAE7-1448] pass the round-trip test of aggregatesNode

* address comments and update the url of substrait submodule

* [POAE7-1497] The header and CMake files after refine

* [POAE7-1497] The header and CMake files after refine

* address comments

* [POAE7-1497]the TypeConvertor of Substrait utils code refactor

* [POAE7-1497]the GlobalCommonVariable of Substrait utils code refactor

* remove header file except TypeConvertor

* make global variables into a singleton class
  • Loading branch information
ZJie1 authored Feb 24, 2022
1 parent 7b89cf2 commit f211c83
Show file tree
Hide file tree
Showing 5 changed files with 664 additions and 1 deletion.
4 changes: 3 additions & 1 deletion velox/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ add_library(
Unnest.cpp
Values.cpp
VectorHasher.cpp
SubstraitIRConverter.cpp)
SubstraitIRConverter.cpp
SubstraitVeloxTypeConvertor.cpp
GlobalCommonVariable.cpp)

find_library(cider cider)

Expand Down
44 changes: 44 additions & 0 deletions velox/exec/GlobalCommonVariable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "GlobalCommonVariable.h"

namespace facebook::velox {

GlobalCommonVarSingleton& GlobalCommonVarSingleton::getInstance() {
static GlobalCommonVarSingleton instance;
return instance;
}

io::substrait::Plan* GlobalCommonVarSingleton::getSPlan() const {
return sPlan_;
}
void GlobalCommonVarSingleton::setSPlan(io::substrait::Plan* s_plan) {
sPlan_ = s_plan;
}
const std::unordered_map<uint64_t, std::string>&
GlobalCommonVarSingleton::getFunctionsMap() const {
return functions_map_;
}
void GlobalCommonVarSingleton::setFunctionsMap(
const std::unordered_map<uint64_t, std::string>& functions_map) {
functions_map_ = functions_map;
}
// Substrait is ordinal based field reference implementation. sGlobalMapping
// is used to tracked the mapping from ID to field reference.
io::substrait::Type_NamedStruct* sGlobalMapping_ =
new io::substrait::Type_NamedStruct();
} // namespace facebook::velox
51 changes: 51 additions & 0 deletions velox/exec/GlobalCommonVariable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "plan.pb.h"

namespace facebook::velox {
class GlobalCommonVarSingleton {
public:
static GlobalCommonVarSingleton& getInstance();
GlobalCommonVarSingleton(GlobalCommonVarSingleton const&) = delete;
GlobalCommonVarSingleton& operator=(GlobalCommonVarSingleton const&) = delete;
~GlobalCommonVarSingleton(){};

io::substrait::Plan* getSPlan() const;
void setSPlan(io::substrait::Plan* s_plan);
const std::unordered_map<uint64_t, std::string>& getFunctionsMap() const;
void setFunctionsMap(
const std::unordered_map<uint64_t, std::string>& functions_map);

protected:
// An intermediate variable to help us get the corresponding function mapping
// relationship when convert from substrait to velox
io::substrait::Plan* sPlan_;

// parse the function mapping from substrait plan.
std::unordered_map<uint64_t, std::string> functions_map_;

private:
GlobalCommonVarSingleton()
: sPlan_(new io::substrait::Plan), functions_map_({{0, ""}}){};
};

// Substrait is ordinal based field reference implementation. sGlobalMapping
// is used to tracked the mapping from ID to field reference.
extern io::substrait::Type_NamedStruct* sGlobalMapping_;
} // namespace facebook::velox
Loading

0 comments on commit f211c83

Please sign in to comment.