Open fly512 opened 4 years ago
go我也不太熟悉,我在研究一下,这几天推一个可以work的版本
看了下代码,即使解出来,如何遍历 AfterImages?
把 avro 库 method.go compileRef 方法里的第一个 return fmt.Errorf 去掉 也能运行成功
看了下代码,即使解出来,如何遍历 AfterImages?
用了一个最笨的办法
func (o *ALiYunDtsRecord) GetAfterImagesFields() (v []ALiYunDtsField, err error) {
afterImagesArr := o.DtsAvroRecord.AfterImages.ArrayUnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject
return o.GetImagesFieldsRaw(afterImagesArr)
}
func (o ALiYunDtsRecord) GetImagesFieldsRaw(dtsImagesArray []dtsavro.UnionNullIntegerCharacterDecimalFloatTimestampDateTimeTimestampWithTimeZoneBinaryGeometryTextGeometryBinaryObjectTextObjectEmptyObject) (v []ALiYunDtsField, err error) { l := len(o.DtsAvroRecord.Fields.ArrayField) v = make([]ALiYunDtsField, 0, l) for k, field := range o.DtsAvroRecord.Fields.ArrayField { o := &ALiYunDtsUnionObj{ DtsUnionNullObj: dtsImagesArray[k], } fieldValue, rowErr := o.GetValue() if rowErr != nil { err = rowErr } rv := ALiYunDtsField { Name: field.Name, Value: fieldValue, Err: err, } v = append(v, rv) } return }
func (o *ALiYunDtsRecord) ImagesFieldsToMap(s []ALiYunDtsField) (v map[string]interface{}, hasError bool, err error) { v = make(map[string]interface{}) for _, field := range s { v[field.Name] = field.Value if !hasError && field.Err != nil { hasError = true } } return }
```go
func GetStringValue(v interface{}) (string, bool) {
switch rv := v.(type) {
case *string:
return *rv, true
case string:
return rv, true
case int, int8, int16, int32, int64:
return fmt.Sprintf("%d", rv), true
case uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%d", rv), true
case float32, float64:
return fmt.Sprintf("%f", rv), true
case complex64, complex128:
return fmt.Sprintf("%f", rv), true
case bool:
if rv {
return "1", true
}
return "0", true
}
return "", false
}
如题,启动就报错,貌似 record.avsc 有问题
: Incompatible types by name: &{com.alibaba.dts.formats.avro.Integer 0xc000148bd0} &{com.alibaba.dts.formats.avro.Decimal 0xc000149490}