Skip to content

Commit 603f4e2

Browse files
committed
Support MATCH Variables in endpoint
Inefficient, to be redone, but it works
1 parent 3e8affd commit 603f4e2

4 files changed

Lines changed: 59 additions & 17 deletions

File tree

postgraph--0.1.0.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ AS 'MODULE_PATHNAME';
313313
CREATE FUNCTION build_vertex(graphid, oid, gtype)
314314
RETURNS vertex
315315
LANGUAGE c
316-
IMMUTABLE
316+
STABLE
317317
CALLED ON NULL INPUT
318318
PARALLEL SAFE
319319
COST 50
@@ -442,7 +442,7 @@ AS 'MODULE_PATHNAME';
442442

443443

444444
CREATE FUNCTION retrieve_vertex(graph_oid gtype, id graphid)
445-
RETURNS gtype
445+
RETURNS TABLE (properties gtype)
446446
RETURNS NULL ON NULL INPUT
447447
STABLE
448448
PARALLEL SAFE
@@ -590,9 +590,9 @@ CREATE OPERATOR = (
590590
COMMUTATOR = =,
591591
NEGATOR = <>,
592592
RESTRICT = eqsel,
593-
JOIN = eqjoinsel--,
594-
--HASHES,
595-
--MERGES
593+
JOIN = eqjoinsel,
594+
HASHES,
595+
MERGES
596596
);
597597

598598
CREATE FUNCTION graphid_ne(graphid, graphid)

regress/sql/cypher_create.sql

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ MATCH ()<-[]-() RETURN 1;
6464
MATCH ()<-[q]-() RETURN 1;
6565

6666

67-
MATCH ()<-[q]-() RETURN q;
68-
69-
MATCH (e)<-[q]-() RETURN q, e;
70-
71-
/*
7267
MATCH (a)-[]->() RETURN a;
7368

7469
MATCH (a)<-[]-() RETURN a;
@@ -77,7 +72,7 @@ MATCH (a)<-[]-() RETURN a;
7772
MATCH ()-[]->(a) RETURN a;
7873

7974
MATCH ()<-[]-(a) RETURN a;
80-
*/
75+
8176
SELECT * FROM cypher_create._ag_label_vertex;
8277

8378
SELECT * FROM cypher_create._adj__adj__ag_label_vertex;

src/backend/utils/adt/vertex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ build_vertex(PG_FUNCTION_ARGS) {
102102
graphid id = AG_GETARG_GRAPHID(0);
103103
Oid graph_oid = PG_GETARG_OID(1);
104104
gtype *properties = NULL;
105-
if (!PG_ARGISNULL(2)) {
105+
/* if (!PG_ARGISNULL(2)) {
106106
properties = AG_GET_ARG_GTYPE_P(2);
107107
108108
if (!AGT_ROOT_IS_OBJECT(properties))
109109
PG_RETURN_NULL();
110110
}
111-
111+
*/
112112
AG_RETURN_VERTEX(create_vertex(id, graph_oid, properties));
113113
}
114114

src/backend/utils/edge_searching.c

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,57 @@ static Datum get_vertex(Oid graph_oid, int64 graphid)
8787

8888
PG_FUNCTION_INFO_V1(retrieve_vertex);
8989
Datum retrieve_vertex(PG_FUNCTION_ARGS) {
90-
gtype *graph_oid = GT_ARG_TO_INT4_DATUM(0);
91-
graphid id = AG_GETARG_GRAPHID(1);
90+
91+
//PG_RETURN_POINTER(get_vertex(graph_oid, id));
92+
93+
//gtype *graph_oid = GT_ARG_TO_INT4_DATUM(0);
94+
//graphid id = AG_GETARG_GRAPHID(1);
9295

93-
PG_RETURN_POINTER(get_vertex(graph_oid, id));
96+
//lquery *label = PG_GETARG_LQUERY_P(1);
97+
//bool include_props = PG_GETARG_BOOL(2);
98+
FuncCallContext *funcctx;
99+
if (SRF_IS_FIRSTCALL())
100+
{
101+
MemoryContext oldcontext;
102+
TupleDesc tupdesc;
103+
104+
funcctx = SRF_FIRSTCALL_INIT();
105+
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
106+
107+
tupdesc = CreateTemplateTupleDesc(1);
108+
109+
tupdesc->tdtypeid = RECORDOID; /* not right, but we don't care */
110+
tupdesc->tdtypmod = -1;
111+
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "properties",
112+
GTYPEOID, -1, 0);
113+
114+
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
115+
116+
MemoryContextSwitchTo(oldcontext);
117+
118+
funcctx = SRF_PERCALL_SETUP();
119+
120+
121+
Datum values[1];
122+
bool nulls[1];
123+
HeapTuple tuple1;
124+
gtype *graph_oid = GT_ARG_TO_INT4_DATUM(0);
125+
graphid id = AG_GETARG_GRAPHID(1);
126+
127+
bool isnull;
128+
values[0] = get_vertex(graph_oid, id);
129+
nulls[0] = true;
130+
tuple1 = heap_form_tuple(funcctx->tuple_desc, values, nulls);
131+
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple1));
132+
}
133+
134+
SRF_RETURN_DONE(funcctx);
135+
136+
137+
138+
139+
140+
94141
}
95142

96143

@@ -190,7 +237,7 @@ Datum edge_search(PG_FUNCTION_ARGS)
190237
//ereport(WARNING, errmsg("value %lu", DatumGetInt64(values[2])));
191238
values[3] = heap_getattr(cxt->slot->tts_ops->get_heap_tuple(cxt->slot), 4, RelationGetDescr(vertex_desc->desc[0]->rs_rd), &isnull);
192239
nulls[3] = isnull;
193-
tuple1 = heap_form_tuple(funcctx->tuple_desc, &values, &nulls);
240+
tuple1 = heap_form_tuple(funcctx->tuple_desc, values, nulls);
194241
//cxt->slot->tts_ops->get_heap_tuple(cxt->slot);
195242

196243
//tuple1 = cxt->slot->tts_ops->copy_heap_tuple(cxt->slot);

0 commit comments

Comments
 (0)