Skip to content

Commit

Permalink
Update cypher compatibility compiler to 2.3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Apr 4, 2017
1 parent d2ec7d6 commit 0cf9d0d
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 89 deletions.
2 changes: 1 addition & 1 deletion community/cypher/cypher/pom.xml
Expand Up @@ -185,7 +185,7 @@
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher-compiler-2.3</artifactId>
<version>2.3.9</version>
<version>2.3.10</version>
<exclusions>
<exclusion>
<groupId>org.neo4j</groupId>
Expand Down
Expand Up @@ -21,7 +21,6 @@ package org.neo4j.cypher.internal.compatibility.v2_3

import java.net.URL

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}
Expand Down Expand Up @@ -90,7 +89,7 @@ class ExceptionTranslatingQueryContext(inner: QueryContext) extends DelegatingQu
override def dropIndexRule(labelId: Int, propertyKeyId: Int) =
translateException(super.dropIndexRule(labelId, propertyKeyId))

override def indexSeek(index: IndexDescriptor, value: Any): Iterator[Node] =
override def indexSeek(index: SchemaTypes.IndexDescriptor, value: Any): Iterator[Node] =
translateException(super.indexSeek(index, value))

override def getNodesByLabel(id: Int): Iterator[Node] =
Expand All @@ -105,7 +104,7 @@ class ExceptionTranslatingQueryContext(inner: QueryContext) extends DelegatingQu
override def getOrCreateFromSchemaState[K, V](key: K, creator: => V): V =
translateException(super.getOrCreateFromSchemaState(key, creator))

override def upgrade(context: spi.QueryContext): LockingQueryContext =
override def upgrade(context: QueryContext): LockingQueryContext =
translateException(super.upgrade(context))

override def createUniqueConstraint(labelId: Int, propertyKeyId: Int) =
Expand Down Expand Up @@ -141,7 +140,7 @@ class ExceptionTranslatingQueryContext(inner: QueryContext) extends DelegatingQu
override def getRelTypeName(id: Int) =
translateException(super.getRelTypeName(id))

override def lockingExactUniqueIndexSearch(index: IndexDescriptor, value: Any) =
override def lockingExactUniqueIndexSearch(index: SchemaTypes.IndexDescriptor, value: Any) =
translateException(super.lockingExactUniqueIndexSearch(index, value))

override def commitAndRestartTx() =
Expand Down
Expand Up @@ -33,7 +33,7 @@ object exceptionHandler extends MapToPublicExceptions[CypherException] {
throw new ProfilerStatisticsNotReadyException(cause)
}

def incomparableValuesException(lhs: String, rhs: String, cause: Throwable) = new IncomparableValuesException(lhs, rhs, cause)
def incomparableValuesException(details:Option[String], lhs: String, rhs: String, cause: Throwable) = new IncomparableValuesException(details, lhs, rhs, cause)

def unknownLabelException(s: String, cause: Throwable) = new UnknownLabelException(s, cause)

Expand Down

This file was deleted.

