in vermeer/apps/structure/property.go [86:194]
func (ps *PropertySchema) initFromHugegraphVertex(hgSchema map[string]any, useProperty bool, vertexPropIDs []string) error {
//从hugegraph中读取schema
//edge和vertex的label和property不相同,需要分开读取。
ps.HgPSchema = &HugegraphPSchema{}
vertexPropIDMap := make(map[int]struct{})
useVertexPropFilter := len(vertexPropIDs) > 0
if useVertexPropFilter {
useVertexPropFilter = false
for _, propID := range vertexPropIDs {
if propID == "" {
continue
}
iLabel, err := strconv.ParseInt(strings.TrimSpace(propID), 10, 64)
if err != nil {
logrus.Errorf("property schema label type not int :%v", propID)
continue
} else {
useVertexPropFilter = true
}
vertexPropIDMap[int(iLabel)] = struct{}{}
}
}
vertexLabels, ok := hgSchema["vertexlabels"].([]any)
if !ok {
return fmt.Errorf("get vertexlabels from hugegraph not correct %v", hgSchema["vertexlabels"])
}
ps.HgPSchema.Labels = make(map[int]string)
properties := make(map[string]struct{})
for _, vLabelAny := range vertexLabels {
vLabel, ok := vLabelAny.(map[string]any)
if !ok {
return fmt.Errorf("get vertex label not correct %v", vLabelAny)
}
id, ok := vLabel["id"].(float64)
if !ok {
return fmt.Errorf("get vertex label id not correct %v", vLabel["id"])
}
name, ok := vLabel["name"].(string)
if !ok {
return fmt.Errorf("get vertex label name not correct %v", vLabel["id"])
}
ps.HgPSchema.Labels[int(id)] = name
labelProperties, ok := vLabel["properties"].([]any)
if !ok {
return fmt.Errorf("get vertex label properties not correct %v", vLabel["properties"])
}
for _, labelProperty := range labelProperties {
propString, ok := labelProperty.(string)
if !ok {
return fmt.Errorf("get vertex label property not correct %v", labelProperty)
}
properties[propString] = struct{}{}
}
}
if !useProperty {
ps.Schema = make([]*PSchema, 1)
ps.Schema[0] = &PSchema{
VType: ValueTypeString,
PropKey: "label",
}
} else {
propKeys, ok := hgSchema["propertykeys"].([]any)
if !ok {
return fmt.Errorf("get propertykeys from hugegraph not correct %v", hgSchema["propertykeys"])
}
ps.Schema = make([]*PSchema, 1, len(properties)+1)
ps.Schema[0] = &PSchema{
VType: ValueTypeString,
PropKey: "label",
}
ps.HgPSchema.PropIndex = make(map[int]int, len(properties))
idx := 1
for _, propKeyAny := range propKeys {
propKey, ok := propKeyAny.(map[string]any)
if !ok {
return fmt.Errorf("get property key not correct %v", propKeyAny)
}
propKeyName, ok := propKey["name"].(string)
if !ok {
return fmt.Errorf("get property name not correct %v", propKey["name"])
}
if _, ok := properties[propKeyName]; !ok {
continue
}
propID, ok := propKey["id"].(float64)
if !ok {
return fmt.Errorf("get property id not correct %v", propKey["id"])
}
if _, ok := vertexPropIDMap[int(propID)]; useVertexPropFilter && !ok {
continue
}
ps.Schema = append(ps.Schema, &PSchema{})
ps.Schema[idx].PropKey = propKeyName
switch propKey["data_type"].(string) {
case "INT", "LONG":
ps.Schema[idx].VType = ValueTypeInt32
case "FLOAT", "DOUBLE":
ps.Schema[idx].VType = ValueTypeFloat32
case "STRING", "BYTE", "DATE", "BOOL", "TEXT", "BOOLEAN":
ps.Schema[idx].VType = ValueTypeString
default:
logrus.Errorf("hugegraph data_type:%v not match", propKey["data_type"].(string))
}
ps.HgPSchema.PropIndex[int(propID)] = idx
idx++
}
}
return nil
}