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);
}
}
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);
}
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}");
}
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);
}
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")));
}
Aggregations