Skip to content

Commit

Permalink
Some renames reflecting new design changes. (facebookincubator#9)
Browse files Browse the repository at this point in the history
* Rename to reflect some changes in Doc

* Minor changes

* Add OmnisciDB plan translator

* Add to CMakeList file
  • Loading branch information
Ferdinand Xu committed Sep 27, 2021
1 parent da48a69 commit a7b1e54
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 110 deletions.
2 changes: 1 addition & 1 deletion cider/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
# 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.
add_library(cider_core CiderPlanNode.cpp)
add_library(cider_core ComputeIRNode.cpp OmnisciDBTranslator.cpp)
include_directories(.)
27 changes: 27 additions & 0 deletions cider/core/ComputeIRNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 "velox/cider/core/ComputeIRNode.h"
#include <set>
#include <stack>

namespace intel::cider::core {
namespace {
static const std::vector<std::shared_ptr<const ComputeIRNode>> EMPTY_SOURCES;
}

const std::vector<std::shared_ptr<const ComputeIRNode>>&
TableScanIRNode::sources() const {
return EMPTY_SOURCES;
}
} // namespace intel::cider::core
72 changes: 36 additions & 36 deletions cider/core/CiderPlanNode.h → cider/core/ComputeIRNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
#pragma once
#include "string.h"
#include "velox/cider/core/CiderRowExpr.h"
#include "velox/cider/core/IRRowExpr.h"
#include "velox/external/json/json.hpp"
#include "velox/external/map/fifo_map.hpp"

Expand All @@ -24,48 +24,48 @@ using tmp_json = nlohmann::basic_json<tmp_fifo_map>;

namespace intel::cider::core {
typedef std::string PlanNodeId;
class CiderPlanNode {
class ComputeIRNode {
public:
explicit CiderPlanNode(const PlanNodeId& id) : id_{id} {}
explicit ComputeIRNode(const PlanNodeId& id) : id_{id} {}

virtual ~CiderPlanNode() {}
virtual ~ComputeIRNode() {}

const PlanNodeId& id() const {
return id_;
}

virtual const std::vector<std::shared_ptr<const CiderPlanNode>>& sources()
virtual const std::vector<std::shared_ptr<const ComputeIRNode>>& sources()
const = 0;

virtual json toCiderJSON(std::string ciderPlanId) const = 0;
virtual json toOmnisciDBJSON(std::string ciderPlanId) const = 0;

virtual std::string name() const = 0;

/**
* Convert from CiderPlanNode into Cider RelAlg node json string
* @param node as CiderPlanNode
* @return cider RelAlg string
* Convert from IRPlanNode into OmnisciDB RelAlg node json string
* @param node as ComputeIRNode
* @return OmnisciDB RelAlg string
*/
static std::string toCiderRelAlgStr(
const std::shared_ptr<CiderPlanNode>& node);
static std::string toOmnisciDBRelAlgStr(
const std::shared_ptr<ComputeIRNode>& node);

private:
const PlanNodeId id_;
};

class CiderProjectNode : public CiderPlanNode {
class ProjectIRNode : public ComputeIRNode {
public:
CiderProjectNode(
ProjectIRNode(
const PlanNodeId& id,
std::vector<std::string> assignmentKeys,
std::vector<std::shared_ptr<const CiderRowExpr>> assignmentExprs,
std::shared_ptr<const CiderPlanNode> source)
: CiderPlanNode(id),
std::vector<std::shared_ptr<const IRRowExpr>> assignmentExprs,
std::shared_ptr<const ComputeIRNode> source)
: ComputeIRNode(id),
assignmentKeys_{assignmentKeys},
assignmentExprs_(assignmentExprs),
sources_{source} {}

json toCiderJSON(std::string ciderPlanId) const override {
json toOmnisciDBJSON(std::string ciderPlanId) const override {
json projectNode = json::object();
projectNode.push_back({"id", ciderPlanId});
projectNode.push_back({"relOp", name()});
Expand All @@ -85,28 +85,28 @@ class CiderProjectNode : public CiderPlanNode {
return "LogicalProject";
}

const std::vector<std::shared_ptr<const CiderPlanNode>>& sources()
const std::vector<std::shared_ptr<const ComputeIRNode>>& sources()
const override {
return sources_;
}

private:
const std::vector<std::string> assignmentKeys_;
const std::vector<std::shared_ptr<const CiderRowExpr>> assignmentExprs_;
const std::vector<std::shared_ptr<const CiderPlanNode>> sources_;
const std::vector<std::shared_ptr<const IRRowExpr>> assignmentExprs_;
const std::vector<std::shared_ptr<const ComputeIRNode>> sources_;
};

class CiderFilterNode : public CiderPlanNode {
class FilterIRNode : public ComputeIRNode {
public:
CiderFilterNode(
FilterIRNode(
const PlanNodeId& id,
std::shared_ptr<const CiderRowExpr> filter,
std::shared_ptr<const CiderPlanNode> source)
: CiderPlanNode(id), filter_(filter), sources_{source} {}
std::shared_ptr<const IRRowExpr> filter,
std::shared_ptr<const ComputeIRNode> source)
: ComputeIRNode(id), filter_(filter), sources_{source} {}

json toCiderJSON(std::string ciderPlanId) const override {
json toOmnisciDBJSON(std::string cid) const override {
json filterNode = json::object();
filterNode.push_back({"id", ciderPlanId});
filterNode.push_back({"id", cid});
filterNode.push_back({"relOp", name()});
filterNode.push_back({"condition", filter_->toCiderJSON()});
return filterNode;
Expand All @@ -116,24 +116,24 @@ class CiderFilterNode : public CiderPlanNode {
return "LogicalFilter";
}

const std::vector<std::shared_ptr<const CiderPlanNode>>& sources()
const std::vector<std::shared_ptr<const ComputeIRNode>>& sources()
const override {
return sources_;
}

private:
const std::shared_ptr<const CiderRowExpr> filter_;
const std::vector<std::shared_ptr<const CiderPlanNode>> sources_;
const std::shared_ptr<const IRRowExpr> filter_;
const std::vector<std::shared_ptr<const ComputeIRNode>> sources_;
};

class CiderTableScanNode : public CiderPlanNode {
class TableScanIRNode : public ComputeIRNode {
public:
CiderTableScanNode(
TableScanIRNode(
const PlanNodeId& id,
std::string tableName,
std::string schemaName,
std::vector<std::string> fieldNames)
: CiderPlanNode(id),
: ComputeIRNode(id),
tableName_(tableName),
schemaName_(schemaName),
fieldNames_(fieldNames){};
Expand All @@ -142,9 +142,9 @@ class CiderTableScanNode : public CiderPlanNode {
return "LogicalTableScan";
}

json toCiderJSON(std::string ciderPlanId) const override {
json toOmnisciDBJSON(std::string cid) const override {
json scanNode = json::object();
scanNode.push_back({"id", ciderPlanId});
scanNode.push_back({"id", cid});
scanNode.push_back({"name", name()});

tmp_json fieldJsonNames = tmp_json::array();
Expand All @@ -160,7 +160,7 @@ class CiderTableScanNode : public CiderPlanNode {
return scanNode;
}

const std::vector<std::shared_ptr<const CiderPlanNode>>& sources()
const std::vector<std::shared_ptr<const ComputeIRNode>>& sources()
const override;

private:
Expand Down
14 changes: 7 additions & 7 deletions cider/core/CiderExpressions.h → cider/core/IRExpressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/
#pragma once
#include "velox/cider/core/CiderRowExpr.h"
#include "velox/cider/core/IRRowExpr.h"

using json = nlohmann::json;

Expand Down Expand Up @@ -58,9 +58,9 @@ namespace intel::cider::core{
}
}

class CiderConstantExpr : public CiderRowExpr {
class IRConstantExpr : public IRRowExpr {
public:
CiderConstantExpr(std::string value, std::string type)
IRConstantExpr(std::string value, std::string type)
: type_{move(type)}, value_{move(value)} {}

std::string value() const{
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace intel::cider::core{
const std::string value_;
};

class CiderVariableExpr : public CiderRowExpr {
class CiderVariableExpr : public IRRowExpr {
public:
CiderVariableExpr(std::string name, std::string type, int index)
: name_{move(name)}, type_{move(type)}, index_(index) {}
Expand All @@ -141,9 +141,9 @@ namespace intel::cider::core{
};

// row expression that describes a predicate, such as "field_a > 2"
class CiderCallExpr : public CiderRowExpr {
class CiderCallExpr : public IRRowExpr {
public:
CiderCallExpr(std::string op, std::string type, std::vector<std::shared_ptr<const CiderRowExpr>>& expressions)
CiderCallExpr(std::string op, std::string type, std::vector<std::shared_ptr<const IRRowExpr>>& expressions)
: op_{move(op)}, type_{move(type)}, expressions_{move(expressions)} {}

json toCiderJSON() const override {
Expand All @@ -167,6 +167,6 @@ class CiderCallExpr : public CiderRowExpr {
private:
const std::string op_;
const std::string type_;
const std::vector<std::shared_ptr<const CiderRowExpr>> expressions_;
const std::vector<std::shared_ptr<const IRRowExpr>> expressions_;
};
}
4 changes: 2 additions & 2 deletions cider/core/CiderRowExpr.h → cider/core/IRRowExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
using json = nlohmann::json;

namespace intel::cider::core {
class CiderRowExpr {
class IRRowExpr {
public:
virtual json toCiderJSON() const = 0;
virtual ~CiderRowExpr() = default;
virtual ~IRRowExpr() = default;
};
} // namespace intel::cider::core
32 changes: 10 additions & 22 deletions cider/core/CiderPlanNode.cpp → cider/core/OmnisciDBTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stack>
#include <set>
#include "velox/cider/core/CiderPlanNode.h"
#pragma once
#include "OmnisciDBTranslator.h"

namespace intel::cider::core {
namespace {
static const std::vector<std::shared_ptr<const CiderPlanNode>> EMPTY_SOURCES;
}

const std::vector<std::shared_ptr<const CiderPlanNode>>&
CiderTableScanNode::sources() const {
return EMPTY_SOURCES;
}

std::string CiderPlanNode::toCiderRelAlgStr(
const std::shared_ptr<CiderPlanNode>& node) {
std::string OmnisciDBTranslator::toRelAlgStr(
const std::shared_ptr<ComputeIRNode>& node) {
// return json string
std::stack<std::shared_ptr<const CiderPlanNode>> planNodes;
std::set<std::shared_ptr<const CiderPlanNode>> visited;
std::stack<std::shared_ptr<const ComputeIRNode>> planNodes;
std::set<std::shared_ptr<const ComputeIRNode>> visited;
planNodes.emplace(node);
visited.emplace(node);
std::shared_ptr<const CiderPlanNode> currentNode;
std::shared_ptr<const ComputeIRNode> currentNode;
std::string lastConvertedPlanId;
json rootNode = json::object();
json relsNode = json::array();
Expand All @@ -58,12 +47,11 @@ std::string CiderPlanNode::toCiderRelAlgStr(
}
}
// add json
relsNode.push_back(currentNode->toCiderJSON(std::to_string(ciderPlanId)));
relsNode.push_back(
currentNode->toOmnisciDBJSON(std::to_string(ciderPlanId)));
ciderPlanId++;
planNodes.pop();
}
rootNode.push_back({"relsNode", relsNode});
return rootNode.dump();
}

} // namespace intel::cider::core
}
23 changes: 23 additions & 0 deletions cider/core/OmnisciDBTranslator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 "velox/cider/core/ComputeIRNode.h"

namespace intel::cider::core {
class OmnisciDBTranslator {
public:
std::string OmnisciDBTranslator::toRelAlgStr(
const std::shared_ptr<ComputeIRNode>& node);
};
} // namespace intel::cider::core
14 changes: 7 additions & 7 deletions velox/core/PlanNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
#pragma once

#include "cider/core/ComputeIRNode.h"
#include "velox/connectors/Connector.h"
#include "velox/core/Expressions.h"
#include "cider/core/CiderPlanNode.h"

using namespace intel::cider::core;

Expand Down Expand Up @@ -1005,13 +1005,13 @@ class LimitNode : public PlanNode {
const std::vector<std::shared_ptr<const PlanNode>> sources_;
};

class JITedNode : public PlanNode {
class ConvergedNode : public PlanNode {
public:
JITedNode(
ConvergedNode(
const PlanNodeId& id,
const std::shared_ptr<const CiderPlanNode>& ciderPlanNode,
const std::shared_ptr<const ComputeIRNode>& IRNode,
const std::shared_ptr<const PlanNode>& source)
: PlanNode(id), ciderPlanNode_(ciderPlanNode), sources_{source} {};
: PlanNode(id), cir_(IRNode), sources_{source} {};

// TODO (Cheng) change to the right output types
const RowTypePtr& outputType() const override {
Expand All @@ -1023,11 +1023,11 @@ class JITedNode : public PlanNode {
}

std::string_view name() const override {
return "JITed";
return "ConvergedNode";
}

private:
const std::shared_ptr<const CiderPlanNode>& ciderPlanNode_;
const std::shared_ptr<const ComputeIRNode>& cir_;
const std::vector<std::shared_ptr<const PlanNode>> sources_;
};

Expand Down
10 changes: 5 additions & 5 deletions velox/core/QueryCtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ class QueryCtx : public Context {
static constexpr const char* kCodegenLazyLoading =
"driver.codegen.lazy_loading";

// Configuration to enable JITed engine and JIT backend
static constexpr const char* kJITEnabled = "driver.jit.enabled";
static constexpr const char* kJITBackend =
"driver.codegen.configuration_file_path";

// Enable hybrid execution mode allowing multiple execution backends
static constexpr const char* kHybridExecEnabled =
"driver.hybrid.execution.enabled";
static constexpr const char* kHybridExecutionBackends =
"driver.hybrid.execution.backends";

// User provided session timezone. Stores a string with the actual timezone
// name, e.g: "America/Los_Angeles".
Expand Down
Loading

0 comments on commit a7b1e54

Please sign in to comment.