Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change unwind to use a WhileLoop instruction with iterators
Introduce two loop data generators that produces iterators for collections of primitive vs. non-primitive types This fixes an acceptance tests that failed because we were relying on Iterable being the base type of the unwind collection expression when type information was not known at compile time. Move increment db hits from WhileLoop into the produceNext of the loop data generators that are actually hitting the database.
- Loading branch information
1 parent
103f2f9
commit 6802730
Showing
15 changed files
with
262 additions
and
67 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
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
45 changes: 45 additions & 0 deletions
45
.../src/main/scala/org/neo4j/cypher/internal/compiler/v3_2/codegen/ir/UnwindCollection.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
/* | |||
* Copyright (c) 2002-2017 "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.v3_2.codegen.ir | |||
|
|||
import org.neo4j.cypher.internal.compiler.v3_2.codegen.ir.expressions.{CodeGenExpression, CodeGenType} | |||
import org.neo4j.cypher.internal.compiler.v3_2.codegen.{CodeGenContext, Variable} | |||
import org.neo4j.cypher.internal.compiler.v3_2.codegen.spi.MethodStructure | |||
|
|||
case class UnwindCollection(opName: String, collection: CodeGenExpression) extends LoopDataGenerator { | |||
override def init[E](generator: MethodStructure[E])(implicit context: CodeGenContext): Unit = | |||
collection.init(generator) | |||
|
|||
override def produceIterator[E](iterVar: String, generator: MethodStructure[E]) | |||
(implicit context: CodeGenContext): Unit = { | |||
generator.declareIterator(iterVar) | |||
val iterator = generator.iteratorFrom(collection.generateExpression(generator)) | |||
generator.assign(iterVar, CodeGenType.Any, iterator) | |||
} | |||
|
|||
override def produceNext[E](nextVar: Variable, iterVar: String, generator: MethodStructure[E]) | |||
(implicit context: CodeGenContext): Unit = { | |||
val next = generator.iteratorNext(generator.loadVariable(iterVar)) | |||
generator.assign(nextVar.name, CodeGenType.Any, next) | |||
} | |||
|
|||
override def hasNext[E](generator: MethodStructure[E], iterVar: String): E = | |||
generator.iteratorHasNext(generator.loadVariable(iterVar)) | |||
} |
50 changes: 50 additions & 0 deletions
50
.../scala/org/neo4j/cypher/internal/compiler/v3_2/codegen/ir/UnwindPrimitiveCollection.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
/* | |||
* Copyright (c) 2002-2017 "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.v3_2.codegen.ir | |||
|
|||
import org.neo4j.cypher.internal.compiler.v3_2.codegen.ir.expressions._ | |||
import org.neo4j.cypher.internal.compiler.v3_2.codegen.spi.MethodStructure | |||
import org.neo4j.cypher.internal.compiler.v3_2.codegen.{CodeGenContext, Variable} | |||
import org.neo4j.cypher.internal.frontend.v3_2.symbols | |||
|
|||
case class UnwindPrimitiveCollection(opName: String, collection: CodeGenExpression) extends LoopDataGenerator { | |||
override def init[E](generator: MethodStructure[E])(implicit context: CodeGenContext): Unit = | |||
collection.init(generator) | |||
|
|||
override def produceIterator[E](iterVar: String, generator: MethodStructure[E]) | |||
(implicit context: CodeGenContext): Unit = { | |||
generator.declarePrimitiveIterator(iterVar, collection.codeGenType) | |||
val iterator = generator.primitiveIteratorFrom(collection.generateExpression(generator), collection.codeGenType) | |||
generator.assign(iterVar, CodeGenType.Any, iterator) | |||
} | |||
|
|||
override def produceNext[E](nextVar: Variable, iterVar: String, generator: MethodStructure[E]) | |||
(implicit context: CodeGenContext): Unit = { | |||
val elementType = collection.codeGenType match { | |||
case CodeGenType(symbols.ListType(innerCt), ListReferenceType(innerRepr)) => CodeGenType(innerCt, innerRepr) | |||
case _ => throw new IllegalArgumentException(s"CodeGenType $collection.codeGenType not supported as primitive iterator") | |||
} | |||
val next = generator.primitiveIteratorNext(generator.loadVariable(iterVar), collection.codeGenType) | |||
generator.assign(nextVar.name, elementType, next) | |||
} | |||
|
|||
override def hasNext[E](generator: MethodStructure[E], iterVar: String): E = | |||
generator.iteratorHasNext(generator.loadVariable(iterVar)) | |||
} |
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
Oops, something went wrong.