Skip to content

Commit 9de3079

Browse files
committed
Implement CREATE EXTENSION
dang, thought that would help...
1 parent 97d4709 commit 9de3079

File tree

7 files changed

+246
-342
lines changed

7 files changed

+246
-342
lines changed

regress/expected/cypher_match.out

+144-208
Large diffs are not rendered by default.

regress/expected/new_cypher.out

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
-- Regression tests don't preload extensions, gotta load it first
1818
LOAD 'postgraph';
19+
CREATE EXTENSION postgraph;
20+
ERROR: extension "postgraph" already exists
21+
CREATE EXTENSION hstore;
1922
-- Basic Graph creation
2023
CREATE GRAPH new_cypher;
2124
NOTICE: graph "new_cypher" has been created

regress/expected/order_by.out

+60-132
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,91 @@
11
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one
3-
* or more contributor license agreements. See the NOTICE file
4-
* distributed with this work for additional information
5-
* regarding copyright ownership. The ASF licenses this file
6-
* to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You may obtain a copy of the License at
2+
* Copyright (C) 2023-2024 PostGraphDB
93
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
118
*
12-
* Unless required by applicable law or agreed to in writing,
13-
* software distributed under the License is distributed on an
14-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
* KIND, either express or implied. See the License for the
16-
* specific language governing permissions and limitations
17-
* under the License.
18-
*/
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*
17+
* Portions Copyright (c) 2020-2023, Apache Software Foundation
18+
* Portions Copyright (c) 2019-2020, Bitnine Global
19+
*/
1920
LOAD 'postgraph';
20-
SET search_path TO postgraph;
21-
SELECT create_graph('order_by');
21+
CREATE GRAPH order_by;
2222
NOTICE: graph "order_by" has been created
2323
create_graph
2424
--------------
2525

2626
(1 row)
2727

28-
SELECT * FROM cypher('order_by', $$CREATE ()$$) AS (result gtype);
29-
result
30-
--------
31-
(0 rows)
28+
USE GRAPH order_by;
29+
use_graph
30+
-----------
31+
32+
(1 row)
3233

33-
SELECT * FROM cypher('order_by', $$CREATE ({i: '1', j: 1})$$) AS (result gtype);
34-
result
35-
--------
34+
CREATE ();
35+
--
3636
(0 rows)
3737

38-
SELECT * FROM cypher('order_by', $$CREATE ({i: 1})$$) AS (result gtype);
39-
result
40-
--------
38+
CREATE ({i: '1', j: 1});
39+
--
4140
(0 rows)
4241

43-
SELECT * FROM cypher('order_by', $$CREATE ({i: 1.0})$$) AS (result gtype);
44-
result
45-
--------
42+
CREATE ({i: 1});
43+
--
4644
(0 rows)
4745

48-
SELECT * FROM cypher('order_by', $$CREATE ({i: 1::numeric})$$) AS (result gtype);
49-
result
50-
--------
46+
CREATE ({i: 1.0});
47+
--
5148
(0 rows)
5249

53-
SELECT * FROM cypher('order_by', $$CREATE ({i: true})$$) AS (result gtype);
54-
result
55-
--------
50+
CREATE ({i: 1::numeric});
51+
--
5652
(0 rows)
5753

58-
SELECT * FROM cypher('order_by', $$CREATE ({i: false})$$) AS (result gtype);
59-
result
60-
--------
54+
CREATE ({i: true});
55+
--
6156
(0 rows)
6257

63-
SELECT * FROM cypher('order_by', $$CREATE ({i: {key: 'value'}})$$) AS (result gtype);
64-
result
65-
--------
58+
CREATE ({i: false});
59+
--
6660
(0 rows)
6761

68-
SELECT * FROM cypher('order_by', $$CREATE ({i: [1]})$$) AS (result gtype);
69-
result
70-
--------
62+
CREATE ({i: {key: 'value'}});
63+
--
7164
(0 rows)
7265

73-
SELECT * FROM cypher('order_by', $$
74-
MATCH (u)
75-
RETURN u.i
76-
ORDER BY u.i
77-
$$) AS (i gtype);
78-
i
79-
------------------
80-
{"key": "value"}
81-
[1]
82-
"1"
83-
false
84-
true
85-
1::numeric
86-
1
87-
1.0
88-
89-
(9 rows)
90-
91-
SELECT * FROM cypher('order_by', $$
92-
MATCH (u)
93-
RETURN u.i
94-
ORDER BY u.i DESC
95-
$$) AS (i gtype);
96-
i
97-
------------------
98-
99-
1
100-
1.0
101-
1::numeric
102-
true
103-
false
104-
"1"
105-
[1]
106-
{"key": "value"}
107-
(9 rows)
108-
109-
SELECT * FROM cypher('order_by', $$
110-
MATCH (x)
111-
RETURN x.j ORDER BY x.j NULLS FIRST
112-
$$) AS (j gtype);
113-
j
114-
---
115-
116-
117-
118-
119-
120-
121-
122-
123-
1
124-
(9 rows)
125-
126-
SELECT * FROM cypher('order_by', $$
127-
MATCH (x)
128-
RETURN x.j ORDER BY x.j NULLS LAST
129-
$$) AS (j gtype);
130-
j
131-
---
132-
1
133-
134-
135-
136-
137-
138-
139-
140-
141-
(9 rows)
142-
143-
SELECT * FROM cypher('order_by', $$
144-
MATCH (x)
145-
RETURN x.i ORDER BY x.i USING <
146-
$$) AS (i gtype);
147-
i
148-
------------------
149-
{"key": "value"}
150-
[1]
151-
"1"
152-
false
153-
true
154-
1::numeric
155-
1
156-
1.0
157-
158-
(9 rows)
66+
CREATE ({i: [1]});
67+
--
68+
(0 rows)
15969

