validate a query
| 2169 | |
| 2170 | // validate a query |
| 2171 | AST_Validation AST_Validate_Query |
| 2172 | ( |
| 2173 | const cypher_astnode_t *root // query to validate |
| 2174 | ) { |
| 2175 | const cypher_astnode_t *body = cypher_ast_statement_get_body(root); |
| 2176 | AST ast; // Build a fake AST with the correct AST root |
| 2177 | ast.root = body; |
| 2178 | |
| 2179 | cypher_astnode_type_t body_type = cypher_astnode_type(body); |
| 2180 | if(body_type == CYPHER_AST_CREATE_NODE_PROPS_INDEX || |
| 2181 | body_type == CYPHER_AST_CREATE_PATTERN_PROPS_INDEX || |
| 2182 | body_type == CYPHER_AST_DROP_PROPS_INDEX) { |
| 2183 | return _ValidateScopes(&ast); |
| 2184 | } |
| 2185 | |
| 2186 | // Verify that the RETURN clause and terminating clause do not violate scoping rules. |
| 2187 | if(_ValidateQuerySequence(&ast) != AST_VALID) { |
| 2188 | return AST_INVALID; |
| 2189 | } |
| 2190 | |
| 2191 | // Verify that the clause order in the scope is valid. |
| 2192 | if(_ValidateClauseOrder(&ast) != AST_VALID) { |
| 2193 | return AST_INVALID; |
| 2194 | } |
| 2195 | |
| 2196 | // Verify that the clauses surrounding UNION return the same column names. |
| 2197 | if(_ValidateUnion_Clauses(&ast) != AST_VALID) { |
| 2198 | return AST_INVALID; |
| 2199 | } |
| 2200 | |
| 2201 | // validate positions of allShortestPaths |
| 2202 | if(!_ValidateAllShortestPaths(body)) { |
| 2203 | ErrorCtx_SetError("RedisGraph support allShortestPaths only in match clauses"); |
| 2204 | return AST_INVALID; |
| 2205 | } |
| 2206 | |
| 2207 | if(!_ValidateShortestPaths(body)) { |
| 2208 | ErrorCtx_SetError("RedisGraph currently only supports shortestPaths in WITH or RETURN clauses"); |
| 2209 | return AST_INVALID; |
| 2210 | } |
| 2211 | |
| 2212 | // Check for invalid queries not captured by libcypher-parser |
| 2213 | return _ValidateScopes(&ast); |
| 2214 | } |
| 2215 | |
| 2216 | //------------------------------------------------------------------------------ |
| 2217 | // Query params validations |
no test coverage detected