This rewriter makes sure that all return items in a RETURN clauses are aliased, and moves any ORDER BY to a preceding WITH clause
This rewriter normalizes the scoping structure of a query, ensuring it is able to be correctly processed for semantic checking.
This rewriter normalizes the scoping structure of a query, ensuring it is able to be correctly processed for semantic checking. It makes sure that all return items in a WITH clauses are aliased, and ensures all ORDER BY and WHERE expressions are shifted into the clause, leaving only a variable. That variable must also appear as an alias in the associated WITH.
This rewriter depends on normalizeReturnClauses having first been run.
Example:
MATCH n WITH n.prop AS prop ORDER BY n.foo DESC RETURN prop
This rewrite will change the query to:
MATCH n
WITH n AS n, n.prop AS prop
WITH prop AS prop, n.foo AS FRESHID39 ORDER BY FRESHID39 DESC
WITH prop AS prop
RETURN prop
It uses multiple WITH clauses to ensure that cardinality and grouping are not altered, even in the presence of aggregation.
This rewriter makes sure that aggregations are on their own in RETURN/WITH clauses, so the planner can have an easy time
This rewriter makes sure that aggregations are on their own in RETURN/WITH clauses, so the planner can have an easy time
Example:
MATCH (n) RETURN { name: n.name, count: count(*) }, n.foo
This query has a RETURN clause where the single expression contains both the aggregate key and the aggregation expression. To make the job easier on the planner, this rewrite will change the query to:
MATCH (n) WITH n.name AS x1, count(*) AS x2, n.foo as X3 RETURN { name: x1, count: x2 }
Merges multiple IN predicates into one.
Merges multiple IN predicates into one.
Examples: MATCH (n) WHERE n.prop IN [1,2,3] AND [2,3,4] RETURN n.prop
MATCH (n) WHERE n.prop IN [1,2,3] OR [2,3,4] RETURN n.prop
MATCH (n) WHERE n.prop IN [1,2,3] AND [4,5,6] RETURN n.prop
NOTE: this rewriter must be applied before auto parameterization, since after that we are just dealing with opaque parameters.
This rewriter ensures that WITH clauses containing a ORDER BY or WHERE are split, such that the ORDER BY or WHERE does not refer to any newly introduced variable.
This rewriter ensures that WITH clauses containing a ORDER BY or WHERE are split, such that the ORDER BY or WHERE does not refer to any newly introduced variable.
This is required due to constraints in the planner. Note that this structure is invalid for semantic checking, which requires that ORDER BY and WHERE _only refer to variables introduced in the associated WITH_.
Additionally, it splits RETURN clauses containing ORDER BY. This would typically be done earlier during normalizeReturnClauses, however "RETURN * ORDER BY" is not handled at that stage, due to lacking variable information. If expandStar has already been run, then this will now work as expected.
This rewriter makes sure that all return items in a RETURN clauses are aliased, and moves any ORDER BY to a preceding WITH clause
Example:
MATCH (n) RETURN n.foo AS foo, n.bar ORDER BY foo
This rewrite will change the query to:
MATCH (n) WITH n.foo AS
FRESHIDxx, n.bar ASFRESHIDnnORDER BYFRESHIDxxRETURNFRESHIDxxAS foo,FRESHIDnnASn.bar