160-
SELECT drop_graph('order_by', true);
70+
MATCH (u) RETURN u.i ORDER BY u.i;
71+
ERROR: operator does not exist: postgraph.vertex -> postgraph.gtype
72+
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
73+
MATCH (u) RETURN u.i ORDER BY u.i DESC;
74+
ERROR: operator does not exist: postgraph.vertex -> postgraph.gtype
75+
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
76+
MATCH (u) RETURN u.i ORDER BY u.i ASC;
77+
ERROR: operator does not exist: postgraph.vertex -> postgraph.gtype
78+
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
79+
MATCH (x) RETURN x.j ORDER BY x.j NULLS FIRST;
80+
ERROR: operator does not exist: postgraph.vertex -> postgraph.gtype
81+
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
82+
MATCH (x) RETURN x.j ORDER BY x.j NULLS LAST;
83+
ERROR: operator does not exist: postgraph.vertex -> postgraph.gtype
84+
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
85+
MATCH (x) RETURN x.i ORDER BY x.i USING <;
86+
ERROR: operator does not exist: postgraph.vertex -> postgraph.gtype
87+
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
88+
DROP GRAPH order_by CASCADE;
16189
NOTICE: drop cascades to 2 other objects
16290
DETAIL: drop cascades to table order_by._ag_label_vertex
16391
drop cascades to table order_by._ag_label_edge

regress/sql/new_cypher.sql

+4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717
-- Regression tests don't preload extensions, gotta load it first
18+
1819
LOAD 'postgraph';
1920

21+
CREATE EXTENSION postgraph;
22+
CREATE EXTENSION hstore;
23+
2024
-- Basic Graph creation
2125
CREATE GRAPH new_cypher;
2226

src/backend/parser/cypher_analyze.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -1157,8 +1157,23 @@ CypherCreateCommandTag(Node *parsetree)
11571157
break;
11581158

11591159
default:
1160+
{
1161+
if (IsA(parsetree, List)) {
1162+
1163+
List *lst = parsetree;
1164+
if (list_length(lst) == 1) {
1165+
Node *n = linitial(lst);
1166+
1167+
if (IsA(n, CreateExtensionStmt)) {
1168+
tag = CMDTAG_CREATE_EXTENSION;
1169+
break;
1170+
}
1171+
}
1172+
}
1173+
11601174
tag = CMDTAG_SELECT;
11611175
break;
1176+
}
11621177
}
11631178

11641179
return tag;
@@ -1343,6 +1358,8 @@ Oid get_session_graph_oid()
13431358
return graph_oid;
13441359
}
13451360

1361+
1362+
13461363
/*
13471364
* parse_analyze
13481365
* Analyze a raw parse tree and transform it to Query form.
@@ -1377,7 +1394,12 @@ cypher_parse_analyze(RawStmt *parseTree, const char *sourceText,
13771394
if (list_length(parseTree->stmt) == 1) {
13781395
Node *n = linitial(parseTree->stmt);
13791396

1380-
if (is_ag_node(n, cypher_create_graph)) {
1397+
if (IsA(n, CreateExtensionStmt)) {
1398+
query = parse_analyze((makeRawStmt(n, 0)), sourceText, paramTypes, numParams,
1399+
queryEnv);
1400+
1401+
return query;
1402+
} else if (is_ag_node(n, cypher_create_graph)) {
13811403
cypher_create_graph *ccg = n;
13821404
//ereport(ERROR, errmsg("Here"));
13831405

src/backend/parser/cypher_gram.y

+11-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
BETWEEN BY
8989
CALL CASE CASCADE COALESCE CONTAINS CREATE CUBE CURRENT CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP
9090
DATE DECADE DELETE DESC DESCENDING DETACH DISTINCT DROP
91-
ELSE END_P ENDS EXCEPT EXCLUDE EXISTS EXTRACT
91+
ELSE END_P ENDS EXCEPT EXCLUDE EXISTS EXTENSION EXTRACT
9292
GRAPH GROUP GROUPS GROUPING
9393
FALSE_P FILTER FIRST_P FOLLOWING FROM
9494
HAVING
@@ -970,6 +970,16 @@ create:
970970
n->graph_name = $3;
971971

972972
$$ = (Node *)n;
973+
}
974+
| CREATE EXTENSION IDENTIFIER
975+
{
976+
CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
977+
978+
n->extname = $3;
979+
n->if_not_exists = false;
980+
n->options = NULL;
981+
982+
$$ = (Node *) n;
973983
}
974984
;
975985

src/include/parser/cypher_kwlist.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ PG_KEYWORD("end", END_P, RESERVED_KEYWORD)
2929
PG_KEYWORD("ends", ENDS, RESERVED_KEYWORD)
3030
PG_KEYWORD("except", EXCEPT, RESERVED_KEYWORD)
3131
PG_KEYWORD("exists", EXISTS, RESERVED_KEYWORD)
32+
PG_KEYWORD("extension", EXTENSION, RESERVED_KEYWORD)
3233
PG_KEYWORD("extract", EXTRACT, RESERVED_KEYWORD)
3334
PG_KEYWORD("false", FALSE_P, RESERVED_KEYWORD)
3435
PG_KEYWORD("filter", FILTER, RESERVED_KEYWORD)

0 commit comments

Comments
 (0)