Search in sources :

Example 6 with GraphProperty

use of com.alibaba.maxgraph.compiler.api.schema.GraphProperty in project GraphScope by alibaba.

the class EdgeTypeMapper method parseFromEdgeType.

public static SchemaElementMapper parseFromEdgeType(GraphEdge graphEdge) {
    EdgeTypeMapper edgeTypeMapper = new EdgeTypeMapper();
    edgeTypeMapper.setId(graphEdge.getLabelId());
    edgeTypeMapper.setLabel(graphEdge.getLabel());
    edgeTypeMapper.setType(TypeEnum.EDGE.toString());
    List<EdgeRelationMapper> relationMapperList = Lists.newArrayList();
    for (EdgeRelation edgeRelation : graphEdge.getRelationList()) {
        relationMapperList.add(EdgeRelationMapper.parseFromEdgeRelation(graphEdge.getLabel(), edgeRelation));
    }
    edgeTypeMapper.setRelationShips(relationMapperList);
    List<GraphPropertyMapper> propertyMapperList = Lists.newArrayList();
    for (GraphProperty graphProperty : graphEdge.getPropertyList()) {
        propertyMapperList.add(GraphPropertyMapper.parseFromGrapyProperty(graphProperty));
    }
    edgeTypeMapper.setPropertyDefList(propertyMapperList);
    return edgeTypeMapper;
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) EdgeRelation(com.alibaba.maxgraph.compiler.api.schema.EdgeRelation)

Example 7 with GraphProperty

use of com.alibaba.maxgraph.compiler.api.schema.GraphProperty in project GraphScope by alibaba.

the class Codec method encode.

public void encode(Map<Integer, PropertyValue> propertiesMap, ByteBuffer scratch) {
    scratch.putInt(this.version);
    scratch.put(this.nullBytesHolder);
    for (int i = 0; i < this.fixedPropertiesCount; i++) {
        GraphProperty propertyDef = this.propertyDefs.get(i);
        PropertyValue propertyValue = propertiesMap.get(propertyDef.getId());
        if (propertyValue != null) {
            writeBytes(scratch, this.offsets.get(i), propertyValue.getValBytes());
        } else if (propertyDef.getDefaultValue() != null) {
            PropertyValue defaultValue = new PropertyValue(propertyDef.getDataType(), propertyDef.getDefaultValue());
            writeBytes(scratch, this.offsets.get(i), defaultValue.getValBytes());
        } else {
            setNull(i, scratch);
        }
    }
    int varOffsetsPos = this.offsets.get(this.offsets.size() - 1);
    int dataOffset = varOffsetsPos + 3 * (this.propertyDefs.size() - this.fixedPropertiesCount);
    scratch.position(dataOffset);
    int varEndOffset = 0;
    for (int i = this.fixedPropertiesCount; i < this.propertyDefs.size(); i++) {
        GraphProperty propertyDef = this.propertyDefs.get(i);
        PropertyValue propertyValue = propertiesMap.get(propertyDef.getId());
        if (propertyValue != null) {
            byte[] valBytes = propertyValue.getValBytes();
            scratch.put(valBytes);
            varEndOffset += valBytes.length;
        } else if (propertyDef.getDefaultValue() != null) {
            PropertyValue defaultValue = new PropertyValue(propertyDef.getDataType(), propertyDef.getDefaultValue());
            byte[] valBytes = defaultValue.getValBytes();
            scratch.put(valBytes);
            varEndOffset += valBytes.length;
        } else {
            setNull(i, scratch);
        }
        byte[] endOffsetBytes = lengthBytes(varEndOffset);
        writeBytes(scratch, varOffsetsPos, endOffsetBytes);
        varOffsetsPos += 3;
    }
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)

Example 8 with GraphProperty

use of com.alibaba.maxgraph.compiler.api.schema.GraphProperty in project GraphScope by alibaba.

the class RpcProcessorUtils method deserializeProperty.

public static Map<String, Object> deserializeProperty(byte[] data, GraphElement typeDef, GraphSchema schema) {
    DataInputStream read = new DataInputStream(new ByteArrayInputStream(data));
    List<GraphProperty> properties = typeDef.getPropertyList();
    Map<String, Object> kv = new HashMap<>(properties.size());
    try {
        int propCount = read.readInt();
        for (int i = 0; i < propCount; i++) {
            int pid = read.readInt();
            GraphProperty property = typeDef.getProperty(pid);
            kv.put(property.getName(), readValueByType(property.getDataType(), read));
        }
    } catch (EOFException e) {
    // ignore;
    } catch (IOException e) {
        throw DataException.unknowError(e);
    }
    return kv;
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) EOFException(java.io.EOFException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 9 with GraphProperty

use of com.alibaba.maxgraph.compiler.api.schema.GraphProperty in project GraphScope by alibaba.

the class GraphWriter method parseRawProperties.

public static Map<Integer, PropertyValue> parseRawProperties(GraphElement graphElement, Map<String, Object> properties) {
    Map<Integer, PropertyValue> res = new HashMap<>();
    if (properties != null) {
        properties.forEach((propertyName, valString) -> {
            GraphProperty propertyDef = graphElement.getProperty(propertyName);
            if (propertyDef == null) {
                throw new PropertyDefNotFoundException("property [" + propertyName + "] not found in [" + graphElement.getLabel() + "]");
            }
            int id = propertyDef.getId();
            DataType dataType = propertyDef.getDataType();
            PropertyValue propertyValue = new PropertyValue(dataType, valString);
            res.put(id, propertyValue);
        });
    }
    return res;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) HashMap(java.util.HashMap) PropertyValue(com.alibaba.maxgraph.sdkcommon.schema.PropertyValue) DataType(com.alibaba.maxgraph.compiler.api.schema.DataType) PropertyDefNotFoundException(com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)

Example 10 with GraphProperty

use of com.alibaba.maxgraph.compiler.api.schema.GraphProperty in project GraphScope by alibaba.

the class EdgeTypeMapper method parseFromEdgeType.

public static SchemaElementMapper parseFromEdgeType(GraphEdge graphEdge) {
    EdgeTypeMapper edgeTypeMapper = new EdgeTypeMapper();
    edgeTypeMapper.setId(graphEdge.getLabelId());
    edgeTypeMapper.setLabel(graphEdge.getLabel());
    edgeTypeMapper.setType(TypeEnum.EDGE.toString());
    List<EdgeRelationMapper> relationMapperList = Lists.newArrayList();
    for (EdgeRelation edgeRelation : graphEdge.getRelationList()) {
        relationMapperList.add(EdgeRelationMapper.parseFromEdgeRelation(graphEdge.getLabel(), edgeRelation));
    }
    edgeTypeMapper.setRelationShips(relationMapperList);
    List<GraphPropertyMapper> propertyMapperList = Lists.newArrayList();
    for (GraphProperty graphProperty : graphEdge.getPropertyList()) {
        propertyMapperList.add(GraphPropertyMapper.parseFromGrapyProperty(graphProperty));
    }
    edgeTypeMapper.setPropertyDefList(propertyMapperList);
    return edgeTypeMapper;
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) EdgeRelation(com.alibaba.maxgraph.compiler.api.schema.EdgeRelation)

Aggregations

GraphProperty (com.alibaba.maxgraph.compiler.api.schema.GraphProperty)11 EdgeRelation (com.alibaba.maxgraph.compiler.api.schema.EdgeRelation)3 GraphVertex (com.alibaba.maxgraph.compiler.api.schema.GraphVertex)3 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)2 PrimaryKeyConstraint (com.alibaba.maxgraph.compiler.api.schema.PrimaryKeyConstraint)2 PropertyValue (com.alibaba.maxgraph.sdkcommon.schema.PropertyValue)2 HashMap (java.util.HashMap)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 PropertyDefNotFoundException (com.alibaba.maxgraph.compiler.api.exception.PropertyDefNotFoundException)1 DataType (com.alibaba.maxgraph.compiler.api.schema.DataType)1 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 LogicalSourceVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex)1 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)1 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)1 ProcessorSourceFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)1 TreeNodeLabelManager (com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager)1 MaxGraphException (com.alibaba.maxgraph.sdkcommon.exception.MaxGraphException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1