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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations