Skip to content

Commit

Permalink
Pushed IndexDescriptor boundary further in ReadOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and chrisvest committed Feb 14, 2017
1 parent 3af48ca commit 76925fb
Show file tree
Hide file tree
Showing 32 changed files with 225 additions and 237 deletions.
Expand Up @@ -20,12 +20,13 @@
package org.neo4j.cypher.internal.spi.v2_3

import org.neo4j.cypher.internal.compiler.v2_3.{IndexDescriptor => CypherIndexDescriptor}
import org.neo4j.kernel.api.schema.{IndexDescriptor => KernelIndexDescriptor, IndexDescriptorFactory}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}

trait IndexDescriptorCompatibility {
implicit def cypherToKernel(index: CypherIndexDescriptor) =
IndexDescriptorFactory.of(index.label, index.property)
NewIndexDescriptorFactory.forLabel(index.label, index.property)

implicit def kernelToCypher(index: KernelIndexDescriptor) =
CypherIndexDescriptor(index.getLabelId, index.getPropertyKeyId)
CypherIndexDescriptor(index.schema().getLabelId, index.schema().getPropertyIds()(0))
}
Expand Up @@ -30,7 +30,8 @@ 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.{NodePropertyDescriptor, IndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.api.schema.{NodePropertyDescriptor}
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore

import scala.collection.JavaConverters._
Expand Down
Expand Up @@ -48,7 +48,8 @@ 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.InternalIndexState
import org.neo4j.kernel.api.schema.{IndexDescriptorFactory, NodePropertyDescriptor, RelationshipPropertyDescriptor}
import org.neo4j.kernel.api.schema.{NodePropertyDescriptor, RelationshipPropertyDescriptor}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
import org.neo4j.kernel.api.{exceptions, _}
import org.neo4j.kernel.impl.core.NodeManager

Expand Down Expand Up @@ -212,10 +213,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
case RangeBetween(rangeGreaterThan, rangeLessThan) =>
rangeGreaterThan.limit(BY_NUMBER).flatMap { greaterThanLimit =>
rangeLessThan.limit(BY_NUMBER).map { lessThanLimit =>
readOps.nodesGetFromIndexRangeSeekByNumber(
index,
greaterThanLimit.endPoint, greaterThanLimit.isInclusive,
lessThanLimit.endPoint, lessThanLimit.isInclusive)
readOps.nodesGetFromIndexRangeSeekByNumber(index, greaterThanLimit.endPoint, greaterThanLimit.isInclusive, lessThanLimit.endPoint, lessThanLimit.isInclusive)
}
}
}).getOrElse(EMPTY_PRIMITIVE_LONG_COLLECTION.iterator)
Expand All @@ -239,10 +237,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
case RangeBetween(rangeGreaterThan, rangeLessThan) =>
rangeGreaterThan.limit(BY_STRING).flatMap { greaterThanLimit =>
rangeLessThan.limit(BY_STRING).map { lessThanLimit =>
readOps.nodesGetFromIndexRangeSeekByString(
index,
greaterThanLimit.endPoint.asInstanceOf[String], greaterThanLimit.isInclusive,
lessThanLimit.endPoint.asInstanceOf[String], lessThanLimit.isInclusive)
readOps.nodesGetFromIndexRangeSeekByString(index, greaterThanLimit.endPoint.asInstanceOf[String], greaterThanLimit.isInclusive, lessThanLimit.endPoint.asInstanceOf[String], lessThanLimit.isInclusive)
}
}.getOrElse(EMPTY_PRIMITIVE_LONG_COLLECTION.iterator)
}
Expand Down Expand Up @@ -468,7 +463,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
}

def dropIndexRule(labelId: Int, propertyKeyId: Int) =
tc.statement.schemaWriteOperations().indexDrop(IndexDescriptorFactory.of( labelId, propertyKeyId ))
tc.statement.schemaWriteOperations().indexDrop(NewIndexDescriptorFactory.forLabel( labelId, propertyKeyId ))

def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = try {
IdempotentResult(tc.statement.schemaWriteOperations().uniquePropertyConstraintCreate(new NodePropertyDescriptor(labelId,
Expand Down
Expand Up @@ -20,12 +20,13 @@
package org.neo4j.cypher.internal.spi.v3_1

import org.neo4j.cypher.internal.compiler.v3_1.{IndexDescriptor => CypherIndexDescriptor}
import org.neo4j.kernel.api.schema.{IndexDescriptor => KernelIndexDescriptor, IndexDescriptorFactory}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}

trait IndexDescriptorCompatibility {
implicit def cypherToKernel(index: CypherIndexDescriptor) =
IndexDescriptorFactory.of(index.label, index.property)
NewIndexDescriptorFactory.forLabel(index.label, index.property)

implicit def kernelToCypher(index: KernelIndexDescriptor) =
CypherIndexDescriptor(index.getLabelId, index.getPropertyKeyId)
CypherIndexDescriptor(index.schema().getLabelId, index.schema().getPropertyIds()(0))
}
Expand Up @@ -24,7 +24,7 @@ import org.neo4j.cypher.internal.compiler.v3_1.spi.{GraphStatistics, StatisticsC
import org.neo4j.cypher.internal.frontend.v3_1.{LabelId, NameId, PropertyKeyId, RelTypeId}
import org.neo4j.kernel.api.ReadOperations
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException
import org.neo4j.kernel.api.schema.IndexDescriptorFactory
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory

object TransactionBoundGraphStatistics {
def apply(ops: ReadOperations) = new StatisticsCompletingGraphStatistics(new BaseTransactionBoundGraphStatistics(ops))
Expand All @@ -35,7 +35,7 @@ object TransactionBoundGraphStatistics {

def indexSelectivity(label: LabelId, property: PropertyKeyId): Option[Selectivity] =
try {
val indexDescriptor = IndexDescriptorFactory.of( label, property )
val indexDescriptor = NewIndexDescriptorFactory.forLabel( label, property )
val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble

// Probability of any node with the given label, to have a property with a given value
Expand All @@ -51,7 +51,7 @@ object TransactionBoundGraphStatistics {

def indexPropertyExistsSelectivity(label: LabelId, property: PropertyKeyId): Option[Selectivity] =
try {
val indexDescriptor = IndexDescriptorFactory.of( label, property )
val indexDescriptor = NewIndexDescriptorFactory.forLabel( label, property )
val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble

// Probability of any node with the given label, to have a given property
Expand Down
Expand Up @@ -26,7 +26,7 @@ import org.neo4j.cypher.internal.LastCommittedTxIdProvider
import org.neo4j.cypher.internal.compiler.v3_1.pipes.EntityProducer
import org.neo4j.cypher.internal.compiler.v3_1.pipes.matching.ExpanderStep
import org.neo4j.cypher.internal.compiler.v3_1.spi._
import org.neo4j.cypher.internal.compiler.v3_1.{InternalNotificationLogger, IndexDescriptor}
import org.neo4j.cypher.internal.compiler.v3_1.{IndexDescriptor, InternalNotificationLogger}
import org.neo4j.cypher.internal.frontend.v3_1.symbols.CypherType
import org.neo4j.cypher.internal.frontend.v3_1.{CypherExecutionException, symbols}
import org.neo4j.graphdb.Node
Expand All @@ -36,7 +36,8 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaKernelException
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.Neo4jTypes.AnyType
import org.neo4j.kernel.api.proc.{Neo4jTypes, QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.{NodePropertyDescriptor, IndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.api.schema.NodePropertyDescriptor
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.impl.proc.Neo4jValue
import org.neo4j.procedure.Mode

Expand Down
Expand Up @@ -35,8 +35,8 @@ import org.neo4j.cypher.internal.compiler.v3_1.helpers.JavaConversionSupport._
import org.neo4j.cypher.internal.compiler.v3_1.pipes.matching.PatternNode
import org.neo4j.cypher.internal.compiler.v3_1.spi._
import org.neo4j.cypher.internal.frontend.v3_1.{Bound, EntityNotFoundException, FailedIndexException, SemanticDirection}
import org.neo4j.cypher.internal.spi.v3_1.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.internal.spi.BeansAPIRelationshipIterator
import org.neo4j.cypher.internal.spi.v3_1.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.cypher.{InternalException, internal}
import org.neo4j.graphalgo.impl.path.ShortestPath
Expand All @@ -53,7 +53,8 @@ import org.neo4j.kernel.api.exceptions.ProcedureException
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.{QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.{IndexDescriptorFactory, NodePropertyDescriptor, RelationshipPropertyDescriptor}
import org.neo4j.kernel.api.schema.{NodePropertyDescriptor, RelationshipPropertyDescriptor}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.kernel.impl.locking.ResourceTypes

Expand Down Expand Up @@ -211,21 +212,18 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)

case rangeLessThan: RangeLessThan[Number] =>
rangeLessThan.limit(BY_NUMBER).map { limit =>
readOps.nodesGetFromIndexRangeSeekByNumber( index, null, false, limit.endPoint, limit.isInclusive )
readOps.nodesGetFromIndexRangeSeekByNumber(index, null, false, limit.endPoint, limit.isInclusive)
}

case rangeGreaterThan: RangeGreaterThan[Number] =>
rangeGreaterThan.limit(BY_NUMBER).map { limit =>
readOps.nodesGetFromIndexRangeSeekByNumber( index, limit.endPoint, limit.isInclusive, null, false )
readOps.nodesGetFromIndexRangeSeekByNumber(index, limit.endPoint, limit.isInclusive, null, false)
}

case RangeBetween(rangeGreaterThan, rangeLessThan) =>
rangeGreaterThan.limit(BY_NUMBER).flatMap { greaterThanLimit =>
rangeLessThan.limit(BY_NUMBER).map { lessThanLimit =>
readOps.nodesGetFromIndexRangeSeekByNumber(
index,
greaterThanLimit.endPoint, greaterThanLimit.isInclusive,
lessThanLimit.endPoint, lessThanLimit.isInclusive )
readOps.nodesGetFromIndexRangeSeekByNumber(index, greaterThanLimit.endPoint, greaterThanLimit.isInclusive, lessThanLimit.endPoint, lessThanLimit.isInclusive)
}
}
}).getOrElse(EMPTY_PRIMITIVE_LONG_COLLECTION.iterator)
Expand All @@ -238,21 +236,18 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)

case rangeLessThan: RangeLessThan[String] =>
rangeLessThan.limit(BY_STRING).map { limit =>
readOps.nodesGetFromIndexRangeSeekByString( index, null, false, limit.endPoint.asInstanceOf[String], limit.isInclusive )
readOps.nodesGetFromIndexRangeSeekByString(index, null, false, limit.endPoint.asInstanceOf[String], limit.isInclusive)
}.getOrElse(EMPTY_PRIMITIVE_LONG_COLLECTION.iterator)

case rangeGreaterThan: RangeGreaterThan[String] =>
rangeGreaterThan.limit(BY_STRING).map { limit =>
readOps.nodesGetFromIndexRangeSeekByString( index, limit.endPoint.asInstanceOf[String], limit.isInclusive, null, false )
readOps.nodesGetFromIndexRangeSeekByString(index, limit.endPoint.asInstanceOf[String], limit.isInclusive, null, false)
}.getOrElse(EMPTY_PRIMITIVE_LONG_COLLECTION.iterator)

case RangeBetween(rangeGreaterThan, rangeLessThan) =>
rangeGreaterThan.limit(BY_STRING).flatMap { greaterThanLimit =>
rangeLessThan.limit(BY_STRING).map { lessThanLimit =>
readOps.nodesGetFromIndexRangeSeekByString(
index,
greaterThanLimit.endPoint.asInstanceOf[String], greaterThanLimit.isInclusive,
lessThanLimit.endPoint.asInstanceOf[String], lessThanLimit.isInclusive )
readOps.nodesGetFromIndexRangeSeekByString(index, greaterThanLimit.endPoint.asInstanceOf[String], greaterThanLimit.isInclusive, lessThanLimit.endPoint.asInstanceOf[String], lessThanLimit.isInclusive)
}
}.getOrElse(EMPTY_PRIMITIVE_LONG_COLLECTION.iterator)
}
Expand Down Expand Up @@ -472,7 +467,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
}

override def dropIndexRule(labelId: Int, propertyKeyId: Int) =
txContext.statement.schemaWriteOperations().indexDrop(IndexDescriptorFactory.of( labelId, propertyKeyId ))
txContext.statement.schemaWriteOperations().indexDrop(NewIndexDescriptorFactory.forLabel( labelId, propertyKeyId ))

override def createUniqueConstraint(labelId: Int, propertyKeyId: Int): IdempotentResult[UniquenessConstraint] = try {
IdempotentResult(txContext.statement.schemaWriteOperations().uniquePropertyConstraintCreate(new NodePropertyDescriptor(labelId, propertyKeyId)))
Expand Down
Expand Up @@ -20,12 +20,13 @@
package org.neo4j.cypher.internal.spi.v3_2

import org.neo4j.cypher.internal.compiler.v3_2.{IndexDescriptor => CypherIndexDescriptor}
import org.neo4j.kernel.api.schema.{IndexDescriptor => KernelIndexDescriptor, NodeMultiPropertyDescriptor, NodePropertyDescriptor, IndexDescriptorFactory}
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}

trait IndexDescriptorCompatibility {
implicit def cypherToKernel(index: CypherIndexDescriptor) =
IndexDescriptorFactory.of(index.label, index.property)
NewIndexDescriptorFactory.forLabel(index.label, index.property)

implicit def kernelToCypher(index: KernelIndexDescriptor) =
CypherIndexDescriptor(index.getLabelId, index.getPropertyKeyId)
CypherIndexDescriptor(index.schema().getLabelId, index.schema().getPropertyIds()(0))
}
Expand Up @@ -24,7 +24,7 @@ import org.neo4j.cypher.internal.frontend.v3_2.{LabelId, NameId, PropertyKeyId,
import org.neo4j.cypher.internal.ir.v3_2.{Cardinality, Selectivity}
import org.neo4j.kernel.api.ReadOperations
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException
import org.neo4j.kernel.api.schema.IndexDescriptorFactory
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory

object TransactionBoundGraphStatistics {
def apply(ops: ReadOperations) = new StatisticsCompletingGraphStatistics(new BaseTransactionBoundGraphStatistics(ops))
Expand All @@ -35,7 +35,7 @@ object TransactionBoundGraphStatistics {

def indexSelectivity(label: LabelId, property: PropertyKeyId): Option[Selectivity] =
try {
val indexDescriptor = IndexDescriptorFactory.of( label, property )
val indexDescriptor = NewIndexDescriptorFactory.forLabel( label, property )
val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble

// Probability of any node with the given label, to have a property with a given value
Expand All @@ -51,7 +51,7 @@ object TransactionBoundGraphStatistics {

def indexPropertyExistsSelectivity(label: LabelId, property: PropertyKeyId): Option[Selectivity] =
try {
val indexDescriptor = IndexDescriptorFactory.of( label, property )
val indexDescriptor = NewIndexDescriptorFactory.forLabel( label, property )
val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble

// Probability of any node with the given label, to have a given property
Expand Down
Expand Up @@ -35,7 +35,7 @@ import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.Neo4jTypes.AnyType
import org.neo4j.kernel.api.proc.{Neo4jTypes, QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.NodePropertyDescriptor
import org.neo4j.kernel.api.schema.{IndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.api.schema_new.index.{NewIndexDescriptor => KernelIndexDescriptor}
import org.neo4j.kernel.impl.proc.Neo4jValue
import org.neo4j.procedure.Mode

Expand Down Expand Up @@ -67,7 +67,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper, logger: Inter

// here we do not need to use getOnlineIndex method because uniqueness constraint creation is synchronous
val index = tc.statement.readOperations().uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(labelId, propertyKeyId))
Some(IndexDescriptor(index.getLabelId, index.getPropertyKeyId))
Some(IndexDescriptor(index.schema().getLabelId, index.schema().getPropertyIds()(0)))
}

private def evalOrNone[T](f: => Option[T]): Option[T] =
Expand All @@ -79,7 +79,7 @@ class TransactionBoundPlanContext(tc: TransactionalContextWrapper, logger: Inter

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

Expand Down

0 comments on commit 76925fb

Please sign in to comment.