func (op *Uint64MergeOperator) PartialMerge(key, leftOperand, rightOperand []byte) ([]byte, bool) { keyStr := string(key) mergeType := getKeyMergeType(keyStr) var mergeFunc func(o1, o2 uint64) uint64 switch strings.ToLower(mergeType) { case "add": mergeFunc = uint64Add case "max": mergeFunc = uint64Max case "min": mergeFunc = uint64Min default: log.Warnf("unkown merge type: %v, key: %v\n", mergeType, string(key)) return nil, false } var ret []byte o1, err := BytesToUint64(leftOperand) if err != nil { return ret, false } o2, err := BytesToUint64(rightOperand) if err != nil { return ret, false } newVal := mergeFunc(o1, o2) return Uint64ToBytes(newVal), true }
func (op *Uint64MergeOperator) FullMerge(key, existingValue []byte, operands [][]byte) ([]byte, bool) { keyStr := string(key) mergeType := getKeyMergeType(keyStr) var mergeFunc func(o1, o2 uint64) uint64 switch strings.ToLower(mergeType) { case "add": mergeFunc = uint64Add case "max": mergeFunc = uint64Max case "min": mergeFunc = uint64Min default: log.Warnf("unkown merge type: %v, key: %v\n", mergeType, string(key)) return nil, false } var ret []byte val, err := BytesToUint64(existingValue) if err != nil { log.WarnErrorf(err, "existing value corruption. %v", existingValue) val = 0 // return ret, false } for _, bytes := range operands { tmp, err := BytesToUint64(bytes) if err != nil { return ret, false } val = mergeFunc(val, tmp) } ret = Uint64ToBytes(val) return ret, true }