in maven-projects/spark/graphar/src/main/scala/org/apache/graphar/util/Utils.scala [76:172]
def generateGraphInfo(
path: String,
graphName: String,
directed: Boolean,
vertexChunkSize: Long,
edgeChunkSize: Long,
fileType: String,
version: String,
vertexSchemas: scala.collection.mutable.Map[String, StructType],
edgeSchemas: scala.collection.mutable.Map[
(String, String, String),
StructType
],
primaryKeys: scala.collection.mutable.Map[String, String]
): GraphInfo = {
val info = new GraphInfo()
info.setName(graphName)
info.setPrefix(path + "/")
info.setVersion("gar/" + version)
vertexSchemas.foreach {
case (key, schema) => {
val vertexInfo = new VertexInfo()
val prefix = "vertex/" + key + "/"
vertexInfo.setPrefix(prefix)
vertexInfo.setType(key)
vertexInfo.setChunk_size(vertexChunkSize)
vertexInfo.setVersion("gar/" + version)
vertexInfo.getProperty_groups().add(new PropertyGroup())
val propertyGroup = vertexInfo.getProperty_groups().get(0)
propertyGroup.setFile_type(fileType)
val properties = propertyGroup.getProperties()
schema.foreach {
case field => {
val property = new Property()
property.setName(field.name)
property.setData_type(sparkDataType2GraphArTypeName(field.dataType))
val isPrimary: Boolean =
if (
(primaryKeys(key) == "" && properties
.size() == 0) || field.name.equals(primaryKeys(key))
) true
else false
property.setIs_primary(isPrimary)
properties.add(property)
}
}
info.addVertexInfo(vertexInfo)
info.vertices.add(key + ".vertex.yml")
}
}
edgeSchemas.foreach {
case (key, schema) => {
val edgeInfo = new EdgeInfo()
edgeInfo.setSrc_type(key._1)
edgeInfo.setEdge_type(key._2)
edgeInfo.setDst_type(key._3)
edgeInfo.setChunk_size(edgeChunkSize)
edgeInfo.setSrc_chunk_size(vertexChunkSize)
edgeInfo.setDst_chunk_size(vertexChunkSize)
edgeInfo.setDirected(directed)
val prefix = "edge/" + edgeInfo.getConcatKey() + "/"
edgeInfo.setVersion("gar/" + version)
edgeInfo.setPrefix(prefix)
val csrAdjList = new AdjList()
csrAdjList.setOrdered(true)
csrAdjList.setAligned_by("src")
csrAdjList.setFile_type(fileType)
val cscAdjList = new AdjList()
cscAdjList.setOrdered(true)
cscAdjList.setAligned_by("dst")
cscAdjList.setFile_type(fileType)
edgeInfo.getAdj_lists().add(csrAdjList)
edgeInfo.getAdj_lists().add(cscAdjList)
if (schema.length > 0) {
edgeInfo.getProperty_groups().add(new PropertyGroup())
val propertyGroup = edgeInfo.getProperty_groups().get(0)
propertyGroup.setFile_type(fileType)
val properties = propertyGroup.getProperties()
schema.foreach {
case field => {
val property = new Property()
property.setName(field.name)
property.setData_type(
sparkDataType2GraphArTypeName(field.dataType)
)
properties.add(property)
}
}
}
info.addEdgeInfo(edgeInfo)
info.edges.add(edgeInfo.getConcatKey() + ".edge.yml")
}
}
return info
}