-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `DeleteWalker` has two stages: 1. Aggregate items for later deletion 2. Deduplicate and perform deletion in side effect - If RETURN depends on DELETE, 2 is executed as last action - In other cases, 2 is executed right after 1. These are separate actions because deduplication is important - Custom predicate for filtering Node types - For safety, delete for unknown types will fail without custom predicate, to avoid deletion of nodes with existing relationships - Deduplicate before deletion to avoid errors on some databases - TCK +1 Signed-off-by: Dwitry dwitry@users.noreply.github.com
- Loading branch information
Showing
21 changed files
with
476 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,6 @@ public interface GremlinPredicates<P> { | |
P endsWith(Object value); | ||
|
||
P contains(Object value); | ||
|
||
P isNode(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...slation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/SimplifyDelete.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2018 "Neo4j, Inc." [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.opencypher.gremlin.translation.ir.rewrite | ||
|
||
import org.opencypher.gremlin.translation.Tokens.{DELETE, DETACH_DELETE, NULL} | ||
import org.opencypher.gremlin.translation.ir.TraversalHelper._ | ||
import org.opencypher.gremlin.translation.ir.model._ | ||
|
||
/** | ||
* Removes surplus actions if `delete` or `detach delete` is not used in query | ||
*/ | ||
object SimplifyDelete extends GremlinRewriter { | ||
def apply(steps: Seq[GremlinStep]): Seq[GremlinStep] = { | ||
val withChoose = foldTraversals(false)((acc, localSteps) => { | ||
acc || extract({ | ||
case ChooseP(IsNode(), Aggregate(DELETE) :: Nil, Aggregate(DETACH_DELETE) :: Nil) :: _ => true | ||
})(localSteps).contains(true) | ||
})(steps) | ||
|
||
if (withChoose) { | ||
return steps | ||
} | ||
|
||
val aggregations = countInTraversals({ | ||
case Aggregate(sideEffectKey) :: _ => sideEffectKey | ||
})(steps) | ||
|
||
val delete = aggregations.getOrElse(DELETE, 0) > 1 | ||
val detachDelete = aggregations.getOrElse(DETACH_DELETE, 0) > 1 | ||
|
||
mapTraversals( | ||
replace({ | ||
case SideEffect(Limit(0) :: Aggregate(DELETE) :: Nil) :: SideEffect( | ||
Limit(0) :: Aggregate(DETACH_DELETE) :: Nil) :: rest => | ||
rest | ||
case Cap(DELETE) :: Unfold :: Dedup() :: Is(Neq(NULL)) :: SideEffect(_) :: Drop :: rest if !delete => | ||
rest | ||
case Cap(DETACH_DELETE) :: Unfold :: Dedup() :: Is(Neq(NULL)) :: Drop :: rest if !detachDelete => | ||
rest | ||
}))(steps) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.