Search in sources :

Example 1 with NodeValue

use of org.neo4j.values.virtual.NodeValue in project neo4j by neo4j.

the class CypherFunctions method asPoint.

private static Value asPoint(DbAccess access, VirtualNodeValue nodeValue, NodeCursor nodeCursor, PropertyCursor propertyCursor) {
    MapValueBuilder builder = new MapValueBuilder();
    for (String key : POINT_KEYS) {
        Value value = access.nodeProperty(nodeValue.id(), access.propertyKey(key), nodeCursor, propertyCursor, true);
        if (value == NO_VALUE) {
            continue;
        }
        builder.add(key, value);
    }
    return PointValue.fromMap(builder.build());
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) TemporalValue(org.neo4j.values.storable.TemporalValue) ArrayValue(org.neo4j.values.storable.ArrayValue) Values.doubleValue(org.neo4j.values.storable.Values.doubleValue) NodeValue(org.neo4j.values.virtual.NodeValue) Value(org.neo4j.values.storable.Value) Values.longValue(org.neo4j.values.storable.Values.longValue) StringValue(org.neo4j.values.storable.StringValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) TextValue(org.neo4j.values.storable.TextValue) PointValue(org.neo4j.values.storable.PointValue) SequenceValue(org.neo4j.values.SequenceValue) PathValue(org.neo4j.values.virtual.PathValue) AnyValue(org.neo4j.values.AnyValue) DoubleValue(org.neo4j.values.storable.DoubleValue) DurationValue(org.neo4j.values.storable.DurationValue) MapValue(org.neo4j.values.virtual.MapValue) NumberValue(org.neo4j.values.storable.NumberValue) LongValue(org.neo4j.values.storable.LongValue) BooleanValue(org.neo4j.values.storable.BooleanValue) ListValue(org.neo4j.values.virtual.ListValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) VirtualNodeValue(org.neo4j.values.virtual.VirtualNodeValue) IntegralValue(org.neo4j.values.storable.IntegralValue) VirtualRelationshipValue(org.neo4j.values.virtual.VirtualRelationshipValue)

Example 2 with NodeValue

use of org.neo4j.values.virtual.NodeValue 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 3 with NodeValue

use of org.neo4j.values.virtual.NodeValue in project neo4j by neo4j.

the class PathWrappingPathValue method nodes.

@Override
public NodeValue[] nodes() {
    int length = path.length() + 1;
    NodeValue[] values = new NodeValue[length];
    int i = 0;
    for (Node node : path.nodes()) {
        values[i++] = ValueUtils.fromNodeEntity(node);
    }
    return values;
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) Node(org.neo4j.graphdb.Node)

Example 4 with NodeValue

use of org.neo4j.values.virtual.NodeValue in project neo4j by neo4j.

the class BoltRequestMessageV3Test method shouldSerializeNode.

// "B1 71 91 B3 4E 0C 92 |84 55 73 65 72 | 86 42 61 6E\n61 6E 61 A284 6E 61 6D 65 83 42 6F 62 83 61 67\n65 0E"
// "B1 71 91 B3 4E 0C 92 |86 42 61 6E 61 6E 61| 84 55\n73 65 72 A2 84 6E 61 6D 65 83 42 6F 62 83 61 67\n65 0E
@Test
void shouldSerializeNode() throws Throwable {
    NodeValue nodeValue = nodeValue(12L, stringArray("User", "Banana"), map(new String[] { "name", "age" }, new AnyValue[] { stringValue("Bob"), intValue(14) }));
    assertThat(serialized(nodeValue)).isEqualTo("B1 71 91 B3 4E 0C 92 84 55 73 65 72 86 42 61 6E" + lineSeparator() + "61 6E 61 A2 84 6E 61 6D 65 83 42 6F 62 83 61 67" + lineSeparator() + "65 0E");
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 5 with NodeValue

use of org.neo4j.values.virtual.NodeValue in project neo4j by neo4j.

the class PathValueBuilderTest method shouldHandleSingleNode.

@Test
void shouldHandleSingleNode() {
    // Given
    NodeValue node = node(42);
    PathValueBuilder builder = builder(node);
    // When
    builder.addNode(node);
    // Then
    assertEquals(path(node), builder.build());
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) Test(org.junit.jupiter.api.Test)

Aggregations

NodeValue (org.neo4j.values.virtual.NodeValue)26 Test (org.junit.jupiter.api.Test)22 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)13 AnyValue (org.neo4j.values.AnyValue)5 PathValue (org.neo4j.values.virtual.PathValue)3 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 ListValue (org.neo4j.values.virtual.ListValue)2 MapValue (org.neo4j.values.virtual.MapValue)2 VirtualNodeValue (org.neo4j.values.virtual.VirtualNodeValue)2 VirtualRelationshipValue (org.neo4j.values.virtual.VirtualRelationshipValue)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1 Mockito (org.mockito.Mockito)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 Answer (org.mockito.stubbing.Answer)1