use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class TimeValue method builder.
private static TimeBuilder<TimeValue> builder(Supplier<ZoneId> defaultZone) {
return new TimeBuilder<>(defaultZone) {
@Override
protected boolean supportsTimeZone() {
return true;
}
@Override
public TimeValue buildInternal() {
boolean selectingTime = fields.containsKey(TemporalFields.time);
boolean selectingTimeZone;
OffsetTime result;
if (selectingTime) {
AnyValue time = fields.get(TemporalFields.time);
if (!(time instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct time from: %s", time));
}
TemporalValue t = (TemporalValue) time;
result = t.getTimePart(defaultZone);
selectingTimeZone = t.supportsTimeZone();
} else {
ZoneId timezone = timezone();
if (!(timezone instanceof ZoneOffset)) {
timezone = assertValidArgument(() -> ZonedDateTime.ofInstant(Instant.now(), timezone())).getOffset();
}
result = defaultTime(timezone);
selectingTimeZone = false;
}
result = assignAllFields(result);
if (timezone != null) {
ZoneOffset currentOffset = assertValidArgument(() -> ZonedDateTime.ofInstant(Instant.now(), timezone())).getOffset();
if (selectingTime && selectingTimeZone) {
result = result.withOffsetSameInstant(currentOffset);
} else {
result = result.withOffsetSameLocal(currentOffset);
}
}
return time(result);
}
@Override
protected TimeValue selectTime(AnyValue temporal) {
if (!(temporal instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct time from: %s", temporal));
}
if (temporal instanceof TimeValue && timezone == null) {
return (TimeValue) temporal;
}
TemporalValue v = (TemporalValue) temporal;
OffsetTime time = v.getTimePart(defaultZone);
if (timezone != null) {
ZoneOffset currentOffset = assertValidArgument(() -> ZonedDateTime.ofInstant(Instant.now(), timezone())).getOffset();
time = time.withOffsetSameInstant(currentOffset);
}
return time(time);
}
};
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class TimeValue method truncate.
public static TimeValue truncate(TemporalUnit unit, TemporalValue input, MapValue fields, Supplier<ZoneId> defaultZone) {
OffsetTime time = input.getTimePart(defaultZone);
OffsetTime truncatedOT = assertValidUnit(() -> time.truncatedTo(unit));
if (fields.size() == 0) {
return time(truncatedOT);
} else {
// Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
AnyValue timezone = fields.get("timezone");
if (timezone != NO_VALUE) {
ZonedDateTime currentDT = assertValidArgument(() -> ZonedDateTime.ofInstant(Instant.now(), timezoneOf(timezone)));
ZoneOffset currentOffset = currentDT.getOffset();
truncatedOT = truncatedOT.withOffsetSameLocal(currentOffset);
}
return updateFieldMapWithConflictingSubseconds(fields, unit, truncatedOT, (mapValue, offsetTime) -> {
if (mapValue.size() == 0) {
return time(offsetTime);
} else {
return build(mapValue.updatedWith("time", time(offsetTime)), defaultZone);
}
});
}
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class DbIndexesFailureMessageIT method listAllIndexesWithFailedIndex.
@Test
void listAllIndexesWithFailedIndex() throws Throwable {
// Given
KernelTransaction dataTransaction = newTransaction(AUTH_DISABLED);
String labelName = "Fail";
String propertyKey = "foo";
int failedLabel = dataTransaction.tokenWrite().labelGetOrCreateForName(labelName);
int propertyKeyId1 = dataTransaction.tokenWrite().propertyKeyGetOrCreateForName(propertyKey);
this.transaction.createNode(Label.label(labelName)).setProperty(propertyKey, "some value");
commit();
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
LabelSchemaDescriptor schema = forLabel(failedLabel, propertyKeyId1);
IndexDescriptor index = transaction.schemaWrite().indexCreate(schema, "fail foo index");
commit();
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
assertThrows(IllegalStateException.class, () -> tx.schema().awaitIndexesOnline(2, MINUTES));
}
// When
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexDetails")).id(), new TextValue[] { stringValue(index.getName()) }, ProcedureCallContext.EMPTY);
assertTrue(stream.hasNext());
AnyValue[] result = stream.next();
assertFalse(stream.hasNext());
// Commit procedure transaction
commit();
// Then
assertEquals(longValue(index.getId()), result[0]);
assertEquals(stringValue("fail foo index"), result[1]);
assertEquals(stringValue("FAILED"), result[2]);
assertEquals(doubleValue(0.0), result[3]);
assertEquals(stringValue("NONUNIQUE"), result[4]);
assertEquals(stringValue("BTREE"), result[5]);
assertEquals(stringValue("NODE"), result[6]);
assertEquals(VirtualValues.list(stringValue(labelName)), result[7]);
assertEquals(VirtualValues.list(stringValue(propertyKey)), result[8]);
assertEquals(stringValue(NATIVE_BTREE10.providerName()), result[9]);
assertMapsEqual(index.getIndexConfig().asMap(), (MapValue) result[10]);
assertThat(((TextValue) result[11]).stringValue()).contains("java.lang.RuntimeException: Fail on update during population");
assertEquals(12, result.length);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class HeapTrackingListValueBuilderTest method addAndIterateElements.
@Test
void addAndIterateElements() {
int iterations = rnd.nextInt(10, 1000);
for (int i = 0; i < iterations; i++) {
listValueBuilder.add(Values.longValue(i));
}
// Validate builder size
long memoryTrackerActualSize = meter.measureDeep(memoryTracker);
long actualBuilderSize = meter.measureDeep(listValueBuilder) - memoryTrackerActualSize;
long estimatedBuilderSize = memoryTracker.estimatedHeapMemory();
assertEquals(actualBuilderSize, estimatedBuilderSize);
// Validate value size
ListValue listValue = listValueBuilder.build();
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.AnyValue in project neo4j by neo4j.
the class UserFunctionTest method shouldGiveHelpfulErrorOnNullMessageException.
@Test
void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
// Given
CallableUserFunction proc = compile(FunctionThatThrowsNullMsgExceptionAtInvocation.class).get(0);
// When
ProcedureException exception = assertThrows(ProcedureException.class, () -> proc.apply(prepareContext(), new AnyValue[0]));
assertThat(exception.getMessage()).isEqualTo("Failed to invoke function `org.neo4j.procedure.impl.throwsAtInvocation`: Caused by: java.lang.IndexOutOfBoundsException");
}
Aggregations