private IndexQuery[] seek( SchemaDescriptor schema, Value[] propertyValues ) { int[] propertyIds = schema.getPropertyIds(); assert propertyIds.length == propertyValues.length; IndexQuery[] query = new IndexQuery[propertyValues.length]; for ( int i = 0; i < query.length; i++ ) { query[i] = IndexQuery.exact( propertyIds[i], propertyValues[i] ); } return query; }
@Override NodeValueIndexCursor queryExact( KernelTransaction ktx ) throws KernelException { return indexQuery( ktx, indexDescriptor, IndexQuery.exact( numberPropId1, numberProp1Values[0] ) ); }
@Override NodeValueIndexCursor queryExact( KernelTransaction ktx ) throws KernelException { return indexQuery( ktx, indexDescriptor, IndexQuery.exact( stringPropId1, stringProp1Values[0] ) ); }
@Override public ResourceIterator<Node> findNodes( Label label, String key1, Object value1, String key2, Object value2, String key3, Object value3 ) { KernelTransaction transaction = statementContext.getKernelTransactionBoundToThisThread( true ); TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); return nodesByLabelAndProperties( transaction, labelId, IndexQuery.exact( tokenRead.propertyKey( key1 ), Values.of( value1 ) ), IndexQuery.exact( tokenRead.propertyKey( key2 ), Values.of( value2 ) ), IndexQuery.exact( tokenRead.propertyKey( key3 ), Values.of( value3 ) ) ); }
private IndexQuery[] queryOf( ValueTuple tuple ) { IndexQuery[] predicates = new IndexQuery[tuple.size()]; int[] propertyIds = indexDescriptor.schema().getPropertyIds(); for ( int i = 0; i < predicates.length; i++ ) { predicates[i] = exact( propertyIds[i], tuple.valueAt( i ) ); } return predicates; } }
@Test void seekQueryReachSearcher() throws Exception { IndexReader simpleIndexReader = getUniqueSimpleReader(); simpleIndexReader.query( IndexQuery.exact( 1, "test" ) ); verify( indexSearcher ).search( any( BooleanQuery.class ), any( DocValuesCollector.class ) ); }
@Test public void mustSelectLuceneForExactPredicateWithOtherValue() throws Exception { // given for ( Object value : FusionIndexTestHelp.valuesNotSupportedBySpecificIndex() ) { IndexQuery indexQuery = IndexQuery.exact( PROP_KEY, value ); // then verifyQueryWithCorrectReader( readers.get( LUCENE ), indexQuery ); } }
private void assertExactPredicate( Object value ) { ExactPredicate p = IndexQuery.exact( propId, value ); assertTrue( test( p, value ) ); assertFalseForOtherThings( p ); }
@Test public void testExact_ComparingBigDoublesAndLongs() { ExactPredicate p = IndexQuery.exact( propId, 9007199254740993L ); assertFalse( test( p, 9007199254740992D ) ); }
private IndexQuery[] exactQuery() { int[] propertyIds = index.schema().getPropertyIds(); IndexQuery[] query = new IndexQuery[propertyIds.length]; for ( int i = 0; i < query.length; i++ ) { int propID = propertyIds[i]; query[i] = IndexQuery.exact( propID, Values.of( propID ) ); } return query; }
@Override public ResourceIterator<Node> findNodes( final Label myLabel, final String key, final Object value ) { KernelTransaction transaction = statementContext.getKernelTransactionBoundToThisThread( true ); TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( myLabel.name() ); int propertyId = tokenRead.propertyKey( key ); return nodesByLabelAndProperty( transaction, labelId, IndexQuery.exact( propertyId, Values.of( value ) ) ); }
@Test public void seekOverAllPartitions() throws Exception { PartitionedIndexReader indexReader = createPartitionedReaderFromReaders(); IndexQuery.ExactPredicate query = IndexQuery.exact( 1, "Test" ); when( indexReader1.query( query ) ).thenReturn( PrimitiveLongResourceCollections.iterator( null, 1 ) ); when( indexReader2.query( query ) ).thenReturn( PrimitiveLongResourceCollections.iterator( null, 2 ) ); when( indexReader3.query( query ) ).thenReturn( PrimitiveLongResourceCollections.iterator( null, 3 ) ); LongSet results = PrimitiveLongCollections.asSet( indexReader.query( query ) ); verifyResult( results ); }
@Test public void mustSelectStringForExactPredicateWithNumberValue() throws Exception { // given for ( Object value : FusionIndexTestHelp.valuesSupportedByString() ) { IndexQuery indexQuery = IndexQuery.exact( PROP_KEY, value ); // then verifyQueryWithCorrectReader( expectedForStrings(), indexQuery ); } }
@Test public void canAddNewData() throws Exception { // WHEN updateAndCommit( asList( add( nodeId, values ), add( nodeId2, values2 ) ) ); IndexReader reader = accessor.newReader(); // THEN assertEquals( asSet( nodeId ), PrimitiveLongCollections.toSet( reader .query( exact( PROP_ID1, values[0] ), exact( PROP_ID2, values[1] ) ) ) ); reader.close(); }
@Test public void testIndexSeekAndScan() throws Exception { updateAndCommit( asList( add( 1L, descriptor.schema(), "a" ), add( 2L, descriptor.schema(), "b" ), add( 3L, descriptor.schema(), "c" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( singletonList( 1L ) ) ); assertThat( query( IndexQuery.exists( 1 ) ), equalTo( asList( 1L, 2L, 3L ) ) ); } }
@Test public void testIndexSeekAndScan() throws Exception { updateAndCommit( asList( add( 1L, descriptor.schema(), "a" ), add( 2L, descriptor.schema(), "a" ), add( 3L, descriptor.schema(), "b" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); assertThat( query( exists( 1 ) ), equalTo( asList( 1L, 2L, 3L ) ) ); }
@Test public void indexReaderShouldHonorRepeatableReads() throws Exception { // GIVEN updateAndCommit( asList( add( nodeId, value ) ) ); IndexReader reader = accessor.newReader(); // WHEN updateAndCommit( asList( remove( nodeId, value ) ) ); // THEN assertEquals( asSet( nodeId ), PrimitiveLongCollections.toSet( reader.query( exact( PROP_ID, value ) ) ) ); reader.close(); }
@Test public void shouldReturnNoEntriesForMismatchingExactPredicate() throws Exception { // given IndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType(); processAll( updates ); // when IndexReader reader = accessor.newReader(); Object value = generateUniqueValue( updates ); LongIterator result = query( reader, IndexQuery.exact( 0, value ) ); assertEntityIdHits( EMPTY_LONG_ARRAY, result ); }
@Test public void canAddNewData() throws Exception { // WHEN updateAndCommit( asList( add( nodeId, value ), add( nodeId2, value2 ) ) ); IndexReader reader = accessor.newReader(); // THEN assertEquals( asSet( nodeId ), PrimitiveLongCollections.toSet( reader.query( exact( PROP_ID, value ) ) ) ); reader.close(); }