@@ -0,0 +1,54 @@
/*
* 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.spi.v2_3

import org.neo4j.cypher.internal.compiler.v2_3.spi.SchemaTypes
import org.neo4j.kernel.api.schema_new.constaints.{NodeExistenceConstraintDescriptor, RelExistenceConstraintDescriptor, UniquenessConstraintDescriptor}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}

trait SchemaDescriptorTranslation {
implicit def cypherToKernel(index: SchemaTypes.IndexDescriptor): KernelIndexDescriptor =
NewIndexDescriptorFactory.forLabel(index.labelId, index.propertyId)

implicit def kernelToCypher(index: KernelIndexDescriptor): SchemaTypes.IndexDescriptor =
if (index.schema().getPropertyIds.length == 1)
SchemaTypes.IndexDescriptor(index.schema().getLabelId, index.schema().getPropertyIds()(0))
else
throw new UnsupportedOperationException("Cypher 2.3 does not support composite indexes")

implicit def kernelToCypher(index: UniquenessConstraintDescriptor): SchemaTypes.UniquenessConstraint =
if (index.schema().getPropertyIds.length == 1)
SchemaTypes.UniquenessConstraint(index.schema().getLabelId, index.schema().getPropertyIds()(0))
else
throw new UnsupportedOperationException("Cypher 2.3 does not support composite constraints")

implicit def kernelToCypher(index: NodeExistenceConstraintDescriptor): SchemaTypes.NodePropertyExistenceConstraint =
if (index.schema().getPropertyIds.length == 1)
SchemaTypes.NodePropertyExistenceConstraint(index.schema().getLabelId, index.schema().getPropertyIds()(0))
else
throw new UnsupportedOperationException("Cypher 2.3 does not support composite constraints")

implicit def kernelToCypher(index: RelExistenceConstraintDescriptor): SchemaTypes.RelationshipPropertyExistenceConstraint =
if (index.schema().getPropertyIds.length == 1)
SchemaTypes.RelationshipPropertyExistenceConstraint(index.schema().getRelTypeId, index.schema().getPropertyIds()(0))
else
throw new UnsupportedOperationException("Cypher 2.3 does not support composite constraints")
}
Expand Up @@ -20,28 +20,26 @@
package org.neo4j.cypher.internal.spi.v2_3

import org.neo4j.cypher.MissingIndexException
import org.neo4j.cypher.internal.compiler.v2_3.IndexDescriptor
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.v3_2.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.InternalIndexState
import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema_new.constaints.{ConstraintBoundary, ConstraintDescriptor}
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore

import scala.collection.JavaConverters._

class TransactionBoundPlanContext(tc: TransactionalContextWrapper)
extends TransactionBoundTokenContext(tc.statement) with PlanContext with IndexDescriptorCompatibility {
extends TransactionBoundTokenContext(tc.statement) with PlanContext with SchemaDescriptorTranslation {

@Deprecated
def getIndexRule(labelName: String, propertyKey: String): Option[IndexDescriptor] = evalOrNone {
def getIndexRule(labelName: String, propertyKey: String): Option[SchemaTypes.IndexDescriptor] = evalOrNone {
val labelId = tc.statement.readOperations().labelGetForName(labelName)
val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey)

Expand All @@ -57,7 +55,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper)
onlineIndexDescriptors.nonEmpty
}

def getUniqueIndexRule(labelName: String, propertyKey: String): Option[IndexDescriptor] = evalOrNone {
def getUniqueIndexRule(labelName: String, propertyKey: String): Option[SchemaTypes.IndexDescriptor] = evalOrNone {
val labelId = tc.statement.readOperations().labelGetForName(labelName)
val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey)

Expand All @@ -68,13 +66,13 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper)
private def evalOrNone[T](f: => Option[T]): Option[T] =
try { f } catch { case _: SchemaKernelException => None }

private def getOnlineIndex(descriptor: KernelIndexDescriptor): Option[IndexDescriptor] =
private def getOnlineIndex(descriptor: KernelIndexDescriptor): Option[SchemaTypes.IndexDescriptor] =
tc.statement.readOperations().indexGetState(descriptor) match {
case InternalIndexState.ONLINE => Some(descriptor)
case _ => None
}

def getUniquenessConstraint(labelName: String, propertyKey: String): Option[UniquenessConstraint] = try {
def getUniquenessConstraint(labelName: String, propertyKey: String): Option[SchemaTypes.UniquenessConstraint] = try {
val labelId = tc.statement.readOperations().labelGetForName(labelName)
val propertyKeyId = tc.statement.readOperations().propertyKeyGetForName(propertyKey)

Expand All @@ -83,7 +81,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper)
SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)
).asScala.collectFirst {
case constraint: ConstraintDescriptor if constraint.`type`() == ConstraintDescriptor.Type.UNIQUE =>
ConstraintBoundary.map( constraint ).asInstanceOf[UniquenessConstraint]
SchemaTypes.UniquenessConstraint(labelId, propertyKeyId)
}
} catch {
case _: KernelException => None
Expand Down

0 comments on commit 0cf9d0d

Please sign in to comment.