You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jo...@apache.org on 2022/05/11 02:50:17 UTC
[incubator-age] branch master updated: Fix Bug in WHERE clause and property contraints
This is an automated email from the ASF dual-hosted git repository.
joshinnis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-age.git
The following commit(s) were added to refs/heads/master by this push:
new 691fb0d Fix Bug in WHERE clause and property contraints
691fb0d is described below
commit 691fb0d5e3dbd5ac9328a0b7842d0806cc124986
Author: Josh Innis <Jo...@gmail.com>
AuthorDate: Tue May 10 19:45:56 2022 -0700
Fix Bug in WHERE clause and property contraints
When the property contraints and the where clause are used together,
the property contraints are ignored.
There was a second issue where the where clause needs to be coerced to a
boolean value before ANDed with the property constraint quals
---
regress/expected/age_load.out | 10 ++++++++++
regress/expected/cypher_match.out | 20 ++++++++++++++++++++
regress/sql/age_load.sql | 6 ++++++
regress/sql/cypher_match.sql | 13 +++++++++++++
src/backend/parser/cypher_clause.c | 12 +++++++++---
5 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/regress/expected/age_load.out b/regress/expected/age_load.out
index c220b31..bae5924 100644
--- a/regress/expected/age_load.out
+++ b/regress/expected/age_load.out
@@ -190,6 +190,16 @@ SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'AT'})
1688849860263940 | "Austria" | "AT"
(1 row)
+SELECT * FROM cypher('agload_test_graph', $$
+ MATCH (u:Country {region : "Europe"})
+ WHERE u.name =~ 'Cro.*'
+ RETURN u.name, u.region
+$$) AS (result_1 agtype, result_2 agtype);
+ result_1 | result_2
+-----------+----------
+ "Croatia" | "Europe"
+(1 row)
+
SELECT drop_graph('agload_test_graph', true);
NOTICE: drop cascades to 7 other objects
DETAIL: drop cascades to table agload_test_graph._ag_label_vertex
diff --git a/regress/expected/cypher_match.out b/regress/expected/cypher_match.out
index febdf36..6327f10 100644
--- a/regress/expected/cypher_match.out
+++ b/regress/expected/cypher_match.out
@@ -1064,6 +1064,26 @@ $$) as (f agtype, t agtype);
"T" | "T"
(9 rows)
+--
+-- Constraints and WHERE clause together
+--
+SELECT * FROM cypher('cypher_match', $$
+ CREATE ({i: 1, j: 2, k: 3}), ({i: 1, j: 3}), ({i:2, k: 3})
+$$) as (a agtype);
+ a
+---
+(0 rows)
+
+SELECT * FROM cypher('cypher_match', $$
+ MATCH (n {j: 2})
+ WHERE n.i = 1
+ RETURN n
+$$) as (n agtype);
+ n
+--------------------------------------------------------------------------------------
+ {"id": 281474976710662, "label": "", "properties": {"i": 1, "j": 2, "k": 3}}::vertex
+(1 row)
+
--
-- Clean up
--
diff --git a/regress/sql/age_load.sql b/regress/sql/age_load.sql
index a6008ca..3516a17 100644
--- a/regress/sql/age_load.sql
+++ b/regress/sql/age_load.sql
@@ -53,4 +53,10 @@ SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country {iso2 : 'AT'})
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'AT'})
RETURN id(n), n.name, n.iso2 $$) as ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
+SELECT * FROM cypher('agload_test_graph', $$
+ MATCH (u:Country {region : "Europe"})
+ WHERE u.name =~ 'Cro.*'
+ RETURN u.name, u.region
+$$) AS (result_1 agtype, result_2 agtype);
+
SELECT drop_graph('agload_test_graph', true);
diff --git a/regress/sql/cypher_match.sql b/regress/sql/cypher_match.sql
index 057e27a..5d42d2e 100644
--- a/regress/sql/cypher_match.sql
+++ b/regress/sql/cypher_match.sql
@@ -536,6 +536,19 @@ SELECT * FROM cypher('cypher_match', $$
RETURN f.name, t.name
$$) as (f agtype, t agtype);
+--
+-- Constraints and WHERE clause together
+--
+SELECT * FROM cypher('cypher_match', $$
+ CREATE ({i: 1, j: 2, k: 3}), ({i: 1, j: 3}), ({i:2, k: 3})
+$$) as (a agtype);
+
+SELECT * FROM cypher('cypher_match', $$
+ MATCH (n {j: 2})
+ WHERE n.i = 1
+ RETURN n
+$$) as (n agtype);
+
--
-- Clean up
--
diff --git a/src/backend/parser/cypher_clause.c b/src/backend/parser/cypher_clause.c
index f74f0c4..2269d3f 100644
--- a/src/backend/parser/cypher_clause.c
+++ b/src/backend/parser/cypher_clause.c
@@ -2543,7 +2543,7 @@ static void transform_match_pattern(cypher_parsestate *cpstate, Query *query,
Expr *prop_qual = makeBoolExpr(AND_EXPR,
cpstate->property_constraint_quals, -1);
- if (quals == NIL)
+ if (expr == NULL)
{
expr = prop_qual;
}
@@ -2560,13 +2560,19 @@ static void transform_match_pattern(cypher_parsestate *cpstate, Query *query,
where_qual = (Expr *)transform_cypher_expr(cpstate, where,
EXPR_KIND_WHERE);
-
- if (quals == NIL)
+ if (expr == NULL)
{
expr = where_qual;
}
else
{
+ /*
+ * coerce the WHERE clause to a boolean before AND with the property
+ * contraints, otherwise there could be evaluation issues.
+ */
+ where_qual = (Expr *)coerce_to_boolean(pstate, (Node *)where_qual,
+ "WHERE");
+
expr = makeBoolExpr(AND_EXPR, list_make2(expr, where_qual), -1);
}
}