Skip to content

Commit

Permalink
WIP use ValueCategory in IndexCapability
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen authored and tinwelint committed Mar 26, 2018
1 parent 5868fbe commit cac705a
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 107 deletions.
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.internal.kernel.api;

import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.ValueCategory;

/**
* Reference to a specific index together with it's capabilities. This reference is valid until the schema of the database changes
Expand All @@ -34,15 +34,15 @@ public interface CapableIndexReference extends IndexReference, IndexCapability
CapableIndexReference NO_INDEX = new CapableIndexReference()
{
@Override
public IndexOrder[] orderCapability( ValueGroup... valueGroups )
public IndexOrder[] orderCapability( ValueCategory... valueCategories )
{
return NO_CAPABILITY.orderCapability( valueGroups );
return NO_CAPABILITY.orderCapability( valueCategories );
}

@Override
public IndexValueCapability valueCapability( ValueGroup... valueGroups )
public IndexValueCapability valueCapability( ValueCategory... valueCategories )
{
return NO_CAPABILITY.valueCapability( valueGroups );
return NO_CAPABILITY.valueCapability( valueCategories );
}

@Override
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.internal.kernel.api;

import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.ValueCategory;

/**
* Capabilities of an index.
Expand All @@ -34,46 +34,46 @@ public interface IndexCapability
IndexOrder[] ORDER_NONE = new IndexOrder[0];

/**
* What possible orderings is this index capable to provide for a query on given combination of {@link ValueGroup}.
* Ordering of ValueGroup correspond to ordering of related {@link IndexReference#properties()}.
* What possible orderings is this index capable to provide for a query on given combination of {@link ValueCategory}.
* Ordering of ValueCategory correspond to ordering of related {@link IndexReference#properties()}.
*
* @param valueGroups Ordered array of {@link ValueGroup ValueGroups} for which index should be queried. Note that valueGroup
* @param valueCategories Ordered array of {@link ValueCategory ValueCategories} for which index should be queried. Note that valueCategory
* must correspond to related {@link IndexReference#properties()}. A {@code null} value in the array
* ({@code new ValueGroup[]{null}}) is interpreted as a wildcard for any {@link ValueGroup}. Note that this is not the same as
* ({@code new ValueCategory[]{null}}) is interpreted as a wildcard for any {@link ValueCategory}. Note that this is not the same as
* {@code order(null)} which is undefined.
* @return {@link IndexOrder} array containing all possible orderings for provided value groups or empty array if no explicit
* ordering is possible or if length of {@code valueGroups} and {@link IndexReference#properties()} differ.
* @return {@link IndexOrder} array containing all possible orderings for provided value categories or empty array if no explicit
* ordering is possible or if length of {@code valueCategories} and {@link IndexReference#properties()} differ.
*/
IndexOrder[] orderCapability( ValueGroup... valueGroups );
IndexOrder[] orderCapability( ValueCategory... valueCategories );

/**
* Is the index capable of providing values for a query on given combination of {@link ValueGroup}.
* Ordering of ValueGroup correspond to ordering of {@code properties} in related {@link IndexReference}.
* Is the index capable of providing values for a query on given combination of {@link ValueCategory}.
* Ordering of ValueCategory correspond to ordering of {@code properties} in related {@link IndexReference}.
*
* @param valueGroups Ordered array of {@link ValueGroup ValueGroups} for which index should be queried. Note that valueGroup
* must correspond to related {@link IndexReference#properties()}. {@link ValueGroup#UNKNOWN} can be used as a wildcard for
* any {@link ValueGroup}. Behaviour is undefined for empty {@code null} array and {@code null} values in array.
* @return {@link IndexValueCapability#YES} if index is capable of providing values for query on provided array of value groups,
* @param valueCategories Ordered array of {@link ValueCategory ValueCategories} for which index should be queried. Note that valueCategory
* must correspond to related {@link IndexReference#properties()}. {@link ValueCategory#UNKNOWN} can be used as a wildcard for
* any {@link ValueCategory}. Behaviour is undefined for empty {@code null} array and {@code null} values in array.
* @return {@link IndexValueCapability#YES} if index is capable of providing values for query on provided array of value categories,
* {@link IndexValueCapability#NO} if not or {@link IndexValueCapability#PARTIAL} for some results. If length of
* {@code valueGroups} and {@link IndexReference#properties()} differ {@link IndexValueCapability#NO} is returned.
* {@code valueCategories} and {@link IndexReference#properties()} differ {@link IndexValueCapability#NO} is returned.
*/
IndexValueCapability valueCapability( ValueGroup... valueGroups );
IndexValueCapability valueCapability( ValueCategory... valueCategories );

default boolean singleWildcard( ValueGroup[] valueGroups )
default boolean singleWildcard( ValueCategory[] valueCategories )
{
return valueGroups.length == 1 && valueGroups[0] == ValueGroup.UNKNOWN;
return valueCategories.length == 1 && valueCategories[0] == ValueCategory.UNKNOWN;
}

