Search in sources :

Example 31 with MapValue

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

the class NodeEntityWrappingNodeValue method writeTo.

@Override
public <E extends Exception> void writeTo(AnyValueWriter<E> writer) throws E {
    if (writer.entityMode() == REFERENCE) {
        writer.writeNodeReference(id());
    } else {
        TextArray l;
        MapValue p;
        try {
            l = labels();
            p = properties();
        } catch (ReadAndDeleteTransactionConflictException e) {
            if (!e.wasDeletedInThisTransaction()) {
                throw e;
            }
            // If it isn't a transient error then the node was deleted in the current transaction and we should write an 'empty' node.
            l = Values.stringArray();
            p = VirtualValues.EMPTY_MAP;
        }
        if (id() < 0) {
            writer.writeVirtualNodeHack(node);
        }
        writer.writeNode(node.getId(), l, p);
    }
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) TextArray(org.neo4j.values.storable.TextArray)

Example 32 with MapValue

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

the class ExecutingQuery method snapshot.

// snapshot state
public QuerySnapshot snapshot() {
    // capture a consistent snapshot of the "live" state
    ExecutingQueryStatus status;
    long waitTimeNanos;
    long currentTimeNanos;
    long cpuTimeNanos;
    String queryText;
    MapValue queryParameters;
    do {
        // read barrier, must be first
        status = this.status;
        // the reason for the retry loop: don't count the wait time twice
        waitTimeNanos = this.waitTimeNanos;
        cpuTimeNanos = cpuClock.cpuTimeNanos(threadExecutingTheQueryId);
        // capture the time as close to the snapshot as possible
        currentTimeNanos = clock.nanos();
        queryText = this.obfuscatedQueryText;
        queryParameters = this.obfuscatedQueryParameters;
    } while (this.status != status);
    // guarded by barrier - unused if status is planning, stable otherwise
    long compilationCompletedNanos = this.compilationCompletedNanos;
    // guarded by barrier - like compilationCompletedNanos
    CompilerInfo planner = status.isParsingOrPlanning() ? null : this.compilerInfo;
    List<ActiveLock> waitingOnLocks = status.isWaitingOnLocks() ? status.waitingOnLocks() : Collections.emptyList();
    // activeLockCount is not atomic to capture, so we capture it after the most sensitive part.
    long totalActiveLocks = transactionBinding.activeLockCount.getAsLong();
    // just needs to be captured at some point...
    var hits = pageHitsOfClosedTransactions + transactionBinding.hitsSupplier.getAsLong();
    var faults = pageFaultsOfClosedTransactions + transactionBinding.faultsSupplier.getAsLong();
    PageCounterValues pageCounters = new PageCounterValues(hits, faults);
    // - at this point we are done capturing the "live" state, and can start computing the snapshot -
    long compilationTimeNanos = (status.isParsingOrPlanning() ? currentTimeNanos : compilationCompletedNanos) - startTimeNanos;
    long elapsedTimeNanos = currentTimeNanos - startTimeNanos;
    cpuTimeNanos -= cpuTimeNanosWhenQueryStarted;
    waitTimeNanos += status.waitTimeNanos(currentTimeNanos);
    return new QuerySnapshot(this, planner, pageCounters, NANOSECONDS.toMicros(compilationTimeNanos), NANOSECONDS.toMicros(elapsedTimeNanos), cpuTimeNanos == 0 && cpuTimeNanosWhenQueryStarted == -1 ? -1 : NANOSECONDS.toMicros(cpuTimeNanos), NANOSECONDS.toMicros(waitTimeNanos), status.name(), status.toMap(currentTimeNanos), waitingOnLocks, totalActiveLocks - transactionBinding.initialActiveLocks, memoryTracker.totalAllocatedMemory(), Optional.ofNullable(queryText), Optional.ofNullable(queryParameters), transactionId);
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) MapValue(org.neo4j.values.virtual.MapValue)

Example 33 with MapValue

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

the class PrettyPrinterTest method shouldHandleMaps.

@Test
void shouldHandleMaps() {
    // Given
    PrettyPrinter printer = new PrettyPrinter();
    MapValue mapValue = props("k1", intValue(42));
    // When
    mapValue.writeTo(printer);
    // Then
    assertThat(printer.value()).isEqualTo("{k1: 42}");
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 34 with MapValue

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

the class AnyValueComparatorTest method shouldTernaryCompareRelationships.

@Test
void shouldTernaryCompareRelationships() {
    NodeValue start = nodeValue(42, stringArray("L"), EMPTY_MAP);
    NodeValue end = nodeValue(43, stringArray("L"), EMPTY_MAP);
    MapValue propMap = map("foo", "bar");
    RelationshipValue rel1 = relationshipValue(42, start, end, stringValue("R"), propMap);
    RelationshipValue rel2 = relationshipValue(43, start, end, stringValue("R"), propMap);
    assertTernaryCompare(rel1, rel1, EQUAL);
    assertTernaryCompare(rel1, rel2, SMALLER_THAN);
    assertTernaryCompare(rel1, relationship(rel1.id()), EQUAL);
    assertTernaryCompare(rel1, intValue(42), UNDEFINED);
    assertTernaryCompare(rel1, propMap, UNDEFINED);
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) MapValue(org.neo4j.values.virtual.MapValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test)

Example 35 with MapValue

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

the class UserFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.

@Test
void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
    // Given
    List<CallableUserFunction> compiled = compile(UserFunctionTest.MultiFunction.class);
    CallableUserFunction bananaPeople = compiled.get(0);
    CallableUserFunction coolPeople = compiled.get(1);
    // When
    Object coolOut = coolPeople.apply(prepareContext(), new AnyValue[0]);
    Object bananaOut = bananaPeople.apply(prepareContext(), new AnyValue[0]);
    // Then
    assertThat(coolOut).isEqualTo(ValueUtils.of(Arrays.asList("Bonnie", "Clyde")));
    assertThat(((MapValue) bananaOut).get("foo")).isEqualTo(ValueUtils.of(Arrays.asList("bar", "baz")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

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