You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by GitBox <gi...@apache.org> on 2022/01/22 00:48:53 UTC

[GitHub] [incubator-age] jrgemignani commented on a change in pull request #173: feat: Implement `UNWIND` clause.

jrgemignani commented on a change in pull request #173:
URL: https://github.com/apache/incubator-age/pull/173#discussion_r790077243



##########
File path: src/backend/utils/adt/agtype.c
##########
@@ -9107,3 +9107,93 @@ Datum age_range(PG_FUNCTION_ARGS)
     /* convert the agtype_value to a datum to return to the caller */
     PG_RETURN_POINTER(agtype_value_to_agtype(agis_result.res));
 }
+
+PG_FUNCTION_INFO_V1(age_unnest);
+/*
+ * Agtype(Array) to SETOF agtype
+ */
+Datum age_unnest(PG_FUNCTION_ARGS)
+{
+    agtype *agtype_arg = AG_GET_ARG_AGTYPE_P(0);
+    bool block_types = PG_GETARG_BOOL(1);
+
+    ReturnSetInfo *rsi;
+    Tuplestorestate *tuple_store;
+    TupleDesc tupdesc;
+    TupleDesc ret_tdesc;
+    MemoryContext old_cxt, tmp_cxt;
+    bool skipNested = false;
+    agtype_iterator *it;
+    agtype_value v;
+    agtype_iterator_token r;
+
+    if (!AGT_ROOT_IS_ARRAY(agtype_arg))
+        ereport(ERROR,
+                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                        errmsg("cannot extract elements from an object")));
+
+    rsi = (ReturnSetInfo *) fcinfo->resultinfo;
+
+    rsi->returnMode = SFRM_Materialize;
+
+    /* it's a simple type, so don't use get_call_result_type() */
+    tupdesc = rsi->expectedDesc;
+
+    old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
+
+    ret_tdesc = CreateTupleDescCopy(tupdesc);
+    BlessTupleDesc(ret_tdesc);
+    tuple_store =
+            tuplestore_begin_heap(rsi->allowedModes & SFRM_Materialize_Random,
+                                  false, work_mem);
+
+    MemoryContextSwitchTo(old_cxt);
+
+    tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
+                                    "age_unnest temporary cxt",
+                                    ALLOCSET_DEFAULT_SIZES);
+
+    it = agtype_iterator_init(&agtype_arg->root);
+
+    while ((r = agtype_iterator_next(&it, &v, skipNested)) != WAGT_DONE)
+    {
+        skipNested = true;
+
+        if (r == WAGT_ELEM)
+        {
+            HeapTuple	tuple;
+            Datum		values[1];

Review comment:
       We do not use the PG style tabs between type and variable, just one space.

##########
File path: src/backend/parser/cypher_clause.c
##########
@@ -458,6 +468,69 @@ static Query *transform_cypher_delete(cypher_parsestate *cpstate,
     return query;
 }
 
+static Query *transform_cypher_unwind(cypher_parsestate *cpstate,
+                                      cypher_clause *clause)
+{
+    ParseState *pstate = (ParseState *) cpstate;
+    cypher_unwind *self = (cypher_unwind *) clause->self;
+

Review comment:
       Please group all of the variable definitions together, unless there are comments in between

##########
File path: src/backend/utils/adt/agtype.c
##########
@@ -9107,3 +9107,93 @@ Datum age_range(PG_FUNCTION_ARGS)
     /* convert the agtype_value to a datum to return to the caller */
     PG_RETURN_POINTER(agtype_value_to_agtype(agis_result.res));
 }
+
+PG_FUNCTION_INFO_V1(age_unnest);
+/*
+ * Agtype(Array) to SETOF agtype
+ */
+Datum age_unnest(PG_FUNCTION_ARGS)
+{
+    agtype *agtype_arg = AG_GET_ARG_AGTYPE_P(0);
+    bool block_types = PG_GETARG_BOOL(1);
+
+    ReturnSetInfo *rsi;
+    Tuplestorestate *tuple_store;
+    TupleDesc tupdesc;
+    TupleDesc ret_tdesc;
+    MemoryContext old_cxt, tmp_cxt;
+    bool skipNested = false;
+    agtype_iterator *it;
+    agtype_value v;
+    agtype_iterator_token r;
+
+    if (!AGT_ROOT_IS_ARRAY(agtype_arg))

Review comment:
       All if/then need to have braces.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org