@Override public Value asValue() { return DateValue.epochDate( epochDay ); }
private static DateValue readDate( ByteBuffer chunk, int offset ) { return epochDate( chunk.getLong( offset ) ); }
@Override public Value decodeForTemporal( long[] valueBlocks, int offset ) { long epochDay = valueIsInlined( valueBlocks[offset] ) ? valueBlocks[offset] >>> 33 : valueBlocks[1 + offset]; return DateValue.epochDate( epochDay ); }
private DateValue unpackDate() throws IOException { long epochDay = unpackLong(); return epochDate( epochDay ); }
@Test public void shouldNotBotherSerializingToRealBytesIfFarFromThreshold() { // given Layout<GenericKey,NativeIndexValue> layout = mock( Layout.class ); doThrow( RuntimeException.class ).when( layout ).newKey(); GenericIndexKeyValidator validator = new GenericIndexKeyValidator( 120, layout ); // when validator.validate( new Value[]{intValue( 10 ), epochDate( 100 ), stringValue( "abc" )} ); // then no exception should have been thrown }
@Test public void shouldInvolveSerializingToRealBytesIfMayCrossThreshold() { // given Layout<GenericKey,NativeIndexValue> layout = mock( Layout.class ); when( layout.newKey() ).thenReturn( new CompositeGenericKey( 3, spatialSettings() ) ); GenericIndexKeyValidator validator = new GenericIndexKeyValidator( 48, layout ); // when try { validator.validate( new Value[]{intValue( 10 ), epochDate( 100 ), stringValue( "abcdefghijklmnopqrstuvw" )} ); fail( "Should have failed" ); } catch ( IllegalArgumentException e ) { // then good assertThat( e.getMessage(), containsString( "abcdefghijklmnopqrstuvw" ) ); verify( layout, times( 1 ) ).newKey(); } }
@Test public void testDateTypeLargeEpochDay() { LocalDate date = DateValue.epochDate( 2147483648L ).asObjectCopy(); String key = "dt"; node1.setProperty( key, date ); newTransaction(); Object property = node1.getProperty( key ); assertEquals( date, property ); }
private void testIndexSeekRangeWithExists( Value obj1, Value obj2, Value obj3, Value obj4, Value obj5 ) throws Exception { Assume.assumeTrue( "Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries() ); updateAndCommit( asList( add( 1L, descriptor.schema(), obj1, Values.of( 100 ) ), add( 2L, descriptor.schema(), obj2, Values.of( "someString" ) ), add( 3L, descriptor.schema(), obj3, Values.of( epochDate( 300 ) ) ), add( 4L, descriptor.schema(), obj4, Values.of( true ) ), add( 5L, descriptor.schema(), obj5, Values.of( 42 ) ) ) ); assertThat( query( range( 0, obj2, true, obj4, false ), exists( 1 ) ), equalTo( asList( 2L, 3L ) ) ); assertThat( query( range( 0, obj4, true, null, false ), exists( 1 ) ), equalTo( asList( 4L, 5L ) ) ); assertThat( query( range( 0, obj4, false, null, true ), exists( 1 ) ), equalTo( singletonList( 5L ) ) ); assertThat( query( range( 0, obj5, false, obj2, true ), exists( 1 ) ), equalTo( EMPTY_LIST ) ); assertThat( query( range( 0, null, false, obj3, false ), exists( 1 ) ), equalTo( asList( 1L, 2L ) ) ); assertThat( query( range( 0, null, true, obj3, true ), exists( 1 ) ), equalTo( asList( 1L, 2L, 3L ) ) ); ValueGroup valueGroup = obj1.valueGroup(); if ( valueGroup != GEOMETRY && valueGroup != GEOMETRY_ARRAY ) { // This cannot be done for spatial values because each bound in a spatial query needs a coordinate reference system, // and those are provided by Value instances, e.g. PointValue assertThat( query( range( 0, obj1.valueGroup() ), exists( 1 ) ), equalTo( asList( 1L, 2L, 3L, 4L, 5L ) ) ); } assertThat( query( range( 0, obj1, false, obj2, true ), exists( 1 ) ), equalTo( singletonList( 2L ) ) ); assertThat( query( range( 0, obj1, false, obj3, false ), exists( 1 ) ), equalTo( singletonList( 2L ) ) ); }
@Test public void testIndexSeekPrefixRangeWithExistsByString() throws Exception { Assume.assumeTrue( "Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries() ); updateAndCommit( asList( add( 1L, descriptor.schema(), "a", 1 ), add( 2L, descriptor.schema(), "A", epochDate( 2 ) ), add( 3L, descriptor.schema(), "apa", "..." ), add( 4L, descriptor.schema(), "apA", "someString" ), add( 5L, descriptor.schema(), "b", true ), add( 6L, descriptor.schema(), "a", 100 ), add( 7L, descriptor.schema(), "A", epochDate( 200 ) ), add( 8L, descriptor.schema(), "apa", "!!!" ), add( 9L, descriptor.schema(), "apA", "someOtherString" ), add( 10L, descriptor.schema(), "b", false ) ) ); assertThat( query( IndexQuery.stringPrefix( 0, stringValue( "a" )), exists( 1 ) ), equalTo( asList( 1L, 3L, 4L, 6L, 8L, 9L ) ) ); assertThat( query( IndexQuery.stringPrefix( 0, stringValue( "A" )), exists( 1 ) ), equalTo( asList( 2L, 7L) ) ); assertThat( query( IndexQuery.stringPrefix( 0, stringValue( "ba") ), exists( 1 ) ), equalTo( EMPTY_LIST ) ); assertThat( query( IndexQuery.stringPrefix( 0, stringValue( "" )), exists( 1 ) ), equalTo( asList( 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L ) ) ); }
@Test public void testDateArray() { LocalDate[] array = new LocalDate[]{DateValue.date( 2018, 1, 31 ).asObjectCopy(), DateValue.epochDate( 2147483648L ).asObjectCopy()}; String key = "testarray"; node1.setProperty( key, array ); newTransaction(); LocalDate[] propertyValue = (LocalDate[]) node1.getProperty( key ); assertEquals( array.length, propertyValue.length ); for ( int i = 0; i < array.length; i++ ) { assertEquals( array[i], propertyValue[i] ); } node1.removeProperty( key ); newTransaction(); assertTrue( !node1.hasProperty( key ) ); }
@Override public Value asValue() { return DateValue.epochDate( epochDay ); }
private static DateValue readDate( ByteBuffer chunk, int offset ) { return epochDate( chunk.getLong( offset ) ); }
@Override public Value decodeForTemporal( long[] valueBlocks, int offset ) { long epochDay = valueIsInlined( valueBlocks[offset] ) ? valueBlocks[offset] >>> 33 : valueBlocks[1 + offset]; return DateValue.epochDate( epochDay ); }
private DateValue unpackDate() throws IOException { long epochDay = unpackLong(); return epochDate( epochDay ); }