Skip to content
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6b4bb7d
add cypher test compare result
jiazhenjiang Apr 1, 2024
bfa33dd
Merge branch 'master' into cypher_join_ast
jiazhenjiang Apr 12, 2024
cad4c0e
implement query
jiazhenjiang Apr 16, 2024
5d8f2b0
Merge branch 'master' into cypher_join_ast
jiazhenjiang Apr 16, 2024
50834b1
implement match query
jiazhenjiang Apr 24, 2024
8a401fe
Merge branch 'master' into cypher_join_ast
qishipengqsp Apr 26, 2024
e6dcbeb
Merge branch 'master' into cypher_join_ast
qishipengqsp May 7, 2024
3a6f99b
implement standalone call and create
jiazhenjiang May 16, 2024
9b8f1f3
Merge branch 'master' into cypher_join_ast
jiazhenjiang May 16, 2024
d777633
Merge branch 'cypher_join_ast' of https://github.com/jiazhenjiang/tug…
jiazhenjiang May 16, 2024
f9e3e4f
cpplint
jiazhenjiang May 16, 2024
87e28cf
cpplint
jiazhenjiang May 16, 2024
85d95f0
cpplint
jiazhenjiang May 16, 2024
271348f
fix double format
jiazhenjiang May 17, 2024
37855fb
update
jiazhenjiang May 23, 2024
95271e6
update
jiazhenjiang May 23, 2024
e85b571
implement set
jiazhenjiang May 27, 2024
df86ed6
implement gql set
jiazhenjiang May 27, 2024
745b791
Merge branch 'master' into cypher_join_ast
jiazhenjiang May 27, 2024
bc09ac1
fix test case
jiazhenjiang May 27, 2024
15037cc
move dml
jiazhenjiang May 27, 2024
918806e
cpplint
jiazhenjiang May 27, 2024
285b8aa
cpplint
jiazhenjiang May 27, 2024
93cd07b
add create delete set
jiazhenjiang May 28, 2024
e237903
implement unwind
jiazhenjiang May 30, 2024
83e342a
fix bug
jiazhenjiang Jun 3, 2024
729c1bb
implement count(*)
jiazhenjiang Jun 3, 2024
f71af20
implement expression
jiazhenjiang Jun 4, 2024
3f27530
multi match init
spasserby Jun 5, 2024
29a6aed
Merge pull request #1 from spasserby/multi_match
jiazhenjiang Jun 5, 2024
5b5a462
fix bug
jiazhenjiang Jun 5, 2024
313c6ce
Merge branch 'ddl_cypher' of https://github.com/jiazhenjiang/tugraph-…
jiazhenjiang Jun 5, 2024
4790c6e
fix bug
jiazhenjiang Jun 7, 2024
f5e11ab
fix bug
jiazhenjiang Jun 12, 2024
2db23cd
fix bug
jiazhenjiang Jun 12, 2024
24f91db
implement inquery call
jiazhenjiang Jun 14, 2024
bb5368b
fix bug
jiazhenjiang Jun 14, 2024
aa1b684
fix bug
jiazhenjiang Jun 17, 2024
ecae16b
implement merge
jiazhenjiang Jun 17, 2024
d021e60
implement merge
jiazhenjiang Jun 18, 2024
3e3ad93
fix bug in merge clause
jiazhenjiang Jun 19, 2024
98a8165
fix bug
jiazhenjiang Jun 19, 2024
cb5219b
merge master
jiazhenjiang Jun 19, 2024
c949fe4
fix bug
jiazhenjiang Jun 19, 2024
4e446a4
cpplint
jiazhenjiang Jun 20, 2024
2ecc8a7
cpplint
jiazhenjiang Jun 20, 2024
1f4663a
fix bug
jiazhenjiang Jun 25, 2024
2f1b503
fix bug
jiazhenjiang Jun 27, 2024
3c19502
fix bug
jiazhenjiang Jun 28, 2024
c7a7e1d
fix bug
jiazhenjiang Jul 1, 2024
b50abb5
open test case
jiazhenjiang Jul 1, 2024
f1a429c
cpplint
jiazhenjiang Jul 3, 2024
24b6a26
implement exists pattern
jiazhenjiang Jul 5, 2024
c015e5e
implements exists pathpattern
jiazhenjiang Jul 10, 2024
a58f1d6
fix bug
jiazhenjiang Jul 11, 2024
0b41329
fix bug
jiazhenjiang Jul 12, 2024
7d8e3fe
implement exists in where
jiazhenjiang Jul 19, 2024
336cf09
remove rewriter file
jiazhenjiang Jul 19, 2024
0a1f6bb
remove log
jiazhenjiang Jul 22, 2024
86876c2
add expression test
jiazhenjiang Jul 22, 2024
a365be6
merge master
jiazhenjiang Jul 22, 2024
de864f9
cpplint
jiazhenjiang Jul 22, 2024
4fbba19
comments
jiazhenjiang Jul 23, 2024
9c5ac27
comments
jiazhenjiang Jul 25, 2024
83da9d8
add comment
jiazhenjiang Jul 26, 2024
a465f14
cpplint
jiazhenjiang Jul 26, 2024
21fbae5
Merge branch 'master' into exist_path
wangtao9 Jul 29, 2024
c38a2bc
Merge branch 'master' into exist_path
jiazhenjiang Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions deps/geax-front-end/include/geax-front-end/ast/AstDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,7 @@ class AstDumper : public AstNodeVisitor {
std::any visit(Exists* node) override {
INDET_GUARD();
VARIABLE_GUARD_WITH_TYPE_NAME(Exists);
auto expr = node->expr();
auto& path_chains = node->pathChains();
VISIT_PARAM_AND_CHECK_WITH_MSG(expr);
VISIT_PARAM_AND_CHECK_WITH_MSG(path_chains);
return GEAXErrorCode::GEAX_SUCCEED;
}
Expand Down
8 changes: 4 additions & 4 deletions deps/geax-front-end/include/geax-front-end/ast/expr/Exists.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
#define GEAXFRONTEND_AST_EXPR_EXISTS_H_

#include "geax-front-end/ast/clause/PathChain.h"
#include "geax-front-end/ast/expr/UnaryOp.h"
#include "geax-front-end/ast/expr/Expr.h"

namespace geax {
namespace frontend {

class Exists : public UnaryOp {
class Exists : public Expr {
public:
Exists() : UnaryOp(AstNodeType::kExists) {}
Exists() : Expr(AstNodeType::kExists) {}
~Exists() = default;

void appendPathChain(PathChain* pathChain) { pathChains_.emplace_back(pathChain); }
Expand All @@ -46,7 +46,7 @@ class Exists : public UnaryOp {
inline bool Exists::equals(const Expr& other) const {
const auto& expr = static_cast<const Exists&>(other);
// TODO(ljr): PathChain equals
bool ret = UnaryOp::equals(other) && pathChains_.size() == expr.pathChains_.size();
bool ret = pathChains_.size() == expr.pathChains_.size();
return ret;
}

Expand Down
67 changes: 35 additions & 32 deletions src/core/vertex_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ inline Value ReturnKeyEvenIfLong(Value&& v) { return std::move(v); }

// begin of VertexIndexValue

VertexIndexValue::VertexIndexValue()
: v_(1) { *(uint8_t*)v_.Data() = 0; }
VertexIndexValue::VertexIndexValue() : v_(1) { *(uint8_t*)v_.Data() = 0; }

VertexIndexValue::VertexIndexValue(const Value& v)
: v_(v) {}
VertexIndexValue::VertexIndexValue(const Value& v) : v_(v) {}

VertexIndexValue::VertexIndexValue(Value&& v)
: v_(std::move(v)) {}
VertexIndexValue::VertexIndexValue(Value&& v) : v_(std::move(v)) {}

int VertexIndexValue::SearchVid(int64_t vid, bool& found) const {
if (GetVidCount() == 0) {
Expand Down Expand Up @@ -138,15 +135,15 @@ Value VertexIndexValue::CreateKey(const Value& key) const {
// begin of VertexIndexIterator

VertexIndexIterator::VertexIndexIterator(VertexIndex* idx, Transaction* txn, KvTable& table,
const Value& key_start,
const Value& key_end, VertexId vid, IndexType type)
const Value& key_start, const Value& key_end, VertexId vid,
IndexType type)
: IteratorBase(txn),
index_(idx),
it_(table.GetClosestIterator(txn->GetTxn(),
type == IndexType::GlobalUniqueIndex ? key_start
: _detail::PatchKeyWithVid(key_start, vid))),
it_(table.GetClosestIterator(txn->GetTxn(), type == IndexType::GlobalUniqueIndex
? key_start
: _detail::PatchKeyWithVid(key_start, vid))),
key_end_(type == IndexType::GlobalUniqueIndex ? Value::MakeCopy(key_end)
: _detail::PatchKeyWithVid(key_end, -1)),
: _detail::PatchKeyWithVid(key_end, -1)),
iv_(),
valid_(false),
pos_(0),
Expand All @@ -161,15 +158,15 @@ VertexIndexIterator::VertexIndexIterator(VertexIndex* idx, Transaction* txn, KvT
}

VertexIndexIterator::VertexIndexIterator(VertexIndex* idx, KvTransaction* txn, KvTable& table,
const Value& key_start,
const Value& key_end, VertexId vid, IndexType type)
const Value& key_start, const Value& key_end, VertexId vid,
IndexType type)
: IteratorBase(nullptr),
index_(idx),
it_(table.GetClosestIterator(
*txn, type == IndexType::GlobalUniqueIndex ? key_start :
_detail::PatchKeyWithVid(key_start, vid))),
key_end_(type == IndexType::GlobalUniqueIndex ?
Value::MakeCopy(key_end) : _detail::PatchKeyWithVid(key_end, -1)),
it_(table.GetClosestIterator(*txn, type == IndexType::GlobalUniqueIndex
? key_start
: _detail::PatchKeyWithVid(key_start, vid))),
key_end_(type == IndexType::GlobalUniqueIndex ? Value::MakeCopy(key_end)
: _detail::PatchKeyWithVid(key_end, -1)),
iv_(),
valid_(false),
pos_(0),
Expand Down Expand Up @@ -199,8 +196,9 @@ VertexIndexIterator::VertexIndexIterator(VertexIndexIterator&& rhs)
}

bool VertexIndexIterator::KeyOutOfRange() {
if (key_end_.Empty() || (type_ != IndexType::GlobalUniqueIndex
&& key_end_.Size() == _detail::VID_SIZE)) return false;
if (key_end_.Empty() ||
(type_ != IndexType::GlobalUniqueIndex && key_end_.Size() == _detail::VID_SIZE))
return false;
return it_->GetTable().CompareKey(it_->GetTxn(), it_->GetKey(), key_end_) > 0;
}

Expand Down Expand Up @@ -272,6 +270,13 @@ bool VertexIndexIterator::Next() {
return true;
}

bool VertexIndexIterator::Goto(lgraph::VertexId vid) {
if (!it_->GotoClosestKey(curr_key_)) return false;
if (KeyOutOfRange()) return false;
LoadContentFromIt();
return it_->IsValid() && vid == vid_;
}

Value VertexIndexIterator::GetKey() const {
switch (type_) {
case IndexType::GlobalUniqueIndex:
Expand Down Expand Up @@ -307,8 +312,7 @@ void VertexIndexIterator::RefreshContentIfKvIteratorModified() {
}
case IndexType::NonuniqueIndex:
{
if (!it_->GotoClosestKey(_detail::PatchKeyWithVid(curr_key_, vid_)))
return;
if (!it_->GotoClosestKey(_detail::PatchKeyWithVid(curr_key_, vid_))) return;
if (KeyOutOfRange()) return;
// non-unique, need to find correct pos_
iv_ = VertexIndexValue(it_->GetValue());
Expand All @@ -329,8 +333,7 @@ void VertexIndexIterator::RefreshContentIfKvIteratorModified() {
// begin of VertexIndex

VertexIndex::VertexIndex(std::shared_ptr<KvTable> table, FieldType key_type, IndexType type)
: table_(std::move(table)), key_type_(key_type),
ready_(false), disabled_(false), type_(type) {}
: table_(std::move(table)), key_type_(key_type), ready_(false), disabled_(false), type_(type) {}

VertexIndex::VertexIndex(const VertexIndex& rhs)
: table_(rhs.table_),
Expand All @@ -340,7 +343,8 @@ VertexIndex::VertexIndex(const VertexIndex& rhs)
type_(rhs.type_) {}

std::unique_ptr<KvTable> VertexIndex::OpenTable(KvTransaction& txn, KvStore& store,
const std::string& name, FieldType dt, IndexType type) {
const std::string& name, FieldType dt,
IndexType type) {
ComparatorDesc desc;
switch (type) {
case IndexType::GlobalUniqueIndex:
Expand Down Expand Up @@ -370,7 +374,7 @@ void VertexIndex::_AppendVertexIndexEntry(KvTransaction& txn, const Value& k, Ve
}

void VertexIndex::_AppendNonUniqueVertexIndexEntry(KvTransaction& txn, const Value& k,
const std::vector<VertexId>& vids) {
const std::vector<VertexId>& vids) {
FMA_DBG_ASSERT(type_ == IndexType::NonuniqueIndex);
FMA_DBG_ASSERT(!vids.empty());
Value key = CutKeyIfLongOnlyForNonUniqueIndex(k);
Expand All @@ -385,7 +389,7 @@ void VertexIndex::_AppendNonUniqueVertexIndexEntry(KvTransaction& txn, const Val
}

void VertexIndex::Dump(KvTransaction& txn,
const std::function<std::string(const char* p, size_t s)>& key_to_string) {
const std::function<std::string(const char* p, size_t s)>& key_to_string) {
auto it = table_->GetIterator(txn);
for (it->GotoFirstKey(); it->IsValid(); it->Next()) {
const Value& k = it->GetKey();
Expand Down Expand Up @@ -455,8 +459,8 @@ bool VertexIndex::Delete(KvTransaction& txn, const Value& k, int64_t vid) {
return false;
}

bool VertexIndex::Update(KvTransaction& txn, const Value& old_key,
const Value& new_key, int64_t vid) {
bool VertexIndex::Update(KvTransaction& txn, const Value& old_key, const Value& new_key,
int64_t vid) {
if (!Delete(txn, old_key, vid)) {
return false;
}
Expand Down Expand Up @@ -556,8 +560,7 @@ size_t VertexIndex::GetMaxVertexIndexKeySize() {
}

Value VertexIndex::CutKeyIfLongOnlyForNonUniqueIndex(const lgraph::Value& k) {
if (type_ != IndexType::NonuniqueIndex)
return Value::ConstRef(k);
if (type_ != IndexType::NonuniqueIndex) return Value::ConstRef(k);
size_t key_size = GetMaxVertexIndexKeySize();
if (k.Size() < key_size) return Value::ConstRef(k);
return Value(k.Data(), key_size);
Expand Down
2 changes: 2 additions & 0 deletions src/core/vertex_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class VertexIndexIterator : public ::lgraph::IteratorBase {
*/
bool Next();

bool Goto(VertexId vid);


/**
* Gets the current key.
Expand Down
41 changes: 40 additions & 1 deletion src/cypher/arithmetic/ast_expr_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ cypher::FieldData doCallBuiltinFunc(const std::string& name, cypher::RTContext*
return data;
}

const std::string& getNodeOrEdgeName(geax::frontend::AstNode* ast_node) {
if (ast_node->type() == geax::frontend::AstNodeType::kNode) {
geax::frontend::Node* node = (geax::frontend::Node*)ast_node;
if (!node->filler()->v().has_value()) NOT_SUPPORT_AND_THROW();
return node->filler()->v().value();
} else if (ast_node->type() == geax::frontend::AstNodeType::kEdge) {
geax::frontend::Edge* edge = (geax::frontend::Edge*)ast_node;
if (!edge->filler()->v().has_value()) NOT_SUPPORT_AND_THROW();
return edge->filler()->v().value();
} else {
NOT_SUPPORT_AND_THROW();
}
}

namespace cypher {

static cypher::FieldData And(const cypher::FieldData& x, const cypher::FieldData& y) {
Expand Down Expand Up @@ -534,7 +548,32 @@ std::any cypher::AstExprEvaluator::visit(geax::frontend::IsNull* node) {
std::any cypher::AstExprEvaluator::visit(geax::frontend::Exists* node) {
auto path_chains = node->pathChains();
if (path_chains.size() > 1) NOT_SUPPORT_AND_THROW();
NOT_SUPPORT_AND_THROW();
auto head = path_chains[0]->head();
const std::string head_name = getNodeOrEdgeName(head);
auto it_head = sym_tab_->symbols.find(head_name);
if (it_head == sym_tab_->symbols.end() || it_head->second.type != SymbolNode::NODE)
NOT_SUPPORT_AND_THROW();
if (!record_->values[it_head->second.id].CheckEntityEfficient(ctx_))
return Entry(cypher::FieldData(lgraph::FieldData(false)));

auto& tails = path_chains[0]->tails();
for (auto& tail : tails) {
auto relationship = std::get<0>(tail);
const std::string rel_name = getNodeOrEdgeName(relationship);
auto it_rel = sym_tab_->symbols.find(rel_name);
if (it_rel == sym_tab_->symbols.end() || it_rel->second.type != SymbolNode::RELATIONSHIP)
NOT_SUPPORT_AND_THROW();
if (!record_->values[it_rel->second.id].CheckEntityEfficient(ctx_))
return Entry(cypher::FieldData(lgraph::FieldData(false)));
auto neighbor = std::get<1>(tail);
const std::string ne_name = getNodeOrEdgeName(neighbor);
auto it_ne = sym_tab_->symbols.find(ne_name);
if (it_ne == sym_tab_->symbols.end() || it_ne->second.type != SymbolNode::NODE)
NOT_SUPPORT_AND_THROW();
if (!record_->values[it_ne->second.id].CheckEntityEfficient(ctx_))
return Entry(cypher::FieldData(lgraph::FieldData(false)));
}
return Entry(cypher::FieldData(lgraph::FieldData(true)));
}

std::any cypher::AstExprEvaluator::reportError() { return error_msg_; }
Expand Down
Loading