IndexCapability NO_CAPABILITY = new IndexCapability()
{
@Override
public IndexOrder[] orderCapability( ValueGroup... valueGroups )
public IndexOrder[] orderCapability( ValueCategory... valueCategories )
{
return ORDER_NONE;
}

@Override
public IndexValueCapability valueCapability( ValueGroup... valueGroups )
public IndexValueCapability valueCapability( ValueCategory... valueCategories )
{
return IndexValueCapability.NO;
}
Expand Down
Expand Up @@ -19,11 +19,9 @@
*/
package org.neo4j.internal.kernel.api;

import org.neo4j.values.storable.ValueGroup;

/**
* Enum used for two purposes:
* 1. As return value for {@link IndexCapability#orderCapability(ValueGroup...)}.
* 1. As return value for {@link IndexCapability#orderCapability(org.neo4j.values.storable.ValueCategory...)}.
* Only {@link #ASCENDING} and {@link #DESCENDING} is valid for this.
* 2. As parameter for {@link Read#nodeIndexScan(IndexReference, NodeValueIndexCursor, IndexOrder)} and
* {@link Read#nodeIndexSeek(IndexReference, NodeValueIndexCursor, IndexOrder, IndexQuery...)}. Where {@link #NONE} is used when
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.neo4j.values.storable.CoordinateReferenceSystem;
import org.neo4j.values.storable.DateValue;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.ValueCategory;
import org.neo4j.values.storable.Values;

import static java.util.concurrent.TimeUnit.MINUTES;
Expand Down Expand Up @@ -140,7 +140,7 @@ public void shouldPerformExactLookup() throws Exception
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
// when
IndexValueCapability valueCapability = index.valueCapability( ValueGroup.TEXT );
IndexValueCapability valueCapability = index.valueCapability( ValueCategory.TEXT );
read.nodeIndexSeek( index, node, IndexOrder.NONE, IndexQuery.exact( prop, "zero" ) );

// then
Expand All @@ -165,7 +165,7 @@ public void shouldPerformExactLookup() throws Exception
assertFoundNodesAndNoValue( node, uniqueIds, strThree1, strThree2, strThree3 );

// when
valueCapability = index.valueCapability( ValueGroup.NUMBER );
valueCapability = index.valueCapability( ValueCategory.NUMBER );
read.nodeIndexSeek( index, node, IndexOrder.NONE, IndexQuery.exact( prop, 1 ) );

// then
Expand Down Expand Up @@ -196,14 +196,14 @@ public void shouldPerformExactLookup() throws Exception
assertFoundNodesAndNoValue( node, uniqueIds, num12a, num12b );

// when
valueCapability = index.valueCapability( ValueGroup.BOOLEAN );
valueCapability = index.valueCapability( ValueCategory.REST );
read.nodeIndexSeek( index, node, IndexOrder.NONE, IndexQuery.exact( prop, true ) );

// then
assertFoundNodesAndNoValue( node, uniqueIds, boolTrue );

// when
valueCapability = index.valueCapability( ValueGroup.GEOMETRY );
valueCapability = index.valueCapability( ValueCategory.GEOMETRY );
read.nodeIndexSeek( index, node, IndexOrder.NONE, IndexQuery.exact( prop, Values.pointValue( Cartesian, 0, 0 ) ) );

// then
Expand All @@ -228,7 +228,7 @@ public void shouldPerformExactLookup() throws Exception
assertFoundNodesAndNoValue( node, 1, uniqueIds );

// when
valueCapability = index.valueCapability( ValueGroup.DATE );
valueCapability = index.valueCapability( ValueCategory.TEMPORAL );
read.nodeIndexSeek( index, node, IndexOrder.NONE, IndexQuery.exact( prop, DateValue.date( 1989, 3, 24 ) ) );

// then
Expand All @@ -254,7 +254,7 @@ public void shouldPerformExactLookupInCompositeIndex() throws Exception
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
// when
IndexValueCapability valueCapability = index.valueCapability( ValueGroup.TEXT, ValueGroup.TEXT );
IndexValueCapability valueCapability = index.valueCapability( ValueCategory.TEXT, ValueCategory.TEXT );
read.nodeIndexSeek( index, node, IndexOrder.NONE, IndexQuery.exact( firstName, "Joe" ),
IndexQuery.exact( surname, "Dalton" ) );

Expand All @@ -271,7 +271,7 @@ public void shouldPerformStringPrefixSearch() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability stringCapability = index.valueCapability( ValueGroup.TEXT );
IndexValueCapability stringCapability = index.valueCapability( ValueCategory.TEXT );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand All @@ -292,7 +292,7 @@ public void shouldPerformStringSuffixSearch() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability stringCapability = index.valueCapability( ValueGroup.TEXT );
IndexValueCapability stringCapability = index.valueCapability( ValueCategory.TEXT );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand All @@ -312,7 +312,7 @@ public void shouldPerformStringContainmentSearch() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability stringCapability = index.valueCapability( ValueGroup.TEXT );
IndexValueCapability stringCapability = index.valueCapability( ValueCategory.TEXT );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand All @@ -332,7 +332,7 @@ public void shouldPerformStringRangeSearch() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability stringCapability = index.valueCapability( ValueGroup.TEXT );
IndexValueCapability stringCapability = index.valueCapability( ValueCategory.TEXT );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand Down Expand Up @@ -377,7 +377,7 @@ public void shouldPerformNumericRangeSearch() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability numberCapability = index.valueCapability( ValueGroup.NUMBER );
IndexValueCapability numberCapability = index.valueCapability( ValueCategory.NUMBER );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand Down Expand Up @@ -414,7 +414,7 @@ public void shouldPerformTemporalRangeSearch() throws KernelException
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability temporalCapability = index.valueCapability( ValueGroup.DATE );
IndexValueCapability temporalCapability = index.valueCapability( ValueCategory.TEMPORAL );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand Down Expand Up @@ -455,7 +455,7 @@ public void shouldPerformSpatialRangeSearch() throws KernelException
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability spatialCapability = index.valueCapability( ValueGroup.GEOMETRY );
IndexValueCapability spatialCapability = index.valueCapability( ValueCategory.GEOMETRY );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand Down Expand Up @@ -492,7 +492,7 @@ public void shouldPerformIndexScan() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability wildcardCapability = index.valueCapability( ValueGroup.UNKNOWN );
IndexValueCapability wildcardCapability = index.valueCapability( ValueCategory.UNKNOWN );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
Expand All @@ -512,7 +512,7 @@ public void shouldRespectOrderCapabilitiesForNumbers() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexOrder[] orderCapabilities = index.orderCapability( ValueGroup.NUMBER );
IndexOrder[] orderCapabilities = index.orderCapability( ValueCategory.NUMBER );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
{
for ( IndexOrder orderCapability : orderCapabilities )
Expand All @@ -533,7 +533,7 @@ public void shouldRespectOrderCapabilitiesForStrings() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexOrder[] orderCapabilities = index.orderCapability( ValueGroup.TEXT );
IndexOrder[] orderCapabilities = index.orderCapability( ValueCategory.TEXT );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
{
for ( IndexOrder orderCapability : orderCapabilities )
Expand All @@ -554,7 +554,7 @@ public void shouldRespectOrderCapabilitiesForTemporal() throws KernelException
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexOrder[] orderCapabilities = index.orderCapability( ValueGroup.DATE );
IndexOrder[] orderCapabilities = index.orderCapability( ValueCategory.TEMPORAL );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
{
for ( IndexOrder orderCapability : orderCapabilities )
Expand All @@ -576,7 +576,7 @@ public void shouldRespectOrderCapabilitiesForSpatial() throws KernelException
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexOrder[] orderCapabilities = index.orderCapability( ValueGroup.GEOMETRY );
IndexOrder[] orderCapabilities = index.orderCapability( ValueCategory.GEOMETRY );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
{
for ( IndexOrder orderCapability : orderCapabilities )
Expand All @@ -597,7 +597,7 @@ public void shouldRespectOrderCapabilitiesForWildcard() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexOrder[] orderCapabilities = index.orderCapability( ValueGroup.UNKNOWN );
IndexOrder[] orderCapabilities = index.orderCapability( ValueCategory.UNKNOWN );
try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() )
{
for ( IndexOrder orderCapability : orderCapabilities )
Expand Down Expand Up @@ -746,7 +746,7 @@ public void shouldGetNoIndexForUnknownTokens()
}

@Test
public void shouldGetVersionAndKeyFromIndexReference() throws Exception
public void shouldGetVersionAndKeyFromIndexReference()
{
// Given
int label = token.nodeLabel( "Node" );
Expand All @@ -764,7 +764,7 @@ public void shouldNotFindDeletedNodeInIndexScan() throws Exception
int label = token.nodeLabel( "Node" );
int prop = token.propertyKey( "prop" );
CapableIndexReference index = schemaRead.index( label, prop );
IndexValueCapability wildcardCapability = index.valueCapability( ValueGroup.UNKNOWN );
IndexValueCapability wildcardCapability = index.valueCapability( ValueCategory.UNKNOWN );
try ( org.neo4j.internal.kernel.api.Transaction tx = session.beginTransaction();
NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor();
PrimitiveLongSet uniqueIds = Primitive.longSet() )
Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;
import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.ValueCategory;

public class DefaultCapableIndexReference implements CapableIndexReference
{
Expand Down Expand Up @@ -80,15 +80,15 @@ public String providerVersion()
}

@Override
public IndexOrder[] orderCapability( ValueGroup... valueGroups )
public IndexOrder[] orderCapability( ValueCategory... valueCategories )
{
return capability.orderCapability( valueGroups );
return capability.orderCapability( valueCategories );
}

@Override
public IndexValueCapability valueCapability( ValueGroup... valueGroups )
public IndexValueCapability valueCapability( ValueCategory... valueCategories )
{
return capability.valueCapability( valueGroups );
return capability.valueCapability( valueCategories );
}

@Override
Expand Down

0 comments on commit cac705a

Please sign in to comment.