func()

in vermeer/apps/structure/property.go [196:304]


func (ps *PropertySchema) initFromHugegraphEdge(hgSchema map[string]any, useProperty bool, edgePropIDs []string) error {
	if !useProperty {
		return nil
	}
	ps.HgPSchema = &HugegraphPSchema{}
	edgePropIDMap := make(map[int]struct{})
	useEdgePropFilter := len(edgePropIDs) > 0
	if useEdgePropFilter {
		useEdgePropFilter = false
		for _, propID := range edgePropIDs {
			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 {
				useEdgePropFilter = true
			}
			edgePropIDMap[int(iLabel)] = struct{}{}
		}
	}
	edgeLabels, ok := hgSchema["edgelabels"].([]any)
	if !ok {
		return fmt.Errorf("get edgelabels from hugegraph not correct %v", hgSchema["edgelabels"])
	}
	ps.HgPSchema.Labels = make(map[int]string)
	properties := make(map[string]struct{})
	for _, eLabelAny := range edgeLabels {
		eLabel, ok := eLabelAny.(map[string]any)
		if !ok {
			return fmt.Errorf("get edge label not correct %v", eLabelAny)
		}
		id, ok := eLabel["id"].(float64)
		if !ok {
			return fmt.Errorf("get edge label id not correct %v", eLabel["id"])
		}
		name, ok := eLabel["name"].(string)
		if !ok {
			return fmt.Errorf("get edge label name not correct %v", eLabel["id"])
		}
		edgeLabelType, ok := eLabel["edgelabel_type"].(string)
		if !ok {
			return fmt.Errorf("get edgelabel_type not correct %v", eLabel["edgelabel_type"])
		}
		if edgeLabelType == "PARENT" {
			continue
		}
		ps.HgPSchema.Labels[int(id)] = name
		labelProperties, ok := eLabel["properties"].([]any)
		if !ok {
			return fmt.Errorf("get edge label properties not correct %v", eLabel["properties"])
		}
		for _, labelProperty := range labelProperties {
			propString, ok := labelProperty.(string)
			if !ok {
				return fmt.Errorf("get edge label property not correct %v", labelProperty)
			}
			properties[propString] = struct{}{}
		}
	}
	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 := edgePropIDMap[int(propID)]; useEdgePropFilter && !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
}