From 4f9f3e9b4b87e52ab50a88f8f1839c0f47d4153f Mon Sep 17 00:00:00 2001 From: spasserby Date: Thu, 9 Nov 2023 15:13:13 +0800 Subject: [PATCH] fix issue #473 --- src/cypher/arithmetic/arithmetic_expression.h | 1 + src/cypher/execution_plan/ops/op_project.h | 8 +++++++- test/test_cypher.cpp | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cypher/arithmetic/arithmetic_expression.h b/src/cypher/arithmetic/arithmetic_expression.h index 0f208dfce4..e96ae3a099 100644 --- a/src/cypher/arithmetic/arithmetic_expression.h +++ b/src/cypher/arithmetic/arithmetic_expression.h @@ -372,6 +372,7 @@ struct ArithOperandNode { if (type == AR_OPERAND_CONSTANT) { return Entry(constant); } else if (type == AR_OPERAND_VARIADIC) { + CYPHER_THROW_ASSERT(record.values.size() > (size_t)variadic.alias_idx); const auto &entry = record.values[variadic.alias_idx]; switch (entry.type) { case Entry::NODE: diff --git a/src/cypher/execution_plan/ops/op_project.h b/src/cypher/execution_plan/ops/op_project.h index 2a2be785b3..8f3eee8694 100644 --- a/src/cypher/execution_plan/ops/op_project.h +++ b/src/cypher/execution_plan/ops/op_project.h @@ -41,12 +41,18 @@ class Project : public OpBase { const auto &return_body = stmt->return_clause ? std::get<1>(*stmt->return_clause) : std::get<1>(*stmt->with_clause); const auto &return_items = std::get<0>(return_body); + std::unordered_set distinct_alias; for (auto &item : return_items) { auto &expr = std::get<0>(item); auto &var = std::get<1>(item); ArithExprNode ae(expr, sym_tab_); return_elements_.emplace_back(ae); - return_alias_.emplace_back(var.empty() ? expr.ToString(false) : var); + auto alias = var.empty() ? expr.ToString(false) : var; + if (distinct_alias.find(alias) != distinct_alias.end()) { + throw lgraph::CypherException("Duplicate alias: " + alias); + } + distinct_alias.emplace(alias); + return_alias_.emplace_back(alias); if (!var.empty()) modifies.emplace_back(var); } } diff --git a/test/test_cypher.cpp b/test/test_cypher.cpp index d28a9e5188..47e14cbd0e 100644 --- a/test/test_cypher.cpp +++ b/test/test_cypher.cpp @@ -2209,6 +2209,9 @@ int test_fix_crash_issues(cypher::RTContext *ctx) { expected_exception_any(ctx, "MATCH p=(n)-[e]->(m) RETURN p LIMIT 5"); ctx->graph_ = graph; // issue #312 & #464 end + // issue #473 + expected_exception_any(ctx, "MATCH (movie)<-[r]-(n) WITH n,n MATCH (n1) RETURN n1 LIMIT 1"); + expected_exception_any(ctx, "MATCH (movie)<-[r]-(n) return n,n limit 1"); return 0; }