Fix counting when no matched nodes by property (#1518)
This commit is contained in:
parent
d58a464141
commit
46bfeb0023
@ -188,6 +188,8 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
|
||||
utils::MemoryResource *GetMemoryResource() const { return ctx_->memory; }
|
||||
|
||||
void ResetPropertyLookupCache() { property_lookup_cache_.clear(); }
|
||||
|
||||
TypedValue Visit(NamedExpression &named_expression) override {
|
||||
const auto &symbol = symbol_table_->at(named_expression);
|
||||
auto value = named_expression.expression_->Accept(*this);
|
||||
|
@ -3676,6 +3676,7 @@ class AggregateCursor : public Cursor {
|
||||
void ProcessOne(const Frame &frame, ExpressionEvaluator *evaluator) {
|
||||
// Preallocated group_by, since most of the time the aggregation key won't be unique
|
||||
reused_group_by_.clear();
|
||||
evaluator->ResetPropertyLookupCache();
|
||||
|
||||
for (Expression *expression : self_.group_by_) {
|
||||
reused_group_by_.emplace_back(expression->Accept(*evaluator));
|
||||
|
@ -410,19 +410,67 @@ Feature: Aggregations
|
||||
CREATE (s:Subnet {ip: "192.168.0.1"})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, collect(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, collect(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
Then the result should be empty
|
||||
|
||||
Scenario: Empty count aggregation:
|
||||
Scenario: Empty count aggregation
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (s:Subnet {ip: "192.168.0.1"})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, count(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, count(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
Then the result should be empty
|
||||
|
||||
Scenario: Collect nodes properties into a map:
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (t:Tag {short_code: "TST", description: "SYSTEM_TAG"}), (t2:Tag {short_code: "PRD", description: "SYSTEM_TAG"}),
|
||||
(t3:Tag {short_code: "STG", description: "SYSTEM_TAG"}), (device {name: "name1"}), (device)-[a1:ASSOCIATED]->(t),
|
||||
(device)-[a2:ASSOCIATED]->(t2), (device)-[a3:ASSOCIATED]->(t3);
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (d {name: "name1"})-[t:ASSOCIATED]-(tag:Tag) RETURN collect({short_code: tag.short_code, description: tag.description}) as tags;
|
||||
"""
|
||||
Then the result should be:
|
||||
| tags |
|
||||
| [{description: 'SYSTEM_TAG', short_code: 'TST'}, {description: 'SYSTEM_TAG', short_code: 'PRD'}, {description: 'SYSTEM_TAG', short_code: 'STG'}] |
|
||||
|
||||
Scenario: Count directly without WITH clause 01
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (:Node {prop1: 1, prop2: 2, prop3: 3}), (:Node {prop1: 10, prop2: 11, prop3: 12}), (:Node {prop1: 20, prop2: 21, prop3: 22})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (n) RETURN n.prop1, n.prop2, n.prop3, count(*) AS cnt
|
||||
"""
|
||||
Then the result should be:
|
||||
| n.prop1 | n.prop2 | n.prop3 | cnt |
|
||||
| 20 | 21 | 22 | 1 |
|
||||
| 10 | 11 | 12 | 1 |
|
||||
| 1 | 2 | 3 | 1 |
|
||||
|
||||
Scenario: Count directly without WITH clause 02
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (:Node {prop1: 1, prop2: 2, prop3: 3}), (:Node {prop1: 10, prop2: 11, prop3: 12}), (:Node {prop1: 20, prop2: 21, prop3: 22})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (n) WITH n.prop1 AS prop1, n.prop2 AS prop2, n.prop3 AS prop3 RETURN prop1, prop2, prop3, count(*) AS cnt;
|
||||
"""
|
||||
Then the result should be:
|
||||
| prop1 | prop2 | prop3 | cnt |
|
||||
| 20 | 21 | 22 | 1 |
|
||||
| 10 | 11 | 12 | 1 |
|
||||
| 1 | 2 | 3 | 1 |
|
||||
|
@ -410,19 +410,67 @@ Feature: Aggregations
|
||||
CREATE (s:Subnet {ip: "192.168.0.1"})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, collect(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, collect(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
Then the result should be empty
|
||||
|
||||
Scenario: Empty count aggregation:
|
||||
Scenario: Empty count aggregation
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (s:Subnet {ip: "192.168.0.1"})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, count(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
"""
|
||||
MATCH (subnet:Subnet) WHERE FALSE WITH subnet, count(subnet.ip) as ips RETURN id(subnet) as id
|
||||
"""
|
||||
Then the result should be empty
|
||||
|
||||
Scenario: Collect nodes properties into a map:
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (t:Tag {short_code: "TST", description: "SYSTEM_TAG"}), (t2:Tag {short_code: "PRD", description: "SYSTEM_TAG"}),
|
||||
(t3:Tag {short_code: "STG", description: "SYSTEM_TAG"}), (device {name: "name1"}), (device)-[a1:ASSOCIATED]->(t),
|
||||
(device)-[a2:ASSOCIATED]->(t2), (device)-[a3:ASSOCIATED]->(t3);
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (d {name: "name1"})-[t:ASSOCIATED]-(tag:Tag) RETURN collect({short_code: tag.short_code, description: tag.description}) as tags;
|
||||
"""
|
||||
Then the result should be:
|
||||
| tags |
|
||||
| [{description: 'SYSTEM_TAG', short_code: 'TST'}, {description: 'SYSTEM_TAG', short_code: 'PRD'}, {description: 'SYSTEM_TAG', short_code: 'STG'}] |
|
||||
|
||||
Scenario: Count directly without WITH clause 01
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (:Node {prop1: 1, prop2: 2, prop3: 3}), (:Node {prop1: 10, prop2: 11, prop3: 12}), (:Node {prop1: 20, prop2: 21, prop3: 22})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (n) RETURN n.prop1, n.prop2, n.prop3, count(*) AS cnt
|
||||
"""
|
||||
Then the result should be:
|
||||
| n.prop1 | n.prop2 | n.prop3 | cnt |
|
||||
| 20 | 21 | 22 | 1 |
|
||||
| 10 | 11 | 12 | 1 |
|
||||
| 1 | 2 | 3 | 1 |
|
||||
|
||||
Scenario: Count directly without WITH clause 02
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (:Node {prop1: 1, prop2: 2, prop3: 3}), (:Node {prop1: 10, prop2: 11, prop3: 12}), (:Node {prop1: 20, prop2: 21, prop3: 22})
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
MATCH (n) WITH n.prop1 AS prop1, n.prop2 AS prop2, n.prop3 AS prop3 RETURN prop1, prop2, prop3, count(*) AS cnt;
|
||||
"""
|
||||
Then the result should be:
|
||||
| prop1 | prop2 | prop3 | cnt |
|
||||
| 20 | 21 | 22 | 1 |
|
||||
| 10 | 11 | 12 | 1 |
|
||||
| 1 | 2 | 3 | 1 |
|
||||
|
Loading…
Reference in New Issue
Block a user