Skip to content

Commit 6a7f88c

Browse files
committed
Fix Vertex creation of to vertices in MAtch
1 parent 58b0a8e commit 6a7f88c

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

postgraph--0.1.0.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,24 @@ AS 'MODULE_PATHNAME';
442442

443443

444444
CREATE FUNCTION retrieve_vertex(graph_oid gtype, id graphid)
445-
RETURNS TABLE (properties gtype)
445+
RETURNS gtype
446446
RETURNS NULL ON NULL INPUT
447447
STABLE
448448
PARALLEL SAFE
449449
LANGUAGE C
450450
COST 5000
451451
AS 'MODULE_PATHNAME';
452452

453+
454+
--CREATE FUNCTION retrieve_vertex(graph_oid gtype, id graphid)
455+
--RETURNS TABLE (properties gtype)
456+
--RETURNS NULL ON NULL INPUT
457+
--STABLE
458+
--PARALLEL SAFE
459+
--LANGUAGE C
460+
--COST 5000
461+
--AS 'MODULE_PATHNAME';
462+
453463
--
454464
-- There are times when the optimizer might eliminate
455465
-- functions we need. Wrap the function with this to

src/backend/parser/cypher_clause.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,6 @@ add_vertex_retrieval_to_query(cypher_parsestate *cpstate, Query *query, cypher_n
10991099

11001100
Var *var;
11011101
if (var = colNameToVar(cpstate, make_id_alias(node->name), false, -1)) {
1102-
// ereport(WARNING,(errcode(ERRCODE_UNDEFINED_SCHEMA),
1103-
// errmsg("here")));
11041102
node->declared_in_previous_clause = true;
11051103

11061104
*quals = lappend(*quals,
@@ -1111,7 +1109,6 @@ add_vertex_retrieval_to_query(cypher_parsestate *cpstate, Query *query, cypher_n
11111109
return refnameNamespaceItem(cpstate, NULL, PREV_CYPHER_CLAUSE_ALIAS, -1, NULL);
11121110
}
11131111

1114-
int sublevels_up;
11151112
ParseNamespaceItem *pnsi = refnameNamespaceItem(cpstate, NULL, node->name, -1, NULL);
11161113
if (pnsi) {
11171114
node->in_join_tree = false;

src/backend/utils/adt/vertex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ create_vertex(graphid id, Oid graph_oid, gtype *properties) {
127127
append_to_buffer(&buffer, (char *)&graph_oid, sizeof(Oid));
128128

129129
// properties
130-
if (properties == NULL) {
130+
if (!properties) {
131131
gtype_in_state result;
132132

133133
memset(&result, 0, sizeof(gtype_in_state));

src/backend/utils/edge_searching.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static Datum get_vertex(Oid graph_oid, int64 graphid, bool *isnull)
7070
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_TABLE), errmsg("id %lu does not exist", graphid)));
7171

7272
Datum properties = heap_getattr(tuple, 2, RelationGetDescr(rel), isnull);
73-
73+
//*isnull = false;
7474
table_endscan(scan_desc);
7575
table_close(rel, ShareLock);
7676

@@ -79,6 +79,38 @@ static Datum get_vertex(Oid graph_oid, int64 graphid, bool *isnull)
7979

8080

8181

82+
PG_FUNCTION_INFO_V1(retrieve_vertex);
83+
Datum retrieve_vertex(PG_FUNCTION_ARGS) {
84+
Oid graph_oid = GT_ARG_TO_INT4_DATUM(0);
85+
int64 graphid = AG_GETARG_GRAPHID(1);
86+
bool isnull;
87+
88+
label_cache_data *lcd = search_label_graph_oid_cache(graph_oid, (graphid >> ENTRY_ID_BITS));
89+
90+
ScanKeyData scan_keys[1];
91+
ScanKeyInit(&scan_keys[0], 1, BTEqualStrategyNumber, F_OIDEQ, Int64GetDatum(graphid));
92+
93+
Relation rel = table_open(lcd->relation, ShareLock);
94+
95+
TableScanDesc scan_desc = table_beginscan(rel, GetActiveSnapshot(), 1, scan_keys);
96+
97+
HeapTuple tuple;
98+
if (!HeapTupleIsValid(tuple = heap_getnext(scan_desc, ForwardScanDirection)))
99+
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_TABLE), errmsg("id %lu does not exist", graphid)));
100+
101+
Datum properties = heap_getattr(tuple, 2, RelationGetDescr(rel), &isnull);
102+
103+
table_endscan(scan_desc);
104+
table_close(rel, ShareLock);
105+
106+
if (isnull)
107+
PG_RETURN_NULL();
108+
109+
AG_RETURN_GTYPE_P(properties);
110+
111+
}
112+
113+
/*
82114
PG_FUNCTION_INFO_V1(retrieve_vertex);
83115
Datum retrieve_vertex(PG_FUNCTION_ARGS) {
84116
@@ -100,7 +132,7 @@ Datum retrieve_vertex(PG_FUNCTION_ARGS) {
100132
101133
SRF_RETURN_DONE(funcctx);
102134
}
103-
135+
*/
104136

105137
typedef struct edge_search_cxt
106138
{

0 commit comments

Comments
 (0)