in js/src/visitor.ts [136:221]
function inferDType<T extends DataType>(type: T): Type {
switch (type.typeId) {
case Type.Null: return Type.Null;
case Type.Int: {
const { bitWidth, isSigned } = (type as any as Int);
switch (bitWidth) {
case 8: return isSigned ? Type.Int8 : Type.Uint8;
case 16: return isSigned ? Type.Int16 : Type.Uint16;
case 32: return isSigned ? Type.Int32 : Type.Uint32;
case 64: return isSigned ? Type.Int64 : Type.Uint64;
}
// @ts-ignore
return Type.Int;
}
case Type.Float:
switch ((type as any as Float).precision) {
case Precision.HALF: return Type.Float16;
case Precision.SINGLE: return Type.Float32;
case Precision.DOUBLE: return Type.Float64;
}
// @ts-ignore
return Type.Float;
case Type.Binary: return Type.Binary;
case Type.LargeBinary: return Type.LargeBinary;
case Type.Utf8: return Type.Utf8;
case Type.LargeUtf8: return Type.LargeUtf8;
case Type.Bool: return Type.Bool;
case Type.Decimal: return Type.Decimal;
case Type.Time:
switch ((type as any as Time).unit) {
case TimeUnit.SECOND: return Type.TimeSecond;
case TimeUnit.MILLISECOND: return Type.TimeMillisecond;
case TimeUnit.MICROSECOND: return Type.TimeMicrosecond;
case TimeUnit.NANOSECOND: return Type.TimeNanosecond;
}
// @ts-ignore
return Type.Time;
case Type.Timestamp:
switch ((type as any as Timestamp).unit) {
case TimeUnit.SECOND: return Type.TimestampSecond;
case TimeUnit.MILLISECOND: return Type.TimestampMillisecond;
case TimeUnit.MICROSECOND: return Type.TimestampMicrosecond;
case TimeUnit.NANOSECOND: return Type.TimestampNanosecond;
}
// @ts-ignore
return Type.Timestamp;
case Type.Date:
switch ((type as any as Date_).unit) {
case DateUnit.DAY: return Type.DateDay;
case DateUnit.MILLISECOND: return Type.DateMillisecond;
}
// @ts-ignore
return Type.Date;
case Type.Interval:
switch ((type as any as Interval).unit) {
case IntervalUnit.DAY_TIME: return Type.IntervalDayTime;
case IntervalUnit.YEAR_MONTH: return Type.IntervalYearMonth;
case IntervalUnit.MONTH_DAY_NANO: return Type.IntervalMonthDayNano;
}
// @ts-ignore
return Type.Interval;
case Type.Duration:
switch ((type as any as Duration).unit) {
case TimeUnit.SECOND: return Type.DurationSecond;
case TimeUnit.MILLISECOND: return Type.DurationMillisecond;
case TimeUnit.MICROSECOND: return Type.DurationMicrosecond;
case TimeUnit.NANOSECOND: return Type.DurationNanosecond;
}
// @ts-ignore
return Type.Duration;
case Type.Map: return Type.Map;
case Type.List: return Type.List;
case Type.Struct: return Type.Struct;
case Type.Union:
switch ((type as any as Union).mode) {
case UnionMode.Dense: return Type.DenseUnion;
case UnionMode.Sparse: return Type.SparseUnion;
}
// @ts-ignore
return Type.Union;
case Type.FixedSizeBinary: return Type.FixedSizeBinary;
case Type.FixedSizeList: return Type.FixedSizeList;
case Type.Dictionary: return Type.Dictionary;
}
throw new Error(`Unrecognized type '${Type[type.typeId]}'`);
}