| 16 | ) |
| 17 | |
| 18 | func (c *Client) reverseTransform(f arrow.Field, bldr array.Builder, val any) error { |
| 19 | if val == nil { |
| 20 | bldr.AppendNull() |
| 21 | return nil |
| 22 | } |
| 23 | switch b := bldr.(type) { |
| 24 | case *array.BooleanBuilder: |
| 25 | b.Append(val.(bool)) |
| 26 | case *array.Int8Builder: |
| 27 | b.Append(int8(val.(int32))) |
| 28 | case *array.Int16Builder: |
| 29 | b.Append(int16(val.(int32))) |
| 30 | case *array.Int32Builder: |
| 31 | b.Append(val.(int32)) |
| 32 | case *array.Int64Builder: |
| 33 | b.Append(val.(int64)) |
| 34 | case *array.Uint8Builder: |
| 35 | b.Append(uint8(val.(int32))) |
| 36 | case *array.Uint16Builder: |
| 37 | b.Append(uint16(val.(int32))) |
| 38 | case *array.Uint32Builder: |
| 39 | b.Append(uint32(val.(int64))) |
| 40 | case *array.Uint64Builder: |
| 41 | b.Append(uint64(val.(int64))) |
| 42 | case *array.Float32Builder: |
| 43 | b.Append(float32(val.(float64))) |
| 44 | case *array.Float64Builder: |
| 45 | b.Append(val.(float64)) |
| 46 | case *array.StringBuilder: |
| 47 | b.Append(val.(string)) |
| 48 | case *array.LargeStringBuilder: |
| 49 | b.Append(val.(string)) |
| 50 | case *array.BinaryBuilder: |
| 51 | b.Append(val.(bson.Binary).Data) |
| 52 | case *array.TimestampBuilder: |
| 53 | switch b.Type().(*arrow.TimestampType).Unit { |
| 54 | case arrow.Second: |
| 55 | b.Append(arrow.Timestamp((val).(bson.DateTime).Time().UTC().Unix())) |
| 56 | case arrow.Millisecond: |
| 57 | b.Append(arrow.Timestamp((val).(bson.DateTime).Time().UTC().UnixMilli())) |
| 58 | case arrow.Microsecond: |
| 59 | b.Append(arrow.Timestamp((val).(bson.DateTime).Time().UTC().UnixMicro())) |
| 60 | case arrow.Nanosecond: |
| 61 | b.Append(arrow.Timestamp((val).(bson.DateTime).Time().UTC().UnixNano())) |
| 62 | default: |
| 63 | return fmt.Errorf("unsupported timestamp unit %s", f.Type.(*arrow.TimestampType).Unit) |
| 64 | } |
| 65 | case *types.JSONBuilder: |
| 66 | b.Append(val) |
| 67 | case *array.StructBuilder: |
| 68 | m := bsonDocToMap(val) |
| 69 | v, err := json.Marshal(m) |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | dec := json.NewDecoder(bytes.NewReader(v)) |
| 74 | if err := b.UnmarshalOne(dec); err != nil { |
| 75 | return err |