diff --git a/community/cypher/cypher/pom.xml b/community/cypher/cypher/pom.xml index 2aa81cd3361eb..d901d5e166553 100644 --- a/community/cypher/cypher/pom.xml +++ b/community/cypher/cypher/pom.xml @@ -185,7 +185,7 @@ org.neo4j neo4j-cypher-compiler-2.3 - 2.3.8 + 2.3.9 org.neo4j diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/ExceptionTranslatingQueryContextFor2_3.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/ExceptionTranslatingQueryContextFor2_3.scala index cc54713d0dcfb..75cd88ad5ecd5 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/ExceptionTranslatingQueryContextFor2_3.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/ExceptionTranslatingQueryContextFor2_3.scala @@ -21,14 +21,13 @@ package org.neo4j.cypher.internal.compatibility import java.net.URL -import org.neo4j.cypher.internal.compiler.v2_3.spi +import org.neo4j.cypher.internal.compiler.v2_3.{IndexDescriptor, spi} import org.neo4j.cypher.internal.compiler.v2_3.spi._ import org.neo4j.cypher.internal.frontend.v2_3.SemanticDirection import org.neo4j.cypher.{ConstraintValidationException, CypherExecutionException} -import org.neo4j.graphdb.{ConstraintViolationException => KernelConstraintViolationException, Node, PropertyContainer, Relationship} +import org.neo4j.graphdb.{Node, PropertyContainer, Relationship, ConstraintViolationException => KernelConstraintViolationException} import org.neo4j.kernel.api.TokenNameLookup import org.neo4j.kernel.api.exceptions.KernelException -import org.neo4j.kernel.api.index.IndexDescriptor class ExceptionTranslatingQueryContextFor2_3(inner: QueryContext) extends DelegatingQueryContext(inner) { override def setLabelsOnNode(node: Long, labelIds: Iterator[Int]): Int = diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/IndexDescriptorCompatibility.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/IndexDescriptorCompatibility.scala new file mode 100644 index 0000000000000..08ac6432e1908 --- /dev/null +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/IndexDescriptorCompatibility.scala @@ -0,0 +1,31 @@ +/* + * 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 . + */ +package org.neo4j.cypher.internal.spi.v2_3 + +import org.neo4j.cypher.internal.compiler.v2_3.{IndexDescriptor => CypherIndexDescriptor} +import org.neo4j.kernel.api.index.{IndexDescriptor => KernelIndexDescriptor} + +trait IndexDescriptorCompatibility { + implicit def cypherToKernel(index:CypherIndexDescriptor) = + new KernelIndexDescriptor( index.label, index.property ) + + implicit def kernelToCypher(index:KernelIndexDescriptor) = + CypherIndexDescriptor( index.getLabelId, index.getPropertyKeyId ) +} diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundPlanContext.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundPlanContext.scala index 3ea75be80e950..05f68876ad22b 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundPlanContext.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundPlanContext.scala @@ -20,25 +20,25 @@ package org.neo4j.cypher.internal.spi.v2_3 import org.neo4j.cypher.MissingIndexException +import org.neo4j.cypher.internal.compiler.v2_3.{IndexDescriptor => CypherIndexDescriptor} import org.neo4j.cypher.internal.compiler.v2_3.pipes.EntityProducer import org.neo4j.cypher.internal.compiler.v2_3.pipes.matching.ExpanderStep import org.neo4j.cypher.internal.compiler.v2_3.spi._ - import org.neo4j.cypher.internal.spi.TransactionalContextWrapper import org.neo4j.graphdb.Node import org.neo4j.kernel.api.constraints.UniquenessConstraint import org.neo4j.kernel.api.exceptions.KernelException import org.neo4j.kernel.api.exceptions.schema.SchemaKernelException -import org.neo4j.kernel.api.index.{IndexDescriptor, InternalIndexState} +import org.neo4j.kernel.api.index.{InternalIndexState, IndexDescriptor => KernelIndexDescriptor} import org.neo4j.kernel.impl.transaction.log.TransactionIdStore import scala.collection.JavaConverters._ class TransactionBoundPlanContext(tc: TransactionalContextWrapper) - extends TransactionBoundTokenContext(tc.statement) with PlanContext { + extends TransactionBoundTokenContext(tc.statement) with PlanContext with IndexDescriptorCompatibility { @Deprecated - def getIndexRule(labelName: String, propertyKey: String): Option[IndexDescriptor] = evalOrNone { + def getIndexRule(labelName: String, propertyKey: String): Option[CypherIndexDescriptor] = evalOrNone { val labelId = tc.statement.readOperations().labelGetForName(labelName) val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey) @@ -54,7 +54,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper) onlineIndexDescriptors.nonEmpty } - def getUniqueIndexRule(labelName: String, propertyKey: String): Option[IndexDescriptor] = evalOrNone { + def getUniqueIndexRule(labelName: String, propertyKey: String): Option[CypherIndexDescriptor] = evalOrNone { val labelId = tc.statement.readOperations().labelGetForName(labelName) val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey) @@ -65,7 +65,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper) private def evalOrNone[T](f: => Option[T]): Option[T] = try { f } catch { case _: SchemaKernelException => None } - private def getOnlineIndex(descriptor: IndexDescriptor): Option[IndexDescriptor] = + private def getOnlineIndex(descriptor: KernelIndexDescriptor): Option[CypherIndexDescriptor] = tc.statement.readOperations().indexGetState(descriptor) match { case InternalIndexState.ONLINE => Some(descriptor) case _ => None diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundQueryContext.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundQueryContext.scala index 9b4da5c6b1cdd..50d09a86baf34 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundQueryContext.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundQueryContext.scala @@ -26,7 +26,7 @@ import org.neo4j.collection.primitive.PrimitiveLongIterator import org.neo4j.collection.primitive.base.Empty.EMPTY_PRIMITIVE_LONG_COLLECTION import org.neo4j.cypher.InternalException import org.neo4j.cypher.internal.compiler.v2_3.MinMaxOrdering.{BY_NUMBER, BY_STRING, BY_VALUE} -import org.neo4j.cypher.internal.compiler.v2_3._ +import org.neo4j.cypher.internal.compiler.v2_3.{IndexDescriptor => CypherIndexDescriptor, _} import org.neo4j.cypher.internal.compiler.v2_3.ast.convert.commands.DirectionConverter.toGraphDb import org.neo4j.cypher.internal.compiler.v2_3.commands.expressions import org.neo4j.cypher.internal.compiler.v2_3.commands.expressions.{KernelPredicate, OnlyDirectionExpander, TypeAndDirectionExpander} @@ -46,7 +46,7 @@ import org.neo4j.graphdb.traversal.{Evaluators, TraversalDescription, Uniqueness import org.neo4j.kernel.GraphDatabaseQueryService import org.neo4j.kernel.api.constraints.{NodePropertyExistenceConstraint, RelationshipPropertyExistenceConstraint, UniquenessConstraint} import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException} -import org.neo4j.kernel.api.index.{IndexDescriptor, InternalIndexState} +import org.neo4j.kernel.api.index.{InternalIndexState, IndexDescriptor => KernelIndexDescriptor} import org.neo4j.kernel.api.{exceptions, _} import org.neo4j.kernel.impl.core.NodeManager @@ -54,7 +54,7 @@ import scala.collection.JavaConverters._ import scala.collection.{Iterator, mutable} final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) - extends TransactionBoundTokenContext(tc.statement) with QueryContext { + extends TransactionBoundTokenContext(tc.statement) with QueryContext with IndexDescriptorCompatibility { override val nodeOps = new NodeOperations override val relationshipOps = new RelationshipOperations @@ -125,10 +125,10 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) new BeansAPIRelationshipIterator(relationships, nodeManager) } - def indexSeek(index: IndexDescriptor, value: Any) = + def indexSeek(index: CypherIndexDescriptor, value: Any) = JavaConversionSupport.mapToScalaENFXSafe(tc.statement.readOperations().nodesGetFromIndexSeek(index, value))(nodeOps.getById) - def indexSeekByRange(index: IndexDescriptor, value: Any) = value match { + def indexSeekByRange(index: CypherIndexDescriptor, value: Any) = value match { case PrefixRange(prefix: String) => indexSeekByPrefixRange(index, prefix) @@ -140,7 +140,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) throw new InternalException(s"Unsupported index seek by range: $range") } - private def indexSeekByPrefixRange(index: IndexDescriptor, range: InequalitySeekRange[Any]): scala.Iterator[Node] = { + private def indexSeekByPrefixRange(index: CypherIndexDescriptor, range: InequalitySeekRange[Any]): scala.Iterator[Node] = { val groupedRanges = range.groupBy { (bound: Bound[Any]) => bound.endPoint match { case n: Number => classOf[Number] @@ -188,12 +188,12 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) } } - private def indexSeekByPrefixRange(index: IndexDescriptor, prefix: String): scala.Iterator[Node] = { + private def indexSeekByPrefixRange(index: CypherIndexDescriptor, prefix: String): scala.Iterator[Node] = { val indexedNodes = tc.statement.readOperations().nodesGetFromIndexRangeSeekByPrefix(index, prefix) JavaConversionSupport.mapToScalaENFXSafe(indexedNodes)(nodeOps.getById) } - private def indexSeekByNumericalRange(index: IndexDescriptor, range: InequalitySeekRange[Number]): scala.Iterator[Node] = { + private def indexSeekByNumericalRange(index: CypherIndexDescriptor, range: InequalitySeekRange[Number]): scala.Iterator[Node] = { val readOps = tc.statement.readOperations() val matchingNodes: PrimitiveLongIterator = (range match { @@ -220,9 +220,9 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) JavaConversionSupport.mapToScalaENFXSafe(matchingNodes)(nodeOps.getById) } - private def indexSeekByStringRange(index: IndexDescriptor, range: InequalitySeekRange[String]): scala.Iterator[Node] = { + private def indexSeekByStringRange(index: CypherIndexDescriptor, range: InequalitySeekRange[String]): scala.Iterator[Node] = { val readOps = tc.statement.readOperations() - val propertyKeyId = index.getPropertyKeyId + val propertyKeyId = index.property val matchingNodes: PrimitiveLongIterator = range match { case rangeLessThan: RangeLessThan[String] => @@ -249,10 +249,10 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) JavaConversionSupport.mapToScalaENFXSafe(matchingNodes)(nodeOps.getById) } - def indexScan(index: IndexDescriptor) = + def indexScan(index: CypherIndexDescriptor) = mapToScalaENFXSafe(tc.statement.readOperations().nodesGetFromIndexScan(index))(nodeOps.getById) - override def lockingExactUniqueIndexSearch(index: IndexDescriptor, value: Any): Option[Node] = { + override def lockingExactUniqueIndexSearch(index: CypherIndexDescriptor, value: Any): Option[Node] = { val nodeId: Long = tc.statement.readOperations().nodeGetFromUniqueIndexSeek(index, value) if (StatementConstants.NO_SUCH_NODE == nodeId) None else Some(nodeOps.getById(nodeId)) } @@ -454,7 +454,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) tc.statement.readOperations().schemaStateGetOrCreate(key, javaCreator) } - def addIndexRule(labelId: Int, propertyKeyId: Int): IdempotentResult[IndexDescriptor] = try { + def addIndexRule(labelId: Int, propertyKeyId: Int): IdempotentResult[CypherIndexDescriptor] = try { IdempotentResult(tc.statement.schemaWriteOperations().indexCreate(labelId, propertyKeyId)) } catch { case _: AlreadyIndexedException => @@ -465,7 +465,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper) } def dropIndexRule(labelId: Int, propertyKeyId: Int) = - tc.statement.schemaWriteOperations().indexDrop(new IndexDescriptor(labelId, propertyKeyId)) + tc.statement.schemaWriteOperations().indexDrop(new KernelIndexDescriptor(labelId, propertyKeyId)) def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = try { IdempotentResult(tc.statement.schemaWriteOperations().uniquePropertyConstraintCreate(labelId, propertyKeyId))