Skip to content

Commit 8ca54ec

Browse files
committed
Support one vertex in match with no variable name or label
1 parent b96e3bb commit 8ca54ec

9 files changed

Lines changed: 440 additions & 232 deletions

File tree

regress/expected/cypher_create.out

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,29 @@ USE GRAPH cypher_create;
3232
(1 row)
3333

3434
CREATE ();
35-
ERROR: unexpected Node for cypher_clause
35+
WARNING: relcache reference leak: relation "_ag_label_vertex" not closed
36+
--
37+
(0 rows)
38+
39+
SELECT * FROM cypher_create._ag_label_vertex;
40+
id | properties
41+
-----------------+------------
42+
281474976710657 |
43+
(1 row)
44+
45+
MATCH () RETURN 1;
46+
?column?
47+
----------
48+
1
49+
(1 row)
50+
3651
CREATE ()-[]->();
37-
ERROR: unexpected Node for cypher_clause
52+
ERROR: CREATE doesn't work with paths
53+
CYPHER WITH 1 as a
54+
CREATE ();
55+
ERROR: CREATE doesn't work with previous clauses
56+
CREATE () RETURN 1 as a;
57+
ERROR: CREATE doesn't work with next clauses
3858
--
3959
-- Clean up
4060
--

regress/sql/cypher_create.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ CREATE GRAPH cypher_create;
2525
USE GRAPH cypher_create;
2626

2727
CREATE ();
28+
SELECT * FROM cypher_create._ag_label_vertex;
29+
30+
MATCH () RETURN 1;
2831

2932
CREATE ()-[]->();
3033

34+
CYPHER WITH 1 as a
35+
CREATE ();
36+
37+
CREATE () RETURN 1 as a;
38+
3139
--
3240
-- Clean up
3341
--

src/backend/catalog/ag_label.c

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@
4545
#include "utils/ag_cache.h"
4646
#include "utils/graphid.h"
4747

48-
49-
50-
51-
static ResultRelInfo *create_entity_result_rel_info(EState *estate, char *graph_name,
52-
char *label_name);
53-
5448
PG_FUNCTION_INFO_V1(ltree_in);
5549
PG_FUNCTION_INFO_V1(ltree_addltree);
5650

@@ -282,111 +276,4 @@ RangeVar *get_label_range_var(char *graph_name, Oid graph_oid,
282276
return makeRangeVar(graph_name, relname, 2);
283277
}
284278

285-
#include "parser/parse_node.h"
286-
/*
287-
* Given the graph name and the label name, create a ResultRelInfo for the table
288-
* those to variables represent. Open the Indices too.
289-
*/
290-
ResultRelInfo *create_entity_result_rel_info(EState *estate, char *graph_name,
291-
char *label_name)
292-
{
293-
RangeVar *rv;
294-
Relation label_relation;
295-
ResultRelInfo *resultRelInfo;
296-
297-
ParseState *pstate = make_parsestate(NULL);
298-
299-
resultRelInfo = palloc(sizeof(ResultRelInfo));
300-
301-
if (strlen(label_name) == 0)
302-
{
303-
rv = makeRangeVar(graph_name, AG_DEFAULT_LABEL_VERTEX, -1);
304-
}
305-
else
306-
{
307-
rv = makeRangeVar(graph_name, label_name, -1);
308-
}
309-
310-
label_relation = parserOpenTable(pstate, rv, RowExclusiveLock);
311-
312-
// initialize the resultRelInfo
313-
InitResultRelInfo(resultRelInfo, label_relation,
314-
list_length(estate->es_range_table), NULL,
315-
estate->es_instrument);
316-
317-
// open the parse state
318-
ExecOpenIndices(resultRelInfo, false);
319-
320-
free_parsestate(pstate);
321-
322-
return resultRelInfo;
323-
}
324-
325279

326-
/*
327-
* Retrieves a list of all the names of a graph.
328-
*
329-
* XXX: We may want to use the cache system for this function,
330-
* however the cache system currently requires us to know the
331-
* name of the label we want.
332-
*/
333-
List *get_all_edge_labels_per_graph(EState *estate, Oid graph_oid)
334-
{
335-
List *labels = NIL;
336-
ScanKeyData scan_keys[2];
337-
Relation ag_label;
338-
TableScanDesc scan_desc;
339-
HeapTuple tuple;
340-
TupleTableSlot *slot;
341-
ResultRelInfo *resultRelInfo;
342-
343-
// setup scan keys to get all edges for the given graph oid
344-
ScanKeyInit(&scan_keys[1], Anum_ag_label_graph, BTEqualStrategyNumber,
345-
F_OIDEQ, ObjectIdGetDatum(graph_oid));
346-
ScanKeyInit(&scan_keys[0], Anum_ag_label_kind, BTEqualStrategyNumber,
347-
F_CHAREQ, CharGetDatum(LABEL_TYPE_EDGE));
348-
349-
// setup the table to be scanned
350-
ag_label = table_open(ag_label_relation_id(), RowExclusiveLock);
351-
scan_desc = table_beginscan(ag_label, estate->es_snapshot, 2, scan_keys);
352-
353-
resultRelInfo = create_entity_result_rel_info(estate, CATALOG_SCHEMA,
354-
"ag_label");
355-
356-
slot = ExecInitExtraTupleSlot(
357-
estate, RelationGetDescr(resultRelInfo->ri_RelationDesc),
358-
&TTSOpsHeapTuple);
359-
360-
// scan through the results and get all the label names.
361-
while(true)
362-
{
363-
Name label;
364-
bool isNull;
365-
Datum datum;
366-
367-
tuple = heap_getnext(scan_desc, ForwardScanDirection);
368-
369-
// no more labels to process
370-
if (!HeapTupleIsValid(tuple))
371-
break;
372-
373-
ExecStoreHeapTuple(tuple, slot, false);
374-
375-
datum = slot_getattr(slot, Anum_ag_label_name, &isNull);
376-
label = DatumGetName(datum);
377-
378-
labels = lappend(labels, label);
379-
}
380-
381-
table_endscan(scan_desc);
382-
383-
// close the indices
384-
ExecCloseIndices(resultRelInfo);
385-
386-
// close the rel
387-
table_close(resultRelInfo->ri_RelationDesc, RowExclusiveLock);
388-
389-
table_close(resultRelInfo->ri_RelationDesc, RowExclusiveLock);
390-
391-
return labels;
392-
}

src/backend/commands/graph_commands.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ Datum create_graph(PG_FUNCTION_ARGS)
188188
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
189189
errmsg("graph name must not be NULL")));
190190

191-
/*
192-
graph_name = PG_GETARG_NAME(0);
193-
194-
graph_name_str = NameStr(*graph_name);*/
195191
graph_name_str = TextDatumGetCString(PG_GETARG_DATUM(0));
196192
if (graph_exists(graph_name_str))
197193
ereport(ERROR,

src/backend/commands/label_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ static List *create_vertex_table_elements(char *graph_name, char *label_name,
788788
// "properties" gtype NOT NULL DEFAULT CATALOG_SCHEMA."gtype_build_map"()
789789
props = makeColumnDef(AG_VERTEX_COLNAME_PROPERTIES, GTYPEOID, -1,
790790
InvalidOid);
791-
props->constraints = list_make2(build_not_null_constraint(),
791+
props->constraints = list_make2(build_null_constraint(),
792792
build_properties_default());
793793

794794
return list_make2(id, props);

0 commit comments

Comments
 (0)