Search in sources :

Example 36 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class Neo4jPackV1Test method shouldBeAbleToPackAndUnpackMap.

@Test
void shouldBeAbleToPackAndUnpackMap() throws IOException {
    // Given
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = neo4jPack.newPacker(output);
    packer.packMapHeader(ALICE.properties().size());
    ALICE.properties().foreach((s, value) -> {
        try {
            packer.pack(s);
            packer.pack(value);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
    AnyValue unpacked = unpacked(output.bytes());
    // Then
    assertThat(unpacked).isInstanceOf(MapValue.class);
    MapValue unpackedMap = (MapValue) unpacked;
    assertThat(unpackedMap).isEqualTo(ALICE.properties());
}
Also used : AnyValue(org.neo4j.values.AnyValue) UncheckedIOException(java.io.UncheckedIOException) MapValue(org.neo4j.values.virtual.MapValue) IOException(java.io.IOException) BoltIOException(org.neo4j.bolt.messaging.BoltIOException) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test)

Example 37 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class ExecutionPlanConverterTest method noStatisticConversion.

@Test
void noStatisticConversion() {
    MapValue convertedMap = ExecutionPlanConverter.convert(new TestExecutionPlanDescription("description", null, getIdentifiers(), getArguments()));
    assertEquals(convertedMap.get("operatorType"), stringValue("description"));
    assertEquals(convertedMap.get("args"), ValueUtils.asMapValue(getArguments()));
    assertEquals(convertedMap.get("identifiers"), ValueUtils.asListValue(getIdentifiers()));
    assertEquals(convertedMap.get("children"), VirtualValues.EMPTY_LIST);
    assertEquals(convertedMap.size(), 4);
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 38 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class ExecutionPlanConverterTest method fullProfileStatisticConversion.

@Test
void fullProfileStatisticConversion() {
    MapValue convertedMap = ExecutionPlanConverter.convert(new TestExecutionPlanDescription("description", getFullProfilerStatistics(), getIdentifiers(), getArguments()));
    assertEquals(convertedMap.get("operatorType"), stringValue("description"));
    assertEquals(convertedMap.get("args"), ValueUtils.asMapValue(getArguments()));
    assertEquals(convertedMap.get("identifiers"), ValueUtils.asListValue(getIdentifiers()));
    assertEquals(convertedMap.get("children"), VirtualValues.EMPTY_LIST);
    assertEquals(convertedMap.get("rows"), longValue(1L));
    assertEquals(convertedMap.get("dbHits"), longValue(2L));
    assertEquals(convertedMap.get("pageCacheHits"), longValue(3L));
    assertEquals(convertedMap.get("pageCacheMisses"), longValue(2L));
    assertEquals(convertedMap.get("time"), longValue(5L));
    assertEquals(((DoubleValue) convertedMap.get("pageCacheHitRatio")).doubleValue(), 3.0 / 5, 0.0001);
    assertEquals(convertedMap.size(), 10);
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 39 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class BoltResponseMessageReader method read.

public void read(BoltResponseMessageWriter messageWriter) throws IOException {
    try {
        unpacker.unpackStructHeader();
        final int signature = unpacker.unpackStructSignature();
        BoltResponseMessage message = BoltResponseMessage.withSignature(signature);
        try {
            switch(message) {
                case SUCCESS:
                    MapValue successMetadata = unpacker.unpackMap();
                    messageWriter.write(new SuccessMessage(successMetadata));
                    break;
                case RECORD:
                    long length = unpacker.unpackListHeader();
                    final AnyValue[] fields = new AnyValue[(int) length];
                    for (int i = 0; i < length; i++) {
                        fields[i] = unpacker.unpack();
                    }
                    messageWriter.write(new RecordMessage(fields));
                    break;
                case IGNORED:
                    messageWriter.write(IgnoredMessage.IGNORED_MESSAGE);
                    break;
                case FAILURE:
                    MapValue failureMetadata = unpacker.unpackMap();
                    String code = failureMetadata.containsKey("code") ? ((StringValue) failureMetadata.get("code")).stringValue() : Status.General.UnknownError.name();
                    AnyValue msgValue = failureMetadata.get("message");
                    String msg = msgValue != NO_VALUE ? ((StringValue) msgValue).stringValue() : "<No message supplied>";
                    messageWriter.write(new FailureMessage(Neo4jError.codeFromString(code), msg));
                    break;
                default:
                    throw new BoltIOException(Status.Request.InvalidFormat, String.format("Message 0x%s is not supported.", Integer.toHexString(signature)));
            }
        } catch (IllegalArgumentException e) {
            throw new BoltIOException(Status.Request.InvalidFormat, String.format("Message 0x%s is not a valid message signature.", Integer.toHexString(signature)));
        }
    } catch (PackStream.PackStreamException e) {
        throw new BoltIOException(Status.Request.InvalidFormat, String.format("Unable to read message type. Error was: %s.", e.getMessage()), e);
    }
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) PackStream(org.neo4j.bolt.packstream.PackStream) SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) AnyValue(org.neo4j.values.AnyValue) FailureMessage(org.neo4j.bolt.v3.messaging.response.FailureMessage) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage)

Example 40 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class TemporalFunction method apply.

@Override
public final AnyValue apply(Context ctx, AnyValue[] input) throws ProcedureException {
    if (input == null || (input.length > 0 && (input[0] == NO_VALUE || input[0] == null))) {
        return NO_VALUE;
    } else if (input.length == 0 || input[0].equals(DEFAULT_TEMPORAL_ARGUMENT_VALUE)) {
        return now(ctx.statementClock(), null, defaultZone);
    } else if (input[0] instanceof TextValue) {
        return parse((TextValue) input[0], defaultZone);
    } else if (input[0] instanceof TemporalValue) {
        return select(input[0], defaultZone);
    } else if (input[0] instanceof MapValue) {
        MapValue map = (MapValue) input[0];
        String timezone = onlyTimezone(map);
        if (timezone != null) {
            return now(ctx.statementClock(), timezone, defaultZone);
        }
        return build(map, defaultZone);
    } else {
        throw new ProcedureException(Status.Procedure.ProcedureCallFailed, "Invalid call signature for " + getClass().getSimpleName() + ": Provided input was " + Arrays.toString(input));
    }
}
Also used : TextValue(org.neo4j.values.storable.TextValue) TemporalValue(org.neo4j.values.storable.TemporalValue) MapValue(org.neo4j.values.virtual.MapValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException)

Aggregations

MapValue (org.neo4j.values.virtual.MapValue)48 Test (org.junit.jupiter.api.Test)30 AnyValue (org.neo4j.values.AnyValue)7 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)6 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)6 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)5 QueryStatistics (org.neo4j.graphdb.QueryStatistics)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)3 ValueUtils.asMapValue (org.neo4j.kernel.impl.util.ValueUtils.asMapValue)3 Clock (java.time.Clock)2 LocalDate (java.time.LocalDate)2 HashMap (java.util.HashMap)2 SuccessMessage (org.neo4j.bolt.v3.messaging.response.SuccessMessage)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 RelationshipEntity (org.neo4j.kernel.impl.core.RelationshipEntity)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 DateTimeException (java.time.DateTimeException)1