in csharp/src/Apache.Arrow/C/CArrowSchemaExporter.cs [144:219]
private static string GetFormat(IArrowType datatype)
{
switch (datatype)
{
case NullType _: return "n";
case BooleanType _: return "b";
// Integers
case Int8Type _: return "c";
case UInt8Type _: return "C";
case Int16Type _: return "s";
case UInt16Type _: return "S";
case Int32Type _: return "i";
case UInt32Type _: return "I";
case Int64Type _: return "l";
case UInt64Type _: return "L";
// Floats
case HalfFloatType _: return "e";
case FloatType _: return "f";
case DoubleType _: return "g";
// Decimal
case Decimal32Type decimalType:
return $"d:{decimalType.Precision},{decimalType.Scale},32";
case Decimal64Type decimalType:
return $"d:{decimalType.Precision},{decimalType.Scale},64";
case Decimal128Type decimalType:
return $"d:{decimalType.Precision},{decimalType.Scale}";
case Decimal256Type decimalType:
return $"d:{decimalType.Precision},{decimalType.Scale},256";
// Binary
case BinaryType _: return "z";
case BinaryViewType _: return "vz";
case LargeBinaryType _: return "Z";
case StringType _: return "u";
case StringViewType _: return "vu";
case LargeStringType _: return "U";
case FixedSizeBinaryType binaryType:
return $"w:{binaryType.ByteWidth}";
// Date
case Date32Type _: return "tdD";
case Date64Type _: return "tdm";
// Time
case Time32Type timeType:
return String.Format("tt{0}", FormatTimeUnit(timeType.Unit));
case Time64Type timeType:
// Same prefix as Time32, but allowed time units are different.
return String.Format("tt{0}", FormatTimeUnit(timeType.Unit));
// Duration
case DurationType durationType:
return String.Format("tD{0}", FormatTimeUnit(durationType.Unit));
// Timestamp
case TimestampType timestampType:
return String.Format("ts{0}:{1}", FormatTimeUnit(timestampType.Unit), timestampType.Timezone);
// Interval
case IntervalType intervalType:
return intervalType.Unit switch
{
IntervalUnit.YearMonth => "tiM",
IntervalUnit.DayTime => "tiD",
IntervalUnit.MonthDayNanosecond => "tin",
_ => throw new InvalidDataException($"Unsupported interval unit for export: {intervalType.Unit}"),
};
// Nested
case ListType _: return "+l";
case ListViewType _: return "+vl";
case LargeListType _: return "+L";
case FixedSizeListType fixedListType:
return $"+w:{fixedListType.ListSize}";
case StructType _: return "+s";
case UnionType u: return FormatUnion(u);
case MapType _: return "+m";
// Dictionary
case DictionaryType dictionaryType:
return GetFormat(dictionaryType.IndexType);
default: throw new NotImplementedException($"Exporting {datatype.Name} not implemented");
}
}