Skip to content

Commit

Permalink
Merge branch 'master' into enhancement/pattern-expression
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu authored Dec 6, 2022
2 parents 3b649ec + 5553529 commit 24a6b81
Show file tree
Hide file tree
Showing 43 changed files with 1,457 additions and 228 deletions.
3 changes: 2 additions & 1 deletion src/common/expression/PredicateExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ std::unordered_map<std::string, PredicateExpression::Type> PredicateExpression::
const Value& PredicateExpression::evalExists(ExpressionContext& ctx) {
DCHECK(collection_->kind() == Expression::Kind::kAttribute ||
collection_->kind() == Expression::Kind::kSubscript ||
collection_->kind() == Expression::Kind::kLabelTagProperty);
collection_->kind() == Expression::Kind::kLabelTagProperty)
<< "actual kind: " << collection_->kind() << ", toString: " << toString();

if (collection_->kind() == Expression::Kind::kLabelTagProperty) {
result_ = !collection_->eval(ctx).isNull();
Expand Down
17 changes: 17 additions & 0 deletions src/common/function/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <folly/json.h>

#include <boost/algorithm/string/replace.hpp>
#include <cstdint>

#include "common/base/Base.h"
#include "common/datatypes/DataSet.h"
Expand Down Expand Up @@ -41,6 +42,7 @@ std::unordered_map<std::string, Value::Type> FunctionManager::variadicFunReturnT
{"concat_ws", Value::Type::STRING},
{"cos_similarity", Value::Type::FLOAT},
{"coalesce", Value::Type::__EMPTY__},
{"_any", Value::Type::__EMPTY__},
};

std::unordered_map<std::string, std::vector<TypeSignature>> FunctionManager::typeSignature_ = {
Expand Down Expand Up @@ -2820,6 +2822,21 @@ FunctionManager::FunctionManager() {
}
};
}
// Get any argument which is not empty/null
{
auto &attr = functions_["_any"];
attr.minArity_ = 1;
attr.maxArity_ = INT64_MAX;
attr.isAlwaysPure_ = true;
attr.body_ = [](const auto &args) -> Value {
for (const auto &arg : args) {
if (!arg.get().isNull() && !arg.get().empty()) {
return arg.get();
}
}
return Value::kNullValue;
};
}
} // NOLINT

// static
Expand Down
13 changes: 13 additions & 0 deletions src/common/function/test/FunctionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,19 @@ TEST_F(FunctionManagerTest, PurityTest) {
ASSERT_TRUE(result.ok() && result.value() == true);
}

TEST_F(FunctionManagerTest, Any) {
auto dataset = DataSet({"col0", "col1", "col2"});
dataset.emplace_back(Row({1, true, "233"}));
dataset.emplace_back(Row({4, false, "456"}));
Value datasetValue = Value(std::move(dataset));
// null all
{ TEST_FUNCTION(_any, std::vector<Value>({Value(), Value::kNullValue}), Value::kNullBadData); }
// ok
{ TEST_FUNCTION(_any, std::vector<Value>({Value(), Value::kNullValue, Value(1)}), Value(1)); }
// only one
{ TEST_FUNCTION(_any, std::vector<Value>({Value(1)}), Value(1)); }
}

} // namespace nebula

int main(int argc, char **argv) {
Expand Down
26 changes: 1 addition & 25 deletions src/graph/context/Symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ bool SymbolTable::deleteWrittenBy(const std::string& varName, PlanNode* node) {
if (var == vars_.end()) {
return false;
}
for (auto& alias : var->second->colNames) {
auto found = aliasGeneratedBy_.find(alias);
if (found != aliasGeneratedBy_.end()) {
if (found->second == varName) {
aliasGeneratedBy_.erase(alias);
}
}
}
var->second->writtenBy.erase(node);
return true;
}
Expand All @@ -106,6 +98,7 @@ bool SymbolTable::updateWrittenBy(const std::string& oldVar,
}

Variable* SymbolTable::getVar(const std::string& varName) {
DCHECK(!varName.empty()) << "the variable name is empty";
auto var = vars_.find(varName);
if (var == vars_.end()) {
return nullptr;
Expand All @@ -114,22 +107,5 @@ Variable* SymbolTable::getVar(const std::string& varName) {
}
}

void SymbolTable::setAliasGeneratedBy(const std::vector<std::string>& aliases,
const std::string& varName) {
for (auto& alias : aliases) {
if (aliasGeneratedBy_.count(alias) == 0) {
aliasGeneratedBy_.emplace(alias, varName);
}
}
}

StatusOr<std::string> SymbolTable::getAliasGeneratedBy(const std::string& alias) {
auto found = aliasGeneratedBy_.find(alias);
if (found == aliasGeneratedBy_.end()) {
return Status::Error("Not found a variable that generates the alias: %s", alias.c_str());
} else {
return found->second;
}
}
} // namespace graph
} // namespace nebula
6 changes: 0 additions & 6 deletions src/graph/context/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ class SymbolTable final {

Variable* getVar(const std::string& varName);

void setAliasGeneratedBy(const std::vector<std::string>& aliases, const std::string& varName);

StatusOr<std::string> getAliasGeneratedBy(const std::string& alias);

std::string toString() const;

private:
Expand All @@ -85,8 +81,6 @@ class SymbolTable final {
ExecutionContext* ectx_{nullptr};
// var name -> variable
std::unordered_map<std::string, Variable*> vars_;
// alias -> first variable that generate the alias
std::unordered_map<std::string, std::string> aliasGeneratedBy_;
};

} // namespace graph
Expand Down
4 changes: 3 additions & 1 deletion src/graph/executor/logic/ArgumentExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ folly::Future<Status> ArgumentExecutor::execute() {
std::unordered_set<Value> unique;
for (; iter->valid(); iter->next()) {
auto &val = iter->getColumn(alias);
if (!val.isVertex()) {
if (val.isNull()) {
continue;
} else if (!val.isVertex()) {
return Status::Error("Argument only support vertex, but got %s, which is type %s, ",
val.toString().c_str(),
val.typeName().c_str());
Expand Down
2 changes: 2 additions & 0 deletions src/graph/optimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ nebula_add_library(
rule/PushFilterDownAggregateRule.cpp
rule/PushFilterDownProjectRule.cpp
rule/PushFilterDownLeftJoinRule.cpp
rule/PushFilterDownHashInnerJoinRule.cpp
rule/PushFilterDownInnerJoinRule.cpp
rule/PushFilterDownNodeRule.cpp
rule/PushFilterDownScanVerticesRule.cpp
Expand All @@ -53,6 +54,7 @@ nebula_add_library(
rule/EliminateAppendVerticesRule.cpp
rule/PushLimitDownScanEdgesRule.cpp
rule/RemoveProjectDedupBeforeGetDstBySrcRule.cpp
rule/PushFilterDownTraverseRule.cpp
)

nebula_add_subdirectory(test)
Loading

0 comments on commit 24a6b81

Please sign in to comment.