JoshInnis commented on a change in pull request #149:
URL: https://github.com/apache/incubator-age/pull/149#discussion_r768202721



##########
File path: src/backend/parser/cypher_clause.c
##########
@@ -1320,6 +1325,161 @@ static Query *transform_cypher_match(cypher_parsestate 
*cpstate,
         cpstate, transform_cypher_match_pattern, clause, self->where);
 }
 
+static Node *
+transform_clause_for_join(cypher_parsestate *cpstate, cypher_clause *clause,
+                         RangeTblEntry **rte, ParseNamespaceItem **nsitem,
+                         Alias* alias)
+{
+    ParseState *pstate = (ParseState *)cpstate;
+    ParseNamespaceItem *tmp;
+    RangeTblRef *rtr;
+
+    *rte = transform_cypher_clause_as_subquery(cpstate,
+                                               transform_cypher_clause,
+                                               clause, alias, false);
+
+    tmp = (ParseNamespaceItem *) palloc(sizeof(ParseNamespaceItem));
+    tmp->p_rte = *rte;
+    tmp->p_rel_visible = true;
+    tmp->p_cols_visible = true;
+    tmp->p_lateral_only = false;
+    tmp->p_lateral_ok = true;
+    *nsitem = tmp;
+
+    rtr = makeNode(RangeTblRef);
+    rtr->rtindex = RTERangeTablePosn(pstate, *rte, NULL);
+
+    return (Node *) rtr;
+}
+
+static void
+get_res_cols(ParseState *pstate, RangeTblEntry *l_rte,
+             RangeTblEntry *r_rte, List **res_colnames,
+             List **res_colvars)
+{
+    List          *l_colnames;
+    List          *l_colvars;
+    List          *r_colnames;
+    List          *r_colvars;
+    ListCell   *r_lname;
+    ListCell   *r_lvar;
+    List          *colnames = NIL;
+    List          *colvars = NIL;
+
+    expandRTE(l_rte, RTERangeTablePosn(pstate, l_rte, NULL), 0, -1, false,
+              &l_colnames, &l_colvars);
+    expandRTE(r_rte, RTERangeTablePosn(pstate, r_rte, NULL), 0, -1, false,
+              &r_colnames, &r_colvars);
+
+    *res_colnames = list_concat(*res_colnames, l_colnames);
+    *res_colvars = list_concat(*res_colvars, l_colvars);
+
+    forboth(r_lname, r_colnames, r_lvar, r_colvars)
+    {
+        char      *r_colname = strVal(lfirst(r_lname));
+        ListCell   *lname;
+        ListCell   *lvar;
+        Var               *var = NULL;
+
+        forboth(lname, *res_colnames, lvar, *res_colvars)
+        {
+            char *colname = strVal(lfirst(lname));
+
+            if (strcmp(r_colname, colname) == 0)
+            {
+                var = lfirst(lvar);
+                break;
+            }
+        }
+
+        if (var == NULL)
+        {
+            colnames = lappend(colnames, lfirst(r_lname));
+            colvars = lappend(colvars, lfirst(r_lvar));
+        }
+    }
+
+    *res_colnames = list_concat(*res_colnames, colnames);
+    *res_colvars = list_concat(*res_colvars, colvars);
+}
+
+
+static RangeTblEntry *
+transform_cypher_optional_match_clause(cypher_parsestate *cpstate, 
cypher_clause *clause)
+{
+    cypher_clause         *prevclause;
+    cypher_match *self = (cypher_match *)clause->self;
+
+    RangeTblEntry *rte;
+    RangeTblEntry *l_rte, *r_rte;
+    ParseNamespaceItem *l_nsitem, *r_nsitem;
+    ParseState *pstate = (ParseState *) cpstate;
+
+    JoinExpr* j = makeNode(JoinExpr);
+    
+    List          *res_colnames = NIL, *res_colvars = NIL;
+
+    Alias         *l_alias;
+    Alias         *r_alias;
+
+    int                        i;
+    ParseNamespaceItem *nsitem;
+
+    j->jointype = JOIN_LEFT;
+
+
+    l_alias = makeAlias(CYPHER_OPT_LEFT_ALIAS, NIL);
+    r_alias = makeAlias(CYPHER_OPT_RIGHT_ALIAS, NIL);
+
+    j->larg = transform_clause_for_join(cpstate, clause->prev, &l_rte,

Review comment:
       Optional Match may be the first clause in a query. There are no cases to 
handle that situation




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to