Search in sources :

Example 6 with MapValueBuilder

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

the class ExecutionPlanConverter method convert.

public static MapValue convert(ExecutionPlanDescription plan) {
    boolean hasProfilerStatistics = plan.hasProfilerStatistics();
    int size = hasProfilerStatistics ? 10 : 4;
    MapValueBuilder out = new MapValueBuilder(size);
    out.add("operatorType", utf8Value(plan.getName()));
    out.add("args", ValueUtils.asMapValue(plan.getArguments()));
    out.add("identifiers", ValueUtils.asListValue(plan.getIdentifiers()));
    out.add("children", children(plan));
    if (hasProfilerStatistics) {
        ExecutionPlanDescription.ProfilerStatistics profile = plan.getProfilerStatistics();
        if (profile.hasDbHits()) {
            out.add("dbHits", longValue(profile.getDbHits()));
        }
        if (profile.hasPageCacheStats()) {
            out.add("pageCacheHits", longValue(profile.getPageCacheHits()));
            out.add("pageCacheMisses", longValue(profile.getPageCacheMisses()));
            out.add("pageCacheHitRatio", doubleValue(profile.getPageCacheHitRatio()));
        }
        if (profile.hasRows()) {
            out.add("rows", longValue(profile.getRows()));
        }
        if (profile.hasTime()) {
            out.add("time", longValue(profile.getTime()));
        }
    }
    return out.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) ExecutionPlanDescription(org.neo4j.graphdb.ExecutionPlanDescription)

Example 7 with MapValueBuilder

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

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

the class JmxQueryProcedure method toNeo4jValue.

private MapValue toNeo4jValue(ObjectName name, MBeanAttributeInfo attribute) throws JMException {
    AnyValue value;
    try {
        value = toNeo4jValue(jmxServer.getAttribute(name, attribute.getName()));
    } catch (RuntimeMBeanException e) {
        if (e.getCause() != null && e.getCause() instanceof UnsupportedOperationException) {
            // We include the name and description of this attribute still - but the value of it is
            // unknown. We do this rather than rethrow the exception, because several MBeans built into
            // the JVM will throw exception on attribute access depending on their runtime state, even
            // if the attribute is marked as readable. Notably the GC beans do this.
            value = NO_VALUE;
        } else {
            throw e;
        }
    }
    MapValueBuilder builder = new MapValueBuilder(2);
    builder.add("description", stringValue(attribute.getDescription()));
    builder.add("value", value);
    return builder.build();
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) AnyValue(org.neo4j.values.AnyValue)

Example 9 with MapValueBuilder

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

the class JmxQueryProcedure method toNeo4jValue.

private MapValue toNeo4jValue(Map<?, ?> attributeValue) {
    // Build a new map with the same keys, but each value passed
    // through `toNeo4jValue`
    MapValueBuilder builder = new MapValueBuilder();
    attributeValue.forEach((key, value) -> builder.add(key.toString(), toNeo4jValue(value)));
    return builder.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder)

Example 10 with MapValueBuilder

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

the class ValueMapperTest method valueOf.

private static AnyValue valueOf(Object obj) {
    if (obj instanceof MappedGraphType) {
        return ((MappedGraphType) obj).value;
    }
    Value value = Values.unsafeOf(obj, true);
    if (value != null) {
        return value;
    }
    if (obj instanceof List<?>) {
        return ((List<?>) obj).stream().map(ValueMapperTest::valueOf).collect(ListValueBuilder.collector());
    }
    if (obj instanceof Map<?, ?>) {
        @SuppressWarnings("unchecked") Map<String, ?> map = (Map<String, ?>) obj;
        int size = map.size();
        if (size == 0) {
            return EMPTY_MAP;
        }
        MapValueBuilder builder = new MapValueBuilder(size);
        for (Map.Entry<String, ?> entry : map.entrySet()) {
            builder.add(entry.getKey(), valueOf(entry.getValue()));
        }
        return builder.build();
    }
    throw new AssertionError("cannot convert: " + obj + " (a " + obj.getClass().getName() + ")");
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) Values.booleanValue(org.neo4j.values.storable.Values.booleanValue) 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) Values.shortValue(org.neo4j.values.storable.Values.shortValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Values.floatValue(org.neo4j.values.storable.Values.floatValue) Values.numberValue(org.neo4j.values.storable.Values.numberValue) VirtualValues.relationshipValue(org.neo4j.values.virtual.VirtualValues.relationshipValue) Values.byteValue(org.neo4j.values.storable.Values.byteValue) VirtualValues.nodeValue(org.neo4j.values.virtual.VirtualValues.nodeValue) Values.intValue(org.neo4j.values.storable.Values.intValue) PathValue(org.neo4j.values.virtual.PathValue) Values.pointValue(org.neo4j.values.storable.Values.pointValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) VirtualNodeValue(org.neo4j.values.virtual.VirtualNodeValue) Values.charValue(org.neo4j.values.storable.Values.charValue) VirtualRelationshipValue(org.neo4j.values.virtual.VirtualRelationshipValue) List(java.util.List) Map(java.util.Map) Point(org.neo4j.graphdb.spatial.Point)

Aggregations

MapValueBuilder (org.neo4j.values.virtual.MapValueBuilder)22 AnyValue (org.neo4j.values.AnyValue)6 SocketAddress (org.neo4j.configuration.helpers.SocketAddress)5 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)5 Map (java.util.Map)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 Point (org.neo4j.graphdb.spatial.Point)3 HostnamePort (org.neo4j.internal.helpers.HostnamePort)3 LongValue (org.neo4j.values.storable.LongValue)3 Value (org.neo4j.values.storable.Value)3 Values.doubleValue (org.neo4j.values.storable.Values.doubleValue)3 Values.longValue (org.neo4j.values.storable.Values.longValue)3 Values.stringValue (org.neo4j.values.storable.Values.stringValue)3 NodeValue (org.neo4j.values.virtual.NodeValue)3 PathValue (org.neo4j.values.virtual.PathValue)3 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)3 VirtualNodeValue (org.neo4j.values.virtual.VirtualNodeValue)3 VirtualRelationshipValue (org.neo4j.values.virtual.VirtualRelationshipValue)3 SequenceValue (org.neo4j.values.SequenceValue)2