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