Search in sources :

Example 1 with ListValue

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;
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Example 2 with ListValue

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);
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue)

Example 3 with ListValue

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);
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue)

Example 4 with ListValue

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"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValue(org.neo4j.values.virtual.NodeValue) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 5 with ListValue

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"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

ListValue (org.neo4j.values.virtual.ListValue)28 Test (org.junit.jupiter.api.Test)19 AnyValue (org.neo4j.values.AnyValue)14 ArrayList (java.util.ArrayList)3 LongValue (org.neo4j.values.storable.LongValue)3 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2 CalledFromGeneratedCode (org.neo4j.util.CalledFromGeneratedCode)2 BooleanValue (org.neo4j.values.storable.BooleanValue)2 Value (org.neo4j.values.storable.Value)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)2 List (java.util.List)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)1 EmptyMemoryTracker (org.neo4j.memory.EmptyMemoryTracker)1 MemoryTracker (org.neo4j.memory.MemoryTracker)1