Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
57ad9dc
WIP: Refactoring AST_RewriteStarProjections()
nafraf Jul 5, 2023
1137b34
collect_call_projections(): Remove yield_count validation
nafraf Jul 5, 2023
b6620f5
Reorganize shared code
nafraf Jul 5, 2023
ced298c
WIP: _rewrite_call_subquery_star_projections()
nafraf Jul 6, 2023
6cd3c3f
Test CALL{} using CREATE, MERGE, UNWIND, CALL
nafraf Jul 6, 2023
9d47264
replace_clause(): remove unused var scope_start
nafraf Jul 7, 2023
5906b06
Fix intermediate WITH * including new variable
nafraf Jul 7, 2023
fa6756d
Add pointer casting
nafraf Jul 7, 2023
ee1b813
Merge branch 'master' into rewrite_star_projection
nafraf Jul 7, 2023
2b9b226
Remove changes of PR #3139
nafraf Jul 10, 2023
f2e5b19
_Validate_RETURN_Clause(): Check RETURN * without vars in scope
nafraf Jul 11, 2023
4b82445
Merge branch 'master' into rewrite_star_projection
nafraf Jul 11, 2023
4b29940
Check if vars of RETURN * are part of outer scope
nafraf Jul 11, 2023
a86f7d5
Remove raxClone()
nafraf Jul 11, 2023
37f02b4
Add test CALL { ... RETURN *,var}
nafraf Jul 12, 2023
bd20572
Use vctx->ignore_identifiers in _Validate_RETURN_Clause
nafraf Jul 12, 2023
66aee9f
Add collect_non_star_projections()
nafraf Jul 12, 2023
7a3470c
Remove unneedded case from collect_return_projections()
nafraf Jul 12, 2023
63e8b06
Merge branch 'master' into rewrite_star_projection
nafraf Jul 17, 2023
70d09a9
Remove unneeded cast
nafraf Jul 17, 2023
ba88672
Fix query having WITH * after UNION
nafraf Jul 17, 2023
a622b67
Fix collect projection in _rewrite_call_subquery_star_projections()
nafraf Jul 18, 2023
acf9d3f
Add missing replace_clause in AST_RewriteStarProjections()
nafraf Jul 18, 2023
6382406
Remove unneeded casting
nafraf Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add collect_non_star_projections()
  • Loading branch information
nafraf committed Jul 12, 2023
commit 66aee9ff361e7bd8b4853bf9c66a19ade5a628d6
54 changes: 4 additions & 50 deletions src/ast/ast_rewrite_star_projections.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,31 +228,6 @@ static bool _rewrite_call_subquery_star_projections
cypher_astnode_t *inner_query =
cypher_ast_call_subquery_get_query(call_subquery);
rewritten |= AST_RewriteStarProjections(inner_query);
} else if(t == CYPHER_AST_MATCH) {
// the MATCH clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_match_get_pattern(clause);
collect_aliases_in_pattern(pattern, local_identifiers);
} else if(t == CYPHER_AST_CREATE) {
// the CREATE clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_create_get_pattern(clause);
collect_aliases_in_pattern(pattern, local_identifiers);
} else if(t == CYPHER_AST_MERGE) {
// the MERGE clause contains one path
const cypher_astnode_t *path =
cypher_ast_merge_get_pattern_path(clause);
collect_aliases_in_path(path, local_identifiers);
} else if(t == CYPHER_AST_UNWIND) {
// the UNWIND clause introduces one alias
const cypher_astnode_t *unwind_alias =
cypher_ast_unwind_get_alias(clause);
const char *identifier =
cypher_ast_identifier_get_name(unwind_alias);
raxTryInsert(local_identifiers, (unsigned char *)identifier,
strlen(identifier), (void *)unwind_alias, NULL);
} else if(t == CYPHER_AST_CALL) {
collect_call_projections(clause, local_identifiers);
} else if(t == CYPHER_AST_WITH || t == CYPHER_AST_RETURN) {
// check whether the clause contains a star projection
bool has_star = (t == CYPHER_AST_WITH) ?
Expand Down Expand Up @@ -298,6 +273,8 @@ static bool _rewrite_call_subquery_star_projections
} else {
collect_return_projections(clause, local_identifiers);
}
} else {
collect_non_star_projections(clause, local_identifiers);
}

// update last_is_union
Expand Down Expand Up @@ -336,31 +313,6 @@ bool AST_RewriteStarProjections
_rewrite_call_subquery_star_projections(root, i, identifiers);
clause = cypher_ast_query_get_clause(root, i);
collect_call_subquery_projections(clause, identifiers);
} else if(type == CYPHER_AST_MATCH) {
// the MATCH clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_match_get_pattern(clause);
collect_aliases_in_pattern(pattern, identifiers);
} else if(type == CYPHER_AST_CREATE) {
// the CREATE clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_create_get_pattern(clause);
collect_aliases_in_pattern(pattern, identifiers);
} else if(type == CYPHER_AST_MERGE) {
// the MERGE clause contains one path
const cypher_astnode_t *path =
cypher_ast_merge_get_pattern_path(clause);
collect_aliases_in_path(path, identifiers);
} else if(type == CYPHER_AST_UNWIND) {
// the UNWIND clause introduces one alias
const cypher_astnode_t *unwind_alias =
cypher_ast_unwind_get_alias(clause);
const char *identifier =
cypher_ast_identifier_get_name(unwind_alias);
raxTryInsert(identifiers, (unsigned char *)identifier,
strlen(identifier), (void *)unwind_alias, NULL);
} else if(type == CYPHER_AST_CALL) {
collect_call_projections(clause, identifiers);
} else if(type == CYPHER_AST_WITH) {
if(cypher_ast_with_has_include_existing(clause)) {
// clause contains a star projection, replace it
Expand All @@ -385,6 +337,8 @@ bool AST_RewriteStarProjections
raxFree(identifiers);
identifiers = raxNew();
collect_return_projections(clause, identifiers);
} else {
collect_non_star_projections(clause, identifiers);
}
}
raxFree(identifiers);
Expand Down
72 changes: 44 additions & 28 deletions src/ast/ast_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void UpdateCtx_Free
}

// collect aliases defined in a path
void collect_aliases_in_path
static void _collect_aliases_in_path
(
const cypher_astnode_t *path,
rax *identifiers
Expand Down Expand Up @@ -281,14 +281,14 @@ void collect_aliases_in_path
}

// collect aliases defined in a pattern
void collect_aliases_in_pattern
static void _collect_aliases_in_pattern
(
const cypher_astnode_t *pattern,
rax *identifiers
) {
uint path_count = cypher_ast_pattern_npaths(pattern);
for(uint i = 0; i < path_count; i ++) {
collect_aliases_in_path(cypher_ast_pattern_get_path(pattern, i),
_collect_aliases_in_path(cypher_ast_pattern_get_path(pattern, i),
identifiers);
}
}
Expand Down Expand Up @@ -371,6 +371,45 @@ void collect_call_projections(
}
}

// collect aliases of clauses which don't contain star projections:
// CYPHER_AST_MATCH, CYPHER_AST_CREATE, CYPHER_AST_MERGE, CYPHER_AST_UNWIND,
// and CYPHER_AST_CALL
void collect_non_star_projections
(
const cypher_astnode_t *clause,
rax *identifiers
) {

cypher_astnode_type_t type = cypher_astnode_type(clause);

if(type == CYPHER_AST_MATCH) {
// the MATCH clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_match_get_pattern(clause);
_collect_aliases_in_pattern(pattern, identifiers);
} else if(type == CYPHER_AST_CREATE) {
// the CREATE clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_create_get_pattern(clause);
_collect_aliases_in_pattern(pattern, identifiers);
} else if(type == CYPHER_AST_MERGE) {
// the MERGE clause contains one path
const cypher_astnode_t *path =
cypher_ast_merge_get_pattern_path(clause);
_collect_aliases_in_path(path, identifiers);
} else if(type == CYPHER_AST_UNWIND) {
// the UNWIND clause introduces one alias
const cypher_astnode_t *unwind_alias =
cypher_ast_unwind_get_alias(clause);
const char *identifier =
cypher_ast_identifier_get_name(unwind_alias);
raxTryInsert(identifiers, (unsigned char *)identifier,
strlen(identifier), (void *)unwind_alias, NULL);
} else if(type == CYPHER_AST_CALL) {
collect_call_projections(clause, identifiers);
}
}

// collect aliases from a CALL {} clause
void collect_call_subquery_projections
(
Expand Down Expand Up @@ -434,33 +473,10 @@ void collect_aliases_in_scope
// the WITH clause contains either
// aliases or its own STAR projection
collect_with_projections(clause, identifiers);
} else if(type == CYPHER_AST_MATCH) {
// the MATCH clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_match_get_pattern(clause);
collect_aliases_in_pattern(pattern, identifiers);
} else if(type == CYPHER_AST_CREATE) {
// the CREATE clause contains one pattern of N paths
const cypher_astnode_t *pattern =
cypher_ast_create_get_pattern(clause);
collect_aliases_in_pattern(pattern, identifiers);
} else if(type == CYPHER_AST_MERGE) {
// the MERGE clause contains one path
const cypher_astnode_t *path =
cypher_ast_merge_get_pattern_path(clause);
collect_aliases_in_path(path, identifiers);
} else if(type == CYPHER_AST_UNWIND) {
// the UNWIND clause introduces one alias
const cypher_astnode_t *unwind_alias =
cypher_ast_unwind_get_alias(clause);
const char *identifier =
cypher_ast_identifier_get_name(unwind_alias);
raxTryInsert(identifiers, (unsigned char *)identifier,
strlen(identifier), (void *)unwind_alias, NULL);
} else if(type == CYPHER_AST_CALL) {
collect_call_projections(clause, identifiers);
} else if(type == CYPHER_AST_CALL_SUBQUERY) {
collect_call_subquery_projections(clause, identifiers);
} else {
collect_non_star_projections(clause, identifiers);
}
}
}
21 changes: 5 additions & 16 deletions src/ast/ast_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,12 @@ void collect_aliases_in_scope
rax *identifiers // rax to populate with identifiers
);

// collect aliases defined in a pattern
void collect_aliases_in_pattern
// collect aliases of clauses that don't contain star projections:
// CYPHER_AST_MATCH, CYPHER_AST_CREATE, CYPHER_AST_MERGE, CYPHER_AST_UNWIND,
// and CYPHER_AST_CALL
void collect_non_star_projections
(
const cypher_astnode_t *pattern,
rax *identifiers
);

// collect aliases defined in a path
void collect_aliases_in_path
(
const cypher_astnode_t *path,
rax *identifiers
);

// collect aliases defined in a CALL clause
void collect_call_projections(
const cypher_astnode_t *call_clause,
const cypher_astnode_t *clause,
rax *identifiers
);

Expand Down