Skip to content

Commit

Permalink
Merge CapableIndexReference with IndexReference
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed May 21, 2018
1 parent 9d2e9b3 commit d1f21e4
Show file tree
Hide file tree
Showing 36 changed files with 219 additions and 262 deletions.
Expand Up @@ -19,10 +19,10 @@
*/ */
package org.neo4j.cypher.internal.codegen; package org.neo4j.cypher.internal.codegen;


import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.CursorFactory; import org.neo4j.internal.kernel.api.CursorFactory;
import org.neo4j.internal.kernel.api.IndexOrder; import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.internal.kernel.api.IndexQuery; import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.internal.kernel.api.IndexReference;
import org.neo4j.internal.kernel.api.NodeValueIndexCursor; import org.neo4j.internal.kernel.api.NodeValueIndexCursor;
import org.neo4j.internal.kernel.api.Read; import org.neo4j.internal.kernel.api.Read;
import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.KernelException;
Expand Down Expand Up @@ -53,7 +53,7 @@ private CompiledIndexUtils()
* @param value The value to seek for * @param value The value to seek for
* @return A cursor positioned at the data found in index. * @return A cursor positioned at the data found in index.
*/ */
public static NodeValueIndexCursor indexSeek( Read read, CursorFactory cursors, CapableIndexReference index, Object value ) public static NodeValueIndexCursor indexSeek( Read read, CursorFactory cursors, IndexReference index, Object value )
throws KernelException throws KernelException
{ {
assert index.properties().length == 1; assert index.properties().length == 1;
Expand Down
Expand Up @@ -24,7 +24,6 @@ import org.neo4j.cypher.internal.compiler.v2_3.spi.{GraphStatistics, StatisticsC
import org.neo4j.cypher.internal.frontend.v2_3.{LabelId, NameId, PropertyKeyId, RelTypeId} import org.neo4j.cypher.internal.frontend.v2_3.{LabelId, NameId, PropertyKeyId, RelTypeId}
import org.neo4j.internal.kernel.api.{Read, SchemaRead} import org.neo4j.internal.kernel.api.{Read, SchemaRead}
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException
import org.neo4j.kernel.impl.api.store.DefaultIndexReference
import org.neo4j.kernel.impl.query.TransactionalContext import org.neo4j.kernel.impl.query.TransactionalContext


object TransactionBoundGraphStatistics { object TransactionBoundGraphStatistics {
Expand Down
Expand Up @@ -21,13 +21,11 @@


import org.junit.Test; import org.junit.Test;


import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.CursorFactory; import org.neo4j.internal.kernel.api.CursorFactory;
import org.neo4j.internal.kernel.api.IndexReference;
import org.neo4j.internal.kernel.api.NodeValueIndexCursor; import org.neo4j.internal.kernel.api.NodeValueIndexCursor;
import org.neo4j.internal.kernel.api.Read; import org.neo4j.internal.kernel.api.Read;
import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;


import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
Expand All @@ -46,7 +44,7 @@ public void shouldCallIndexSeek() throws KernelException


// GIVEN // GIVEN
Read read = mock( Read.class ); Read read = mock( Read.class );
CapableIndexReference index = mock( CapableIndexReference.class ); IndexReference index = mock( IndexReference.class );
when( index.properties() ).thenReturn( new int[]{42} ); when( index.properties() ).thenReturn( new int[]{42} );


// WHEN // WHEN
Expand All @@ -61,7 +59,7 @@ public void shouldHandleNullInIndexSeek() throws KernelException
{ {
// GIVEN // GIVEN
Read read = mock( Read.class ); Read read = mock( Read.class );
CapableIndexReference index = mock( CapableIndexReference.class ); IndexReference index = mock( IndexReference.class );
when( index.properties() ).thenReturn( new int[]{42} ); when( index.properties() ).thenReturn( new int[]{42} );


// WHEN // WHEN
Expand Down
Expand Up @@ -25,7 +25,7 @@ import org.neo4j.cypher.internal.runtime.interpreted.commands.expressions.Expres
import org.opencypher.v9_0.util.CypherTypeException import org.opencypher.v9_0.util.CypherTypeException
import org.opencypher.v9_0.util.attribution.Id import org.opencypher.v9_0.util.attribution.Id
import org.opencypher.v9_0.expressions.{LabelToken, PropertyKeyToken} import org.opencypher.v9_0.expressions.{LabelToken, PropertyKeyToken}
import org.neo4j.internal.kernel.api.{CapableIndexReference, IndexReference} import org.neo4j.internal.kernel.api.IndexReference
import org.neo4j.values.storable.{TextValue, Values} import org.neo4j.values.storable.{TextValue, Values}
import org.neo4j.values.virtual.NodeValue import org.neo4j.values.virtual.NodeValue


Expand All @@ -35,10 +35,10 @@ abstract class AbstractNodeIndexStringScanPipe(ident: String,
valueExpr: Expression) extends Pipe { valueExpr: Expression) extends Pipe {




private var reference: IndexReference = CapableIndexReference.NO_INDEX private var reference: IndexReference = IndexReference.NO_INDEX


private def reference(context: QueryContext): IndexReference = { private def reference(context: QueryContext): IndexReference = {
if (reference == CapableIndexReference.NO_INDEX) { if (reference == IndexReference.NO_INDEX) {
reference = context.indexReference(label.nameId.id, propertyKey.nameId.id) reference = context.indexReference(label.nameId.id, propertyKey.nameId.id)
} }
reference reference
Expand Down
Expand Up @@ -23,17 +23,17 @@ import org.neo4j.cypher.internal.runtime.QueryContext
import org.neo4j.cypher.internal.runtime.interpreted.ExecutionContext import org.neo4j.cypher.internal.runtime.interpreted.ExecutionContext
import org.opencypher.v9_0.util.attribution.Id import org.opencypher.v9_0.util.attribution.Id
import org.opencypher.v9_0.expressions.{LabelToken, PropertyKeyToken} import org.opencypher.v9_0.expressions.{LabelToken, PropertyKeyToken}
import org.neo4j.internal.kernel.api.{CapableIndexReference, IndexReference} import org.neo4j.internal.kernel.api.IndexReference


case class NodeIndexScanPipe(ident: String, case class NodeIndexScanPipe(ident: String,
label: LabelToken, label: LabelToken,
propertyKey: PropertyKeyToken) propertyKey: PropertyKeyToken)
(val id: Id = Id.INVALID_ID) extends Pipe { (val id: Id = Id.INVALID_ID) extends Pipe {


private var reference: IndexReference = CapableIndexReference.NO_INDEX private var reference: IndexReference = IndexReference.NO_INDEX


private def reference(context: QueryContext): IndexReference = { private def reference(context: QueryContext): IndexReference = {
if (reference == CapableIndexReference.NO_INDEX) { if (reference == IndexReference.NO_INDEX) {
reference = context.indexReference(label.nameId.id, propertyKey.nameId.id) reference = context.indexReference(label.nameId.id, propertyKey.nameId.id)
} }
reference reference
Expand Down
Expand Up @@ -25,7 +25,7 @@ import org.neo4j.cypher.internal.runtime.interpreted.commands.expressions.Expres
import org.opencypher.v9_0.util.attribution.Id import org.opencypher.v9_0.util.attribution.Id
import org.opencypher.v9_0.expressions.{LabelToken, PropertyKeyToken} import org.opencypher.v9_0.expressions.{LabelToken, PropertyKeyToken}
import org.neo4j.cypher.internal.v3_5.logical.plans._ import org.neo4j.cypher.internal.v3_5.logical.plans._
import org.neo4j.internal.kernel.api.{CapableIndexReference, IndexReference} import org.neo4j.internal.kernel.api.IndexReference


case class NodeIndexSeekPipe(ident: String, case class NodeIndexSeekPipe(ident: String,
label: LabelToken, label: LabelToken,
Expand All @@ -36,10 +36,10 @@ case class NodeIndexSeekPipe(ident: String,


override val propertyIds: Array[Int] = propertyKeys.map(_.nameId.id).toArray override val propertyIds: Array[Int] = propertyKeys.map(_.nameId.id).toArray


private var reference: IndexReference = CapableIndexReference.NO_INDEX private var reference: IndexReference = IndexReference.NO_INDEX


private def reference(context: QueryContext): IndexReference = { private def reference(context: QueryContext): IndexReference = {
if (reference == CapableIndexReference.NO_INDEX) { if (reference == IndexReference.NO_INDEX) {
reference = context.indexReference(label.nameId.id, propertyIds:_*) reference = context.indexReference(label.nameId.id, propertyIds:_*)
} }
reference reference
Expand Down

This file was deleted.

Expand Up @@ -24,34 +24,60 @@


import org.neo4j.helpers.collection.Iterators; import org.neo4j.helpers.collection.Iterators;
import org.neo4j.internal.kernel.api.schema.SchemaUtil; import org.neo4j.internal.kernel.api.schema.SchemaUtil;
import org.neo4j.values.storable.ValueCategory;


import static java.lang.String.format; import static java.lang.String.format;


/** /**
* Reference to a specific index. This reference is valid until the schema of the database changes (that is a * Reference to a specific index together with it's capabilities. This reference is valid until the schema of the database changes
* create/drop of an index or constraint occurs). * (that is a create/drop of an index or constraint occurs).
*/ */
public interface IndexReference public interface IndexReference extends IndexCapability
{ {
boolean isUnique(); IndexReference NO_INDEX = new IndexReference()
{
@Override
public IndexOrder[] orderCapability( ValueCategory... valueCategories )
{
return NO_CAPABILITY.orderCapability( valueCategories );
}


int label(); @Override
public IndexValueCapability valueCapability( ValueCategory... valueCategories )
{
return NO_CAPABILITY.valueCapability( valueCategories );
}


int[] properties(); @Override
public boolean isUnique()
{
return false;
}


String providerKey(); @Override
public int label()
{
return Token.NO_TOKEN;
}


String providerVersion(); @Override
public int[] properties()
{
return new int[0];
}


/** @Override
* @param tokenNameLookup used for looking up names for token ids. public String providerKey()
* @return a user friendly description of what this index indexes. {
*/ return null;
default String userDescription( TokenNameLookup tokenNameLookup ) }
{
String type = isUnique() ? "UNIQUE" : "GENERAL"; @Override
return format( "Index( %s, %s )", type, SchemaUtil.niceProperties( tokenNameLookup, properties() ) ); public String providerVersion()
} {
return null;
}
};


/** /**
* Sorts indexes by type, returning first GENERAL indexes, followed by UNIQUE. Implementation is not suitable in * Sorts indexes by type, returning first GENERAL indexes, followed by UNIQUE. Implementation is not suitable in
Expand All @@ -68,4 +94,24 @@ static Iterator<IndexReference> sortByType( Iterator<IndexReference> indexes )
Iterators.filter( IndexReference::isUnique, materialized.iterator() ) ); Iterators.filter( IndexReference::isUnique, materialized.iterator() ) );


} }

boolean isUnique();

int label();

int[] properties();

String providerKey();

String providerVersion();

/**
* @param tokenNameLookup used for looking up names for token ids.
* @return a user friendly description of what this index indexes.
*/
default String userDescription( TokenNameLookup tokenNameLookup )
{
String type = isUnique() ? "UNIQUE" : "GENERAL";
return format( "Index( %s, %s )", type, SchemaUtil.niceProperties( tokenNameLookup, properties() ) );
}
} }
Expand Up @@ -41,9 +41,9 @@ public interface SchemaRead
* *
* @param label the index label * @param label the index label
* @param properties the index properties * @param properties the index properties
* @return the IndexReference, or {@link CapableIndexReference#NO_INDEX} if such an index does not exist. * @return the IndexReference, or {@link IndexReference#NO_INDEX} if such an index does not exist.
*/ */
CapableIndexReference index( int label, int... properties ); IndexReference index( int label, int... properties );


/** /**
* Acquire an index reference of the given {@code label} and {@code properties}. This method does not assert * Acquire an index reference of the given {@code label} and {@code properties}. This method does not assert
Expand All @@ -53,7 +53,7 @@ public interface SchemaRead
* @param properties the index properties * @param properties the index properties
* @return a IndexReference for the given label and properties * @return a IndexReference for the given label and properties
*/ */
CapableIndexReference indexReferenceUnchecked( int label, int... properties ); IndexReference indexReferenceUnchecked( int label, int... properties );


/** /**
* Returns all indexes associated with the given label * Returns all indexes associated with the given label
Expand Down
Expand Up @@ -61,7 +61,7 @@ public void shouldPerformStringSuffixSearch() throws Exception
int prop = tx.tokenRead().propertyKey( "prop" ); int prop = tx.tokenRead().propertyKey( "prop" );
expected.add( nodeWithProp( tx, "2suff" ) ); expected.add( nodeWithProp( tx, "2suff" ) );
nodeWithProp( tx, "skruff" ); nodeWithProp( tx, "skruff" );
CapableIndexReference index = tx.schemaRead().index( label, prop ); IndexReference index = tx.schemaRead().index( label, prop );
try ( NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor() ) try ( NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor() )
{ {
tx.dataRead().nodeIndexSeek( index, nodes, IndexOrder.NONE, IndexQuery.stringSuffix( prop, "suff" ) ); tx.dataRead().nodeIndexSeek( index, nodes, IndexOrder.NONE, IndexQuery.stringSuffix( prop, "suff" ) );
Expand Down Expand Up @@ -97,7 +97,7 @@ public void shouldPerformStringContainsSearch() throws Exception
int prop = tx.tokenRead().propertyKey( "prop" ); int prop = tx.tokenRead().propertyKey( "prop" );
expected.add( nodeWithProp( tx, "homeopatic" ) ); expected.add( nodeWithProp( tx, "homeopatic" ) );
nodeWithProp( tx, "telephonecompany" ); nodeWithProp( tx, "telephonecompany" );
CapableIndexReference index = tx.schemaRead().index( label, prop ); IndexReference index = tx.schemaRead().index( label, prop );
try ( NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor() ) try ( NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor() )
{ {
tx.dataRead().nodeIndexSeek( index, nodes, IndexOrder.NONE, IndexQuery.stringContains( prop, "me" ) ); tx.dataRead().nodeIndexSeek( index, nodes, IndexOrder.NONE, IndexQuery.stringContains( prop, "me" ) );
Expand Down

0 comments on commit d1f21e4

Please sign in to comment.