introduce aliases of a WITH clause to the bound vars return true if no errors where encountered, false otherwise
| 105 | // introduce aliases of a WITH clause to the bound vars |
| 106 | // return true if no errors where encountered, false otherwise |
| 107 | static bool _AST_GetWithAliases |
| 108 | ( |
| 109 | const cypher_astnode_t *node, // ast-node from which to retrieve the aliases |
| 110 | rax *aliases // rax to which to insert the aliases |
| 111 | ) { |
| 112 | if(!node || (cypher_astnode_type(node) != CYPHER_AST_WITH)) { |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | // local env to check for duplicate column names |
| 117 | rax *local_env = raxNew(); |
| 118 | |
| 119 | // traverse the projections |
| 120 | uint num_with_projections = cypher_ast_with_nprojections(node); |
| 121 | for(uint i = 0; i < num_with_projections; i ++) { |
| 122 | const cypher_astnode_t *child = cypher_ast_with_get_projection(node, i); |
| 123 | const cypher_astnode_t *alias_node = cypher_ast_projection_get_alias(child); |
| 124 | const char *alias; |
| 125 | if(alias_node) { |
| 126 | // Retrieve "a" from "WITH [1, 2, 3] as a" |
| 127 | alias = cypher_ast_identifier_get_name(alias_node); |
| 128 | } else { |
| 129 | // Retrieve "a" from "WITH a" |
| 130 | const cypher_astnode_t *expr = cypher_ast_projection_get_expression(child); |
| 131 | if(cypher_astnode_type(expr) != CYPHER_AST_IDENTIFIER) { |
| 132 | ErrorCtx_SetError("WITH clause projections must be aliased"); |
| 133 | raxFree(local_env); |
| 134 | return false; |
| 135 | } |
| 136 | alias = cypher_ast_identifier_get_name(expr); |
| 137 | } |
| 138 | raxInsert(aliases, (unsigned char *)alias, strlen(alias), NULL, NULL); |
| 139 | |
| 140 | // check for duplicate column names (other than internal representation |
| 141 | // of outer-context variables) |
| 142 | if(raxTryInsert(local_env, (unsigned char *)alias, strlen(alias), NULL, |
| 143 | NULL) == 0 && |
| 144 | alias[0] != '@') { |
| 145 | ErrorCtx_SetError("Error: Multiple result columns with the same name are not supported."); |
| 146 | raxFree(local_env); |
| 147 | return false; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | raxFree(local_env); |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | // Extract identifiers / aliases from a procedure call. |
| 156 | static void _AST_GetProcCallAliases |
no test coverage detected