in arrow/compute/exprs/types.go [703:803]
func FromSubstraitType(t types.Type, ext ExtensionIDSet) (arrow.DataType, bool, error) {
nullable := IsNullable(t)
if t.GetTypeVariationReference() > 0 {
_, dt, ok := ext.DecodeTypeArrow(t.GetTypeVariationReference())
if ok {
return dt, nullable, nil
}
}
switch t := t.(type) {
case *types.BooleanType:
return arrow.FixedWidthTypes.Boolean, nullable, nil
case *types.Int8Type:
return arrow.PrimitiveTypes.Int8, nullable, nil
case *types.Int16Type:
return arrow.PrimitiveTypes.Int16, nullable, nil
case *types.Int32Type:
return arrow.PrimitiveTypes.Int32, nullable, nil
case *types.Int64Type:
return arrow.PrimitiveTypes.Int64, nullable, nil
case *types.Float32Type:
return arrow.PrimitiveTypes.Float32, nullable, nil
case *types.Float64Type:
return arrow.PrimitiveTypes.Float64, nullable, nil
case *types.StringType:
return arrow.BinaryTypes.String, nullable, nil
case *types.BinaryType:
return arrow.BinaryTypes.Binary, nullable, nil
case *types.TimestampType:
return &arrow.TimestampType{Unit: arrow.Microsecond}, nullable, nil
case *types.TimestampTzType:
return &arrow.TimestampType{Unit: arrow.Microsecond, TimeZone: TimestampTzTimezone},
nullable, nil
case *types.DateType:
return arrow.FixedWidthTypes.Date32, nullable, nil
case *types.TimeType:
return &arrow.Time64Type{Unit: arrow.Microsecond}, nullable, nil
case *types.IntervalYearType:
return intervalYear(), nullable, nil
case *types.IntervalDayType:
return intervalDay(), nullable, nil
case *types.UUIDType:
return uuid(), nullable, nil
case *types.FixedCharType:
return fixedChar(t.Length), nullable, nil
case *types.VarCharType:
return varChar(t.Length), nullable, nil
case *types.FixedBinaryType:
return &arrow.FixedSizeBinaryType{ByteWidth: int(t.Length)}, nullable, nil
case *types.DecimalType:
return &arrow.Decimal128Type{
Precision: t.Precision,
Scale: t.Scale,
}, nullable, nil
case *types.StructType:
i := 0
fields, err := FieldsFromSubstrait(t.Types, func() string {
i++
return strconv.Itoa(i)
}, ext)
if err != nil {
return nil, false, err
}
return arrow.StructOf(fields...), nullable, nil
case *types.ListType:
elem, elemNullable, err := FromSubstraitType(t.Type, ext)
if err != nil {
return nil, false, err
}
return arrow.ListOfField(arrow.Field{Name: "item", Type: elem, Nullable: elemNullable}),
nullable, nil
case *types.MapType:
key, keyNullable, err := FromSubstraitType(t.Key, ext)
if err != nil {
return nil, false, err
}
if keyNullable {
return nil, false, fmt.Errorf("%w: encountered nullable key field when converting to arrow.Map",
arrow.ErrInvalid)
}
value, valueNullable, err := FromSubstraitType(t.Value, ext)
if err != nil {
return nil, false, err
}
ret := arrow.MapOf(key, value)
ret.SetItemNullable(valueNullable)
return ret, nullable, nil
case *types.UserDefinedType:
anchor := t.TypeReference
_, dt, ok := ext.DecodeTypeArrow(anchor)
if !ok {
return nil, false, arrow.ErrNotImplemented
}
return dt, nullable, nil
}
return nil, false, arrow.ErrNotImplemented
}