Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call subquery validate return #3107

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Conversation

nafraf
Copy link
Contributor

@nafraf nafraf commented Jun 21, 2023

Patch to validate that the returning literals in CALL subquery are aliased.

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 ⚠️

Comparison is base (9c360b2) 90.87% compared to head (aae0e80) 90.87%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3107      +/-   ##
==========================================
- Coverage   90.87%   90.87%   -0.01%     
==========================================
  Files         294      294              
  Lines       30269    30257      -12     
==========================================
- Hits        27508    27495      -13     
- Misses       2761     2762       +1     
Impacted Files Coverage Δ
src/ast/ast.c 92.16% <100.00%> (+0.24%) ⬆️
src/ast/ast_validations.c 97.46% <100.00%> (+0.34%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@raz-mon raz-mon self-requested a review June 22, 2023 05:56
Copy link
Collaborator

@raz-mon raz-mon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!
See few comments.

src/ast/ast.c Outdated Show resolved Hide resolved
src/ast/ast.c Outdated Show resolved Hide resolved
src/ast/ast_validations.c Outdated Show resolved Hide resolved
src/ast/ast_validations.c Outdated Show resolved Hide resolved
src/ast/ast_validations.c Outdated Show resolved Hide resolved
src/ast/ast.c Outdated Show resolved Hide resolved
src/ast/ast.h Outdated Show resolved Hide resolved
"WITH 1 AS a CALL {WITH a SKIP 5 RETURN a} RETURN a",
"WITH true AS a CALL {WITH NOT(a) AS b RETURN b} RETURN b",
"MATCH (n) CALL {WITH n AS n1 RETURN n1 UNION WITH n RETURN n1} RETURN n, n1",
"MATCH (n) CALL {WITH n RETURN n AS n1 UNION WITH n AS n1 RETURN n1} RETURN n, n1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the issue with this last query ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-simple import in the second branch of the UNION.

tests/flow/test_call_subquery.py Show resolved Hide resolved
src/ast/ast.h Outdated Show resolved Hide resolved
@@ -580,6 +580,26 @@ bool AST_ClauseContainsAggregation
return aggregated;
}

const char *AST_GetProjectionAlias
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please copy the comments from the header file to this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Done in 23fa13d

src/ast/ast.c Outdated
Comment on lines 616 to 619
const char *alias = AST_GetProjectionAlias(projection);
if(alias != NULL) {
array_append(columns, alias);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like AST_GetProjectionAlias can't return NULL if my understanding is correct please remove this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Condition removed in 23fa13d

if(strcmp(projections[j], alias) != 0) {
const cypher_astnode_t *proj =
cypher_ast_return_get_projection(return_clause, j);
const char *alias = AST_GetProjectionAlias(proj);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible for AST_GetProjectionAlias to return NULL ?

Copy link
Contributor Author

@nafraf nafraf Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can't return NULL. The unneeded comparison was removed from if(alias == NULL || ...

@@ -1349,23 +1340,24 @@ references to outside variables");
for(uint i = 0; i < n_projections; i++) {
const cypher_astnode_t *proj =
cypher_ast_return_get_projection(return_clause, i);
const char *var_name;
const cypher_astnode_t *identifier =
const cypher_astnode_t *alias_node =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we using alias_node ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't need it. The variable was removed in 23fa13d
Thanks.

if(alias_node == NULL) {
continue;
const cypher_astnode_t *proj = cypher_ast_return_get_projection(n, i);
const char *alias = AST_GetProjectionAlias(proj);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case AST_GetProjectionAlias returns NULL ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can no longer return NULL, the condition is no longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. The condition was removed.

src/ast/ast.h Outdated
// returns the alias of a projection
// the alias will be NULL in the case of an unaliased non-identifier projection
// returned in a Call {} clause
const char *AST_GetSubqueryProjectionAlias
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find AST_GetSubqueryProjectionAlias implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this function. Its definition was deleted in 23fa13d. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants