-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
大佬能提供一个获取afterImages中value的示例吗? #2
Comments
你运行的起来? @Morriaty-The-Murderer |
可以把你的代码贴出来,看看? |
@gua-pian 大致如下 fields := record.Fields.ArrayField
afterImages := record.AfterImages.ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject
esDoc := make(map[string]interface{})
var docID string
for idx, esField := range fields {
r := afterImages[idx]
if r == nil {
continue
}
switch int(r.UnionType) {
case 1:
esDoc[esField] = r.Integer.Value
case 2:
esDoc[esField] = string(r.Character.Value)
case 3:
esDoc[esField] = r.Decimal.Value
case 4:
esDoc[esField] = r.Float.Value
case 5:
esDoc[esField] = r.Timestamp.Timestamp
default:
log.Infof("field <%s> after image <%+v> is ignored", fieldName, r)
}
if fieldName == "id" {
docID = afterImages[idx].Integer.Value
}
} |
@Morriaty-The-Murderer 这个看上去没法很好的实现。或者可以参考 go-martini,做一个 map[reflect.Type] = reflect.Value 这样的 map 结构,辅助查询。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go gen avro 生成的 Union struct 好恶心啊,我目前只能使用switch case的方式获取
The text was updated successfully, but these errors were encountered: