use of org.neo4j.values.storable.LongValue in project neo4j by neo4j.
the class ProcedureCompilation method toAnyValue.
/**
* Takes an expression evaluating to one of the supported java values and turns
* it into the corresponding AnyValue
*
* @param expression the expression to evaluate
* @param userType the type of the expression to map
* @return an expression properly mapped to AnyValue
*/
private static Expression toAnyValue(Expression expression, Class<?> userType, Expression context) {
if (AnyValue.class.isAssignableFrom(userType)) {
return nullCheck(expression, cast(userType, expression));
}
String type = userType.getCanonicalName();
if (type.equals(LONG)) {
return invoke(methodReference(Values.class, LongValue.class, "longValue", long.class), expression);
} else if (type.equals(BOXED_LONG)) {
return nullCheck(expression, invoke(methodReference(Values.class, LongValue.class, "longValue", long.class), unbox(expression)));
} else if (type.equals(DOUBLE)) {
return invoke(methodReference(Values.class, DoubleValue.class, "doubleValue", double.class), expression);
} else if (type.equals(BOXED_DOUBLE)) {
return nullCheck(expression, invoke(methodReference(Values.class, DoubleValue.class, "doubleValue", double.class), unbox(expression)));
} else if (type.equals(NUMBER)) {
return nullCheck(expression, invoke(methodReference(Values.class, NumberValue.class, "numberValue", Number.class), expression));
} else if (type.equals(BOOLEAN)) {
return invoke(methodReference(Values.class, BooleanValue.class, "booleanValue", boolean.class), expression);
} else if (type.equals(BOXED_BOOLEAN)) {
return nullCheck(expression, invoke(methodReference(Values.class, BooleanValue.class, "booleanValue", boolean.class), unbox(expression)));
} else if (type.equals(STRING)) {
return invoke(methodReference(Values.class, Value.class, "stringOrNoValue", String.class), expression);
} else if (type.equals(BYTE_ARRAY)) {
return nullCheck(expression, invoke(methodReference(Values.class, ByteArray.class, "byteArray", byte[].class), expression));
} else if (type.equals(LIST)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, ListValue.class, "asListValue", Iterable.class), expression));
} else if (type.equals(MAP)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, MapValue.class, "asMapValue", Map.class), expression));
} else if (type.equals(ZONED_DATE_TIME)) {
return nullCheck(expression, invoke(methodReference(DateTimeValue.class, DateTimeValue.class, "datetime", ZonedDateTime.class), expression));
} else if (type.equals(OFFSET_TIME)) {
return nullCheck(expression, invoke(methodReference(TimeValue.class, TimeValue.class, "time", OffsetTime.class), expression));
} else if (type.equals(LOCAL_DATE)) {
return nullCheck(expression, invoke(methodReference(DateValue.class, DateValue.class, "date", LocalDate.class), expression));
} else if (type.equals(LOCAL_TIME)) {
return nullCheck(expression, invoke(methodReference(LocalTimeValue.class, LocalTimeValue.class, "localTime", LocalTime.class), expression));
} else if (type.equals(LOCAL_DATE_TIME)) {
return nullCheck(expression, invoke(methodReference(LocalDateTimeValue.class, LocalDateTimeValue.class, "localDateTime", LocalDateTime.class), expression));
} else if (type.equals(TEMPORAL_AMOUNT)) {
return nullCheck(expression, invoke(methodReference(Values.class, DurationValue.class, "durationValue", TemporalAmount.class), expression));
} else if (type.equals(NODE)) {
Expression internalTransaction = invoke(context, methodReference(Context.class, InternalTransaction.class, "internalTransactionOrNull"));
Expression getNode = invoke(internalTransaction, methodReference(InternalTransaction.class, Entity.class, "validateSameDB", Entity.class), expression);
return nullCheck(expression, invoke(methodReference(ValueUtils.class, NodeValue.class, "fromNodeEntity", Node.class), getNode));
} else if (type.equals(RELATIONSHIP)) {
Expression internalTransaction = invoke(context, methodReference(Context.class, InternalTransaction.class, "internalTransactionOrNull"));
Expression getRelationship = invoke(internalTransaction, methodReference(InternalTransaction.class, Entity.class, "validateSameDB", Entity.class), expression);
return nullCheck(expression, invoke(methodReference(ValueUtils.class, RelationshipValue.class, "fromRelationshipEntity", Relationship.class), getRelationship));
} else if (type.equals(PATH)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, PathValue.class, "fromPath", Path.class), expression));
} else if (type.equals(POINT)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, PointValue.class, "asPointValue", Point.class), expression));
} else {
return invoke(methodReference(ValueUtils.class, AnyValue.class, "of", Object.class), expression);
}
}
use of org.neo4j.values.storable.LongValue in project neo4j by neo4j.
the class HeapTrackingListValueBuilderTest method streamAndCollectElements.
@Test
void streamAndCollectElements() {
int iterations = rnd.nextInt(10, 1000);
ArrayList<LongValue> list = new ArrayList<>(iterations);
for (int i = 0; i < iterations; i++) {
list.add(Values.longValue(i));
}
var collector = HeapTrackingListValueBuilder.collector(memoryTracker);
ListValue listValue = list.stream().collect(collector);
// Validate value size
long memoryTrackerActualSize = meter.measureDeep(memoryTracker);
long actualValueSize = meter.measureDeep(listValue) - memoryTrackerActualSize;
long estimatedValueSize = listValue.estimatedHeapUsage();
assertEquals(actualValueSize, estimatedValueSize);
// Validate items
Iterator<AnyValue> iterator = listValue.iterator();
for (int i = 0; i < iterations; i++) {
assertTrue(iterator.hasNext());
assertEquals(i, ((LongValue) iterator.next()).longValue());
}
assertFalse(iterator.hasNext());
}
use of org.neo4j.values.storable.LongValue in project neo4j by neo4j.
the class PrimitiveOnlyValueWriterTest method shouldConvertLongValueToLong.
@Test
void shouldConvertLongValueToLong() {
PrimitiveOnlyValueWriter writer = new PrimitiveOnlyValueWriter();
LongValue value = longValue(42);
assertEquals(42L, writer.valueAsObject(value));
}
use of org.neo4j.values.storable.LongValue in project neo4j by neo4j.
the class PrimitiveOnlyValueWriterTest method shouldConvertMultipleValues.
@Test
void shouldConvertMultipleValues() {
PrimitiveOnlyValueWriter writer = new PrimitiveOnlyValueWriter();
TextValue value1 = stringValue("Hello");
TextValue value2 = stringValue(" ");
TextValue value3 = stringValue("World!");
LongValue value4 = longValue(42);
assertEquals("Hello", writer.valueAsObject(value1));
assertEquals(" ", writer.valueAsObject(value2));
assertEquals("World!", writer.valueAsObject(value3));
assertEquals(42L, writer.valueAsObject(value4));
}
use of org.neo4j.values.storable.LongValue in project neo4j by neo4j.
the class RoutingResultFormat method build.
public static AnyValue[] build(RoutingResult result) {
ListValue routers = asValues(result.routeEndpoints());
ListValue readers = asValues(result.readEndpoints());
ListValue writers = asValues(result.writeEndpoints());
ListValueBuilder servers = ListValueBuilder.newListBuilder();
if (writers.size() > 0) {
MapValueBuilder builder = new MapValueBuilder();
builder.add(ROLE_KEY, WRTE_NAME);
builder.add(ADDRESSES_KEY, writers);
servers.add(builder.build());
}
if (readers.size() > 0) {
MapValueBuilder builder = new MapValueBuilder();
builder.add(ROLE_KEY, READ_NAME);
builder.add(ADDRESSES_KEY, readers);
servers.add(builder.build());
}
if (routers.size() > 0) {
MapValueBuilder builder = new MapValueBuilder();
builder.add(ROLE_KEY, ROUTE_NAME);
builder.add(ADDRESSES_KEY, routers);
servers.add(builder.build());
}
LongValue timeToLiveSeconds = longValue(MILLISECONDS.toSeconds(result.ttlMillis()));
return new AnyValue[] { timeToLiveSeconds, servers.build() };
}
Aggregations