diff --git a/src/ast/ast_annotations_ctx_collection.c b/src/ast/ast_annotations_ctx_collection.c index 090e9c0e33..feafdb8a96 100644 --- a/src/ast/ast_annotations_ctx_collection.c +++ b/src/ast/ast_annotations_ctx_collection.c @@ -10,7 +10,6 @@ AST_AnnotationCtxCollection *AST_AnnotationCtxCollection_New() { AST_AnnotationCtxCollection *anotCtxCollection = rm_malloc(sizeof(AST_AnnotationCtxCollection)); anotCtxCollection->name_ctx = NULL; - anotCtxCollection->params_ctx = NULL; anotCtxCollection->named_paths_ctx = NULL; anotCtxCollection->project_all_ctx = NULL; return anotCtxCollection; @@ -21,11 +20,6 @@ inline AnnotationCtx *AST_AnnotationCtxCollection_GetNameCtx(const AST_Annotatio return anot_ctx_collection->name_ctx; } -inline AnnotationCtx *AST_AnnotationCtxCollection_GetParamsCtx(const AST_AnnotationCtxCollection - *anot_ctx_collection) { - return anot_ctx_collection->params_ctx; -} - inline AnnotationCtx *AST_AnnotationCtxCollection_GetNamedPathsCtx(const AST_AnnotationCtxCollection *anot_ctx_collection) { return anot_ctx_collection->named_paths_ctx; @@ -41,12 +35,6 @@ inline void AST_AnnotationCtxCollection_SetNameCtx(AST_AnnotationCtxCollection * anot_ctx_collection->name_ctx = name_ctx; } -inline void AST_AnnotationCtxCollection_SetParamsCtx(AST_AnnotationCtxCollection - *anot_ctx_collection, - AnnotationCtx *params_ctx) { - anot_ctx_collection->params_ctx = params_ctx; -} - inline void AST_AnnotationCtxCollection_SetNamedPathsCtx(AST_AnnotationCtxCollection *anot_ctx_collection, AnnotationCtx *named_paths_ctx) { @@ -62,7 +50,6 @@ inline void AST_AnnotationCtxCollection_SetProjectAllCtx(AST_AnnotationCtxCollec void AST_AnnotationCtxCollection_Free(AST_AnnotationCtxCollection *anotCtxCollection) { if(anotCtxCollection) { if(anotCtxCollection->name_ctx) cypher_ast_annotation_context_free(anotCtxCollection->name_ctx); - if(anotCtxCollection->params_ctx) cypher_ast_annotation_context_free(anotCtxCollection->params_ctx); if(anotCtxCollection->named_paths_ctx) cypher_ast_annotation_context_free( anotCtxCollection->named_paths_ctx); if(anotCtxCollection->project_all_ctx) cypher_ast_annotation_context_free( diff --git a/src/ast/ast_annotations_ctx_collection.h b/src/ast/ast_annotations_ctx_collection.h index d09d5897c5..abce0d4505 100644 --- a/src/ast/ast_annotations_ctx_collection.h +++ b/src/ast/ast_annotations_ctx_collection.h @@ -13,32 +13,23 @@ typedef cypher_ast_annotation_context_t AnnotationCtx; * specific AST nodes annotation use case. For each context there is a dedicated inlined * getter and setter. */ typedef struct { - AnnotationCtx *name_ctx; // Annotation context for naming graph entities and ORDER items. - AnnotationCtx *params_ctx; // Annotation context for query parameters. + AnnotationCtx *name_ctx; // Annotation context for naming graph entities and ORDER items. AnnotationCtx *project_all_ctx; // Context containing aliases for WITH/RETURN * projections. AnnotationCtx *named_paths_ctx; // Annotation context for named paths projections. } AST_AnnotationCtxCollection; AST_AnnotationCtxCollection *AST_AnnotationCtxCollection_New(); -AnnotationCtx *AST_AnnotationCtxCollection_GetNameCtx(const AST_AnnotationCtxCollection - *anot_ctx_collection); -AnnotationCtx *AST_AnnotationCtxCollection_GetParamsCtx(const AST_AnnotationCtxCollection - *anot_ctx_collection); -AnnotationCtx *AST_AnnotationCtxCollection_GetNamedPathsCtx(const AST_AnnotationCtxCollection - *anot_ctx_collection); -AnnotationCtx *AST_AnnotationCtxCollection_GetProjectAllCtx(const AST_AnnotationCtxCollection - *anot_ctx_collection); - -void AST_AnnotationCtxCollection_SetNameCtx(AST_AnnotationCtxCollection *anot_ctx_collection, - AnnotationCtx *name_ctx); -void AST_AnnotationCtxCollection_SetParamsCtx(AST_AnnotationCtxCollection *anot_ctx_collection, - AnnotationCtx *params_ctx); -void AST_AnnotationCtxCollection_SetNamedPathsCtx(AST_AnnotationCtxCollection *anot_ctx_collection, - AnnotationCtx *named_paths_ctx); -void AST_AnnotationCtxCollection_SetProjectAllCtx(AST_AnnotationCtxCollection *anot_ctx_collection, - AnnotationCtx *project_all_ctx); +AnnotationCtx *AST_AnnotationCtxCollection_GetNameCtx(const AST_AnnotationCtxCollection *anot_ctx_collection); -void AST_AnnotationCtxCollection_Free(AST_AnnotationCtxCollection *anot_ctx_collection); +AnnotationCtx *AST_AnnotationCtxCollection_GetNamedPathsCtx(const AST_AnnotationCtxCollection *anot_ctx_collection); + +AnnotationCtx *AST_AnnotationCtxCollection_GetProjectAllCtx(const AST_AnnotationCtxCollection *anot_ctx_collection); + +void AST_AnnotationCtxCollection_SetNameCtx(AST_AnnotationCtxCollection *anot_ctx_collection, AnnotationCtx *name_ctx); +void AST_AnnotationCtxCollection_SetNamedPathsCtx(AST_AnnotationCtxCollection *anot_ctx_collection, AnnotationCtx *named_paths_ctx); +void AST_AnnotationCtxCollection_SetProjectAllCtx(AST_AnnotationCtxCollection *anot_ctx_collection, AnnotationCtx *project_all_ctx); + +void AST_AnnotationCtxCollection_Free(AST_AnnotationCtxCollection *anot_ctx_collection); diff --git a/src/ast/ast_enrich.c b/src/ast/ast_enrich.c index d53d57ccbd..5a9f0dfead 100644 --- a/src/ast/ast_enrich.c +++ b/src/ast/ast_enrich.c @@ -5,7 +5,6 @@ */ #include "enrichment/annotate_entities.h" -#include "enrichment/annotate_params.h" #include "enrichment/annotate_project_all.h" #include "enrichment/annotate_projected_named_paths.h" @@ -20,6 +19,5 @@ void AST_Enrich(AST *ast) { AST_AnnotateEntities(ast); AST_AnnotateProjectAll(ast); AST_AnnotateNamedPaths(ast); - AST_AnnotateParams(ast); } diff --git a/src/ast/enrichment/annotate_params.c b/src/ast/enrichment/annotate_params.c deleted file mode 100644 index 037bdfaec0..0000000000 --- a/src/ast/enrichment/annotate_params.c +++ /dev/null @@ -1,72 +0,0 @@ -/* -* Copyright 2018-2020 Redis Labs Ltd. and Contributors -* -* This file is available under the Redis Labs Source Available License Agreement -*/ - -#include "../ast.h" -#include "../../util/arr.h" -#include "../../query_ctx.h" -#include "../../arithmetic/arithmetic_expression.h" - -//------------------------------------------------------------------------------ -// Annotation context - query parameters -//------------------------------------------------------------------------------ - -/* This function collects every AST node which is a named parameter place holder. If the same name - * of a parameter apears in more then one place it is append to array of all the placeholders with - * the same name. - * The function returns a rax with parameter name as key, and the array of placeholders as values. */ -static void _collect_query_params_map(const cypher_astnode_t *ast_exp, rax *parameter_map) { - cypher_astnode_type_t type = cypher_astnode_type(ast_exp); - // In case of parameter. - if(type == CYPHER_AST_PARAMETER) { - const char *identifier = cypher_ast_parameter_get_name(ast_exp); - const cypher_astnode_t **exp_arr = raxFind(parameter_map, (unsigned char *)identifier, - strlen(identifier)); - // Use array in case of same parameter is used in multiple locations. - if(exp_arr == raxNotFound) exp_arr = array_new(const cypher_astnode_t *, 1); - exp_arr = array_append(exp_arr, ast_exp); - raxInsert(parameter_map, (unsigned char *)identifier, strlen(identifier), (void *)exp_arr, NULL); - } else { - // Recurse over children. - uint child_count = cypher_astnode_nchildren(ast_exp); - for(uint i = 0; i < child_count; i++) { - const cypher_astnode_t *child = cypher_astnode_get_child(ast_exp, i); - // Recursively continue mapping. - _collect_query_params_map(child, parameter_map); - } - } -} - -static void _annotate_params(AST *ast) { - // Check for number of parameters, if there aren't any, return; - rax *params_values = QueryCtx_GetParams(); - if(!params_values || raxSize(params_values) == 0) return; - AnnotationCtx *params_ctx = AST_AnnotationCtxCollection_GetParamsCtx(ast->anot_ctx_collection); - rax *query_params_map = raxNew(); - _collect_query_params_map(ast->root, query_params_map); - raxIterator iter; - raxStart(&iter, query_params_map); - raxSeek(&iter, "^", NULL, 0); - while(raxNext(&iter)) { - const char *key = (const char *)iter.key; - const cypher_astnode_t **exp_arr = iter.data; - const cypher_astnode_t *param_value = raxFind(params_values, (unsigned char *) key, iter.key_len); - assert(param_value != raxNotFound); - uint array_length = array_len(exp_arr); - for(uint i = 0; i < array_length; i++) { - cypher_astnode_attach_annotation(params_ctx, exp_arr[i], (void *)param_value, NULL); - } - - } - raxStop(&iter); - raxFreeWithCallback(query_params_map, array_free); -} - -void AST_AnnotateParams(AST *ast) { - AnnotationCtx *param_ctx = cypher_ast_annotation_context(); - AST_AnnotationCtxCollection_SetParamsCtx(ast->anot_ctx_collection, param_ctx); - _annotate_params(ast); -} - diff --git a/src/ast/enrichment/annotate_params.h b/src/ast/enrichment/annotate_params.h deleted file mode 100644 index 359baf7424..0000000000 --- a/src/ast/enrichment/annotate_params.h +++ /dev/null @@ -1,11 +0,0 @@ -/* -* Copyright 2018-2020 Redis Labs Ltd. and Contributors -* -* This file is available under the Redis Labs Source Available License Agreement -*/ - -#pragma once - -#include "../ast.h" - -void AST_AnnotateParams(AST *ast);