Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Neo4jsource
Commits
a583ab6e
Commit
a583ab6e
authored
11 years ago
by
Davide Grohmann
Browse files
Options
Download
Email Patches
Plain Diff
Add rewriter to transform equals for id(a), a.prop to in collection predicates
parent
7303642b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
community/cypher/cypher-compiler-2.1/src/main/scala/org/neo4j/cypher/internal/compiler/v2_1/ast/rewriters/rewriteEqualityToInCollection.scala
+39
-0
...er/v2_1/ast/rewriters/rewriteEqualityToInCollection.scala
community/cypher/cypher-compiler-2.1/src/test/scala/org/neo4j/cypher/internal/compiler/v2_1/ast/rewriters/RewriteEqualityToInCollectionTest.scala
+61
-0
...2_1/ast/rewriters/RewriteEqualityToInCollectionTest.scala
with
100 additions
and
0 deletions
+100
-0
community/cypher/cypher-compiler-2.1/src/main/scala/org/neo4j/cypher/internal/compiler/v2_1/ast/rewriters/rewriteEqualityToInCollection.scala
0 → 100644
+
39
-
0
View file @
a583ab6e
/**
* Copyright (c) 2002-2014 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
org.neo4j.cypher.internal.compiler.v2_1.ast.rewriters
import
org.neo4j.cypher.internal.compiler.v2_1._
import
org.neo4j.cypher.internal.compiler.v2_1.ast._
object
rewriteEqualityToInCollection
extends
Rewriter
{
override
def
apply
(
that
:
AnyRef
)
=
bottomUp
(
instance
).
apply
(
that
)
private
val
instance
:
Rewriter
=
Rewriter
.
lift
{
// id(a) = value
case
predicate
@Equals
(
func
@FunctionInvocation
(
_
,
_
,
IndexedSeq
(
idExpr
)),
p
@ConstantExpression
(
idValueExpr
))
if
func
.
function
==
Some
(
functions
.
Id
)
=>
In
(
func
,
Collection
(
Seq
(
idValueExpr
))(
p
.
position
))(
predicate
.
position
)
// a.prop = value
case
predicate
@Equals
(
prop
@Property
(
id
:
Identifier
,
propKeyName
),
p
@ConstantExpression
(
idValueExpr
))
=>
In
(
prop
,
Collection
(
Seq
(
idValueExpr
))(
p
.
position
))(
predicate
.
position
)
}
}
This diff is collapsed.
Click to expand it.
community/cypher/cypher-compiler-2.1/src/test/scala/org/neo4j/cypher/internal/compiler/v2_1/ast/rewriters/RewriteEqualityToInCollectionTest.scala
0 → 100644
+
61
-
0
View file @
a583ab6e
/**
* Copyright (c) 2002-2014 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
org.neo4j.cypher.internal.compiler.v2_1.ast.rewriters
import
org.neo4j.cypher.internal.commons.CypherFunSuite
import
org.neo4j.cypher.internal.compiler.v2_1.planner.AstRewritingTestSupport
import
org.neo4j.cypher.internal.compiler.v2_1.bottomUp
class
RewriteEqualityToInCollectionTest
extends
CypherFunSuite
with
AstRewritingTestSupport
{
test
(
"should transform id(a) = ConstValue to id(a) IN [ConstValue]"
)
{
val
original
=
parser
.
parse
(
"MATCH (a) WHERE id(a) = 42"
)
val
expected
=
parser
.
parse
(
"MATCH (a) WHERE id(a) IN [42]"
)
val
result
=
original
.
rewrite
(
rewriteEqualityToInCollection
)
result
should
equal
(
expected
)
}
test
(
"should not transform id(a) = NonConstValue"
)
{
val
original
=
parser
.
parse
(
"MATCH (a) WHERE id(a) = rand()"
)
val
result
=
original
.
rewrite
(
rewriteEqualityToInCollection
)
result
should
equal
(
original
)
}
test
(
"should transform a.prop = ConstValue to a.prop IN [ConstValue]"
)
{
val
original
=
parser
.
parse
(
"MATCH (a) WHERE a.prop = 42"
)
val
expected
=
parser
.
parse
(
"MATCH (a) WHERE a.prop IN [42]"
)
val
result
=
original
.
rewrite
(
rewriteEqualityToInCollection
)
result
should
equal
(
expected
)
}
test
(
"should not transform a.prop = NonConstValue"
)
{
val
original
=
parser
.
parse
(
"MATCH (a) WHERE a.prop = rand()"
)
val
result
=
original
.
rewrite
(
rewriteEqualityToInCollection
)
result
should
equal
(
original
)
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment