Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Aug 26, 2024
1 parent 0345fc1 commit b386c41
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/binder/bind/ddl/bound_create_table_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ BoundCreateTableInfo BoundCreateTableInfo::deserialize(Deserializer& deserialize
deserializer.deserializeValue(hasParent);
switch (type) {
case TableType::NODE:
case TableType::EXTERNAL_NODE:
case TableType::REL: {
extraInfo = BoundExtraCreateTableInfo::deserialize(deserializer, type);
} break;
Expand Down Expand Up @@ -62,6 +63,9 @@ std::unique_ptr<BoundExtraCreateTableInfo> BoundExtraCreateTableInfo::deserializ
case TableType::NODE: {
info = BoundExtraCreateNodeTableInfo::deserialize(deserializer);
} break;
case TableType::EXTERNAL_NODE: {
info = BoundExtraCreateExternalNodeTableInfo::deserialize(deserializer);
} break;
case TableType::REL: {
info = BoundExtraCreateRelTableInfo::deserialize(deserializer);
} break;
Expand Down
1 change: 1 addition & 0 deletions src/include/function/table/bind_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct TableFuncBindData {
virtual ~TableFuncBindData() = default;

common::idx_t getNumColumns() const { return columnTypes.size(); }
bool hasColumnSkips() const { return !columnSkips.empty(); }
void setColumnSkips(std::vector<bool> skips) { columnSkips = std::move(skips); }
KUZU_API std::vector<bool> getColumnSkips() const;

Expand Down
1 change: 1 addition & 0 deletions src/include/planner/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PropertyExprCollection {
public:
void addProperties(const std::string& patternName,
std::shared_ptr<binder::Expression> property);
bool contains(const binder::Expression& pattern, const std::string propertyName) const;
binder::expression_vector getProperties(const binder::Expression& pattern) const;
binder::expression_vector getProperties() const;

Expand Down
6 changes: 6 additions & 0 deletions src/optimizer/projection_push_down_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ void ProjectionPushDownOptimizer::visitCopyFrom(LogicalOperator* op) {

void ProjectionPushDownOptimizer::visitTableFunctionCall(LogicalOperator* op) {
auto& tableFunctionCall = op->cast<LogicalTableFunctionCall>();
// We have an interesting problem here. By default, we scan from external sources, columns are
// bound as variables. So in projection push down, we check "variablesInUse".
// When try to execute cypher over external sources directly, TODO: fnish
if (tableFunctionCall.getBindData()->hasColumnSkips()) {
return;
}
std::vector<bool> columnSkips;
for (auto& column : tableFunctionCall.getColumns()) {
columnSkips.push_back(!variablesInUse.contains(column));
Expand Down
7 changes: 7 additions & 0 deletions src/planner/plan/append_scan_node_table.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "binder/expression/property_expression.h"
#include "planner/operator/scan/logical_scan_node_table.h"
#include "planner/operator/logical_hash_join.h"
#include "planner/operator/logical_table_function_call.h"
#include "planner/planner.h"
#include "main/client_context.h"
#include "catalog/catalog_entry/external_node_table_catalog_entry.h"
Expand Down Expand Up @@ -44,6 +45,12 @@ void Planner::appendScanNodeTable(const Expression& expr, const expression_vecto
auto bindData = scanFunc.bindFunc(clientContext, &bindInput);
auto scanInfo = BoundTableScanSourceInfo(scanFunc, std::move(bindData), node.getPropertyExprs());
appendTableFunctionCall(scanInfo, plan);
auto& tableFunctionCall = plan.getLastOperator()->cast<LogicalTableFunctionCall>();
std::vector<bool> columnSkips;
for (auto i =0u; i < entry->getNumProperties(); ++i) {
columnSkips.push_back(!propertyExprCollection.contains(expr, entry->getProperty(i).getName()));
}
tableFunctionCall.setColumnSkips(columnSkips);
// Join external table with internal table.
auto joinCondition = std::make_pair(pkExpr, pkExpr);
std::vector<binder::expression_pair> joinConditions;
Expand Down
13 changes: 13 additions & 0 deletions src/planner/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "binder/bound_explain.h"
#include "main/client_context.h"
#include "binder/expression/property_expression.h"

using namespace kuzu::binder;
using namespace kuzu::catalog;
Expand All @@ -11,6 +12,18 @@ using namespace kuzu::storage;
namespace kuzu {
namespace planner {

bool PropertyExprCollection::contains(const Expression& pattern, const std::string propertyName) const {
if (!patternNameToProperties.contains(pattern.getUniqueName())) {
return false;
}
for (auto& expr : patternNameToProperties.at(pattern.getUniqueName())) {
if (expr->constCast<PropertyExpression>().getPropertyName() == propertyName) {
return true;
}
}
return false;
}

expression_vector PropertyExprCollection::getProperties(const Expression& pattern) const {
if (!patternNameToProperties.contains(pattern.getUniqueName())) {
return binder::expression_vector{};
Expand Down

0 comments on commit b386c41

Please sign in to comment.