use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class CypherBoolean method in.
@CalledFromGeneratedCode
public static Value in(AnyValue lhs, AnyValue rhs) {
assert rhs != NO_VALUE;
ListValue anyValues = CypherFunctions.asList(rhs);
boolean seenUndefined = false;
for (AnyValue value : anyValues) {
switch(lhs.ternaryEquals(value)) {
case TRUE:
return Values.TRUE;
case UNDEFINED:
seenUndefined = true;
case FALSE:
break;
default:
throw new IllegalStateException("Unknown state");
}
}
return seenUndefined ? NO_VALUE : Values.FALSE;
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class CypherFunctions method fullSlice.
public static ListValue fullSlice(AnyValue collection, AnyValue fromValue, AnyValue toValue) {
assert collection != NO_VALUE && fromValue != NO_VALUE && toValue != NO_VALUE : "NO_VALUE checks need to happen outside this call";
int from = asInt(fromValue);
int to = asInt(toValue);
ListValue list = asList(collection);
int size = list.size();
if (from >= 0 && to >= 0) {
return list.slice(from, to);
} else if (from >= 0) {
return list.slice(from, size + to);
} else if (to >= 0) {
return list.slice(size + from, to);
} else {
return list.slice(size + from, size + to);
}
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class CypherFunctions method fromSlice.
public static ListValue fromSlice(AnyValue collection, AnyValue fromValue) {
assert collection != NO_VALUE && fromValue != NO_VALUE : "NO_VALUE checks need to happen outside this call";
int from = asInt(fromValue);
ListValue list = asList(collection);
if (from >= 0) {
return list.drop(from);
} else {
return list.drop(list.size() + from);
}
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class SchemaProcedureIT method testLabelIndex.
@Test
void testLabelIndex() throws Throwable {
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
long nbrIndexesOnStartup = Iterators.count(transaction.schemaRead().indexesGetAll());
// Given there is label with index and a constraint
long nodeId = transaction.dataWrite().nodeCreate();
int labelId = transaction.tokenWrite().labelGetOrCreateForName("Person");
transaction.dataWrite().nodeAddLabel(nodeId, labelId);
int propertyIdName = transaction.tokenWrite().propertyKeyGetOrCreateForName("name");
int propertyIdAge = transaction.tokenWrite().propertyKeyGetOrCreateForName("age");
transaction.dataWrite().nodeSetProperty(nodeId, propertyIdName, Values.of("Emil"));
commit();
SchemaWrite schemaOps = schemaWriteInNewTransaction();
schemaOps.indexCreate(forLabel(labelId, propertyIdName), "my index");
schemaOps.uniquePropertyConstraintCreate(uniqueForSchema(forLabel(labelId, propertyIdAge)).withName("constraint name"));
commit();
// When
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "schema", "visualization")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
while (stream.hasNext()) {
AnyValue[] next = stream.next();
assertEquals(2, next.length);
ListValue nodes = (ListValue) next[0];
assertEquals(1, nodes.size());
NodeValue node = (NodeValue) nodes.value(0);
assertThat(node.labels()).isEqualTo(Values.stringArray("Person"));
assertEquals(stringValue("Person"), node.properties().get("name"));
assertEquals(VirtualValues.list(stringValue("name")), node.properties().get("indexes"));
assertEquals(VirtualValues.list(stringValue("Constraint( id=" + (3 + nbrIndexesOnStartup) + ", name='constraint name', type='UNIQUENESS', schema=(:Person {age}), " + "ownedIndex=" + (2 + nbrIndexesOnStartup) + " )")), node.properties().get("constraints"));
}
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class SchemaProcedureIT method testRelationShip.
@Test
void testRelationShip() throws Throwable {
// Given there ar
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
long nodeIdPerson = transaction.dataWrite().nodeCreate();
int labelIdPerson = transaction.tokenWrite().labelGetOrCreateForName("Person");
transaction.dataWrite().nodeAddLabel(nodeIdPerson, labelIdPerson);
long nodeIdLocation = transaction.dataWrite().nodeCreate();
int labelIdLocation = transaction.tokenWrite().labelGetOrCreateForName("Location");
transaction.dataWrite().nodeAddLabel(nodeIdLocation, labelIdLocation);
int relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName("LIVES_IN");
transaction.dataWrite().relationshipCreate(nodeIdPerson, relationshipTypeId, nodeIdLocation);
commit();
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "schema", "visualization")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
while (stream.hasNext()) {
AnyValue[] next = stream.next();
assertEquals(2, next.length);
ListValue relationships = (ListValue) next[1];
assertEquals(1, relationships.size());
RelationshipValue relationship = (RelationshipValue) relationships.value(0);
assertEquals("LIVES_IN", relationship.type().stringValue());
assertThat(relationship.startNode().labels()).isEqualTo(Values.stringArray("Person"));
assertThat(relationship.endNode().labels()).isEqualTo(Values.stringArray("Location"));
}
}
Aggregations