in arrow/internal/arrjson/arrjson.go [125:245]
func typeToJSON(arrowType arrow.DataType) (json.RawMessage, error) {
var typ interface{}
switch dt := arrowType.(type) {
case *arrow.NullType:
typ = nameJSON{"null"}
case *arrow.BooleanType:
typ = nameJSON{"bool"}
case *arrow.Int8Type:
typ = bitWidthJSON{Name: "int", Signed: true, BitWidth: 8}
case *arrow.Int16Type:
typ = bitWidthJSON{Name: "int", Signed: true, BitWidth: 16}
case *arrow.Int32Type:
typ = bitWidthJSON{Name: "int", Signed: true, BitWidth: 32}
case *arrow.Int64Type:
typ = bitWidthJSON{Name: "int", Signed: true, BitWidth: 64}
case *arrow.Uint8Type:
typ = bitWidthJSON{Name: "int", Signed: false, BitWidth: 8}
case *arrow.Uint16Type:
typ = bitWidthJSON{Name: "int", Signed: false, BitWidth: 16}
case *arrow.Uint32Type:
typ = bitWidthJSON{Name: "int", Signed: false, BitWidth: 32}
case *arrow.Uint64Type:
typ = bitWidthJSON{Name: "int", Signed: false, BitWidth: 64}
case *arrow.Float16Type:
typ = floatJSON{"floatingpoint", "HALF"}
case *arrow.Float32Type:
typ = floatJSON{"floatingpoint", "SINGLE"}
case *arrow.Float64Type:
typ = floatJSON{"floatingpoint", "DOUBLE"}
case *arrow.BinaryType:
typ = nameJSON{"binary"}
case *arrow.LargeBinaryType:
typ = nameJSON{"largebinary"}
case *arrow.StringType:
typ = nameJSON{"utf8"}
case *arrow.LargeStringType:
typ = nameJSON{"largeutf8"}
case *arrow.BinaryViewType:
typ = nameJSON{"binaryview"}
case *arrow.StringViewType:
typ = nameJSON{"utf8view"}
case *arrow.Date32Type:
typ = unitZoneJSON{Name: "date", Unit: "DAY"}
case *arrow.Date64Type:
typ = unitZoneJSON{Name: "date", Unit: "MILLISECOND"}
case *arrow.MonthIntervalType:
typ = unitZoneJSON{Name: "interval", Unit: "YEAR_MONTH"}
case *arrow.DayTimeIntervalType:
typ = unitZoneJSON{Name: "interval", Unit: "DAY_TIME"}
case *arrow.MonthDayNanoIntervalType:
typ = unitZoneJSON{Name: "interval", Unit: "MONTH_DAY_NANO"}
case *arrow.DurationType:
switch dt.Unit {
case arrow.Second:
typ = unitZoneJSON{Name: "duration", Unit: "SECOND"}
case arrow.Millisecond:
typ = unitZoneJSON{Name: "duration", Unit: "MILLISECOND"}
case arrow.Microsecond:
typ = unitZoneJSON{Name: "duration", Unit: "MICROSECOND"}
case arrow.Nanosecond:
typ = unitZoneJSON{Name: "duration", Unit: "NANOSECOND"}
}
case *arrow.Time32Type:
switch dt.Unit {
case arrow.Second:
typ = bitWidthJSON{Name: "time", BitWidth: dt.BitWidth(), Unit: "SECOND"}
case arrow.Millisecond:
typ = bitWidthJSON{Name: "time", BitWidth: dt.BitWidth(), Unit: "MILLISECOND"}
}
case *arrow.Time64Type:
switch dt.Unit {
case arrow.Microsecond:
typ = bitWidthJSON{Name: "time", BitWidth: dt.BitWidth(), Unit: "MICROSECOND"}
case arrow.Nanosecond:
typ = bitWidthJSON{Name: "time", BitWidth: dt.BitWidth(), Unit: "NANOSECOND"}
}
case *arrow.TimestampType:
switch dt.Unit {
case arrow.Second:
typ = unitZoneJSON{Name: "timestamp", Unit: "SECOND", TimeZone: dt.TimeZone}
case arrow.Millisecond:
typ = unitZoneJSON{Name: "timestamp", Unit: "MILLISECOND", TimeZone: dt.TimeZone}
case arrow.Microsecond:
typ = unitZoneJSON{Name: "timestamp", Unit: "MICROSECOND", TimeZone: dt.TimeZone}
case arrow.Nanosecond:
typ = unitZoneJSON{Name: "timestamp", Unit: "NANOSECOND", TimeZone: dt.TimeZone}
}
case *arrow.ListType:
typ = nameJSON{"list"}
case *arrow.LargeListType:
typ = nameJSON{"largelist"}
case *arrow.ListViewType:
typ = nameJSON{"listview"}
case *arrow.LargeListViewType:
typ = nameJSON{"largelistview"}
case *arrow.MapType:
typ = mapJSON{Name: "map", KeysSorted: dt.KeysSorted}
case *arrow.StructType:
typ = nameJSON{"struct"}
case *arrow.FixedSizeListType:
typ = listSizeJSON{"fixedsizelist", dt.Len()}
case *arrow.FixedSizeBinaryType:
typ = byteWidthJSON{"fixedsizebinary", dt.ByteWidth}
case *arrow.Decimal32Type:
typ = decimalJSON{"decimal", int(dt.Scale), int(dt.Precision), 32}
case *arrow.Decimal64Type:
typ = decimalJSON{"decimal", int(dt.Scale), int(dt.Precision), 64}
case *arrow.Decimal128Type:
typ = decimalJSON{"decimal", int(dt.Scale), int(dt.Precision), 128}
case *arrow.Decimal256Type:
typ = decimalJSON{"decimal", int(dt.Scale), int(dt.Precision), 256}
case arrow.UnionType:
typ = unionJSON{"union", dt.Mode().String(), dt.TypeCodes()}
case *arrow.RunEndEncodedType:
typ = nameJSON{"runendencoded"}
default:
return nil, fmt.Errorf("unknown arrow.DataType %v", arrowType)
}
return json.Marshal(typ)
}