Search in sources :

Example 31 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class ValueUtilsTest method shouldHandleCollection.

@Test
void shouldHandleCollection() {
    // Given
    Collection<Integer> collection = Arrays.asList(1, 2, 3);
    // When
    AnyValue of = ValueUtils.of(collection);
    // Then
    assertThat(of).isInstanceOf(ListValue.class);
    ListValue listValue = (ListValue) of;
    assertThat(listValue.value(0)).isEqualTo(intValue(1));
    assertThat(listValue.value(1)).isEqualTo(intValue(2));
    assertThat(listValue.value(2)).isEqualTo(intValue(3));
    assertThat(listValue.size()).isEqualTo(3);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 32 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class TemporalValue method updateFieldMapWithConflictingSubseconds.

static <TEMP extends Temporal, VALUE> VALUE updateFieldMapWithConflictingSubseconds(MapValue fields, TemporalUnit unit, TEMP temporal, BiFunction<MapValue, TEMP, VALUE> mapFunction) {
    boolean conflictingMilliSeconds = unit == ChronoUnit.MILLIS && (fields.containsKey("microsecond") || fields.containsKey("nanosecond"));
    boolean conflictingMicroSeconds = unit == ChronoUnit.MICROS && fields.containsKey("nanosecond");
    if (conflictingMilliSeconds) {
        AnyValue millis = Values.intValue(temporal.get(ChronoField.MILLI_OF_SECOND));
        AnyValue micros = fields.get("microsecond");
        AnyValue nanos = fields.get("nanosecond");
        int newNanos = validNano(millis, micros, nanos);
        TEMP newTemporal = (TEMP) temporal.with(ChronoField.NANO_OF_SECOND, newNanos);
        MapValue filtered = fields.filter((k, ignore) -> !k.equals("microsecond") && !k.equals("nanosecond"));
        return mapFunction.apply(filtered, newTemporal);
    } else if (conflictingMicroSeconds) {
        AnyValue micros = Values.intValue(temporal.get(ChronoField.MICRO_OF_SECOND));
        AnyValue nanos = fields.get("nanosecond");
        int newNanos = validNano(null, micros, nanos);
        TEMP newTemporal = (TEMP) temporal.with(ChronoField.NANO_OF_SECOND, newNanos);
        MapValue filtered = fields.filter((k, ignore) -> !k.equals("nanosecond"));
        return mapFunction.apply(filtered, newTemporal);
    } else {
        return mapFunction.apply(fields, temporal);
    }
}
Also used : ChronoField(java.time.temporal.ChronoField) AnyValue(org.neo4j.values.AnyValue) DateTimeValue.parseZoneName(org.neo4j.values.storable.DateTimeValue.parseZoneName) ZonedDateTime(java.time.ZonedDateTime) TemporalUnit(java.time.temporal.TemporalUnit) BiFunction(java.util.function.BiFunction) LocalDateTime(java.time.LocalDateTime) TemporalQuery(java.time.temporal.TemporalQuery) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ValueRange(java.time.temporal.ValueRange) Matcher(java.util.regex.Matcher) TemporalParseException(org.neo4j.exceptions.TemporalParseException) Map(java.util.Map) LocalTime(java.time.LocalTime) TemporalAmount(java.time.temporal.TemporalAmount) MapValue(org.neo4j.values.virtual.MapValue) ZoneOffset(java.time.ZoneOffset) StructureBuilder(org.neo4j.values.StructureBuilder) IntegralValue.safeCastIntegral(org.neo4j.values.storable.IntegralValue.safeCastIntegral) LocalDateTimeValue.localDateTime(org.neo4j.values.storable.LocalDateTimeValue.localDateTime) HashFunction(org.neo4j.hashing.HashFunction) DateTimeException(java.time.DateTimeException) OffsetTime(java.time.OffsetTime) EnumMap(java.util.EnumMap) UnsupportedTemporalUnitException(org.neo4j.exceptions.UnsupportedTemporalUnitException) TemporalField(java.time.temporal.TemporalField) Set(java.util.Set) DateTimeValue.datetime(org.neo4j.values.storable.DateTimeValue.datetime) TimeValue.time(org.neo4j.values.storable.TimeValue.time) UnsupportedTemporalTypeException(java.time.temporal.UnsupportedTemporalTypeException) ZoneId(java.time.ZoneId) InvalidArgumentException(org.neo4j.exceptions.InvalidArgumentException) NO_NUMBER(org.neo4j.values.storable.NumberType.NO_NUMBER) Objects(java.util.Objects) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) ChronoUnit(java.time.temporal.ChronoUnit) IsoFields(java.time.temporal.IsoFields) LocalDate(java.time.LocalDate) Pattern(java.util.regex.Pattern) Pair(org.neo4j.internal.helpers.collection.Pair) Temporal(java.time.temporal.Temporal) TemporalAdjuster(java.time.temporal.TemporalAdjuster) ArithmeticException(org.neo4j.exceptions.ArithmeticException) AnyValue(org.neo4j.values.AnyValue) MapValue(org.neo4j.values.virtual.MapValue)

Example 33 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class LocalTimeValue method builder.

private static TimeValue.TimeBuilder<LocalTimeValue> builder(Supplier<ZoneId> defaultZone) {
    return new TimeValue.TimeBuilder<>(defaultZone) {

        @Override
        protected boolean supportsTimeZone() {
            return false;
        }

        @Override
        public LocalTimeValue buildInternal() {
            LocalTime result;
            if (fields.containsKey(TemporalFields.time)) {
                AnyValue time = fields.get(TemporalFields.time);
                if (!(time instanceof TemporalValue)) {
                    throw new InvalidArgumentException(String.format("Cannot construct local time from: %s", time));
                }
                result = ((TemporalValue) time).getLocalTimePart();
            } else {
                result = DEFAULT_LOCAL_TIME;
            }
            result = assignAllFields(result);
            return localTime(result);
        }

        @Override
        protected LocalTimeValue selectTime(AnyValue time) {
            if (!(time instanceof TemporalValue)) {
                throw new InvalidArgumentException(String.format("Cannot construct local time from: %s", time));
            }
            TemporalValue v = (TemporalValue) time;
            LocalTime lt = v.getLocalTimePart();
            return localTime(lt);
        }
    };
}
Also used : InvalidArgumentException(org.neo4j.exceptions.InvalidArgumentException) LocalTime(java.time.LocalTime) AnyValue(org.neo4j.values.AnyValue)

Example 34 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class VirtualValues method map.

public static MapValue map(String[] keys, AnyValue[] values) {
    assert keys.length == values.length;
    long payloadSize = 0;
    Map<String, AnyValue> map = new HashMap<>((int) ((float) keys.length / 0.75f + 1.0f));
    for (int i = 0; i < keys.length; i++) {
        String key = keys[i];
        AnyValue value = values[i];
        map.put(key, value);
        payloadSize += sizeOf(key) + value.estimatedHeapUsage();
    }
    return new MapValue.MapWrappingMapValue(map, payloadSize);
}
Also used : HashMap(java.util.HashMap) AnyValue(org.neo4j.values.AnyValue)

Example 35 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class ListValue method iterationWriteTo.

private <E extends Exception> void iterationWriteTo(AnyValueWriter<E> writer) throws E {
    writer.beginList(size());
    for (AnyValue value : this) {
        value.writeTo(writer);
    }
    writer.endList();
}
Also used : AnyValue(org.neo4j.values.AnyValue)

Aggregations

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5