in c/src/main/java/org/apache/arrow/c/Format.java [38:244]
static String asString(ArrowType arrowType) {
if (arrowType instanceof ExtensionType) {
ArrowType innerType = ((ExtensionType) arrowType).storageType();
return asString(innerType);
}
switch (arrowType.getTypeID()) {
case Binary:
return "z";
case Bool:
return "b";
case Date:
{
ArrowType.Date type = (ArrowType.Date) arrowType;
switch (type.getUnit()) {
case DAY:
return "tdD";
case MILLISECOND:
return "tdm";
default:
throw new UnsupportedOperationException(
String.format("Date type with unit %s is unsupported", type.getUnit()));
}
}
case Decimal:
{
ArrowType.Decimal type = (ArrowType.Decimal) arrowType;
if (type.getBitWidth() == 128) {
return String.format("d:%d,%d", type.getPrecision(), type.getScale());
}
return String.format(
"d:%d,%d,%d", type.getPrecision(), type.getScale(), type.getBitWidth());
}
case Duration:
{
ArrowType.Duration type = (ArrowType.Duration) arrowType;
switch (type.getUnit()) {
case SECOND:
return "tDs";
case MILLISECOND:
return "tDm";
case MICROSECOND:
return "tDu";
case NANOSECOND:
return "tDn";
default:
throw new UnsupportedOperationException(
String.format("Duration type with unit %s is unsupported", type.getUnit()));
}
}
case FixedSizeBinary:
{
ArrowType.FixedSizeBinary type = (ArrowType.FixedSizeBinary) arrowType;
return String.format("w:%d", type.getByteWidth());
}
case FixedSizeList:
{
ArrowType.FixedSizeList type = (ArrowType.FixedSizeList) arrowType;
return String.format("+w:%d", type.getListSize());
}
case FloatingPoint:
{
ArrowType.FloatingPoint type = (ArrowType.FloatingPoint) arrowType;
switch (type.getPrecision()) {
case HALF:
return "e";
case SINGLE:
return "f";
case DOUBLE:
return "g";
default:
throw new UnsupportedOperationException(
String.format(
"FloatingPoint type with precision %s is unsupported", type.getPrecision()));
}
}
case Int:
{
String format;
ArrowType.Int type = (ArrowType.Int) arrowType;
switch (type.getBitWidth()) {
case Byte.SIZE:
format = "C";
break;
case Short.SIZE:
format = "S";
break;
case Integer.SIZE:
format = "I";
break;
case Long.SIZE:
format = "L";
break;
default:
throw new UnsupportedOperationException(
String.format("Int type with bitwidth %d is unsupported", type.getBitWidth()));
}
if (type.getIsSigned()) {
format = format.toLowerCase(Locale.ROOT);
}
return format;
}
case Interval:
{
ArrowType.Interval type = (ArrowType.Interval) arrowType;
switch (type.getUnit()) {
case DAY_TIME:
return "tiD";
case YEAR_MONTH:
return "tiM";
case MONTH_DAY_NANO:
return "tin";
default:
throw new UnsupportedOperationException(
String.format("Interval type with unit %s is unsupported", type.getUnit()));
}
}
case LargeBinary:
return "Z";
case LargeList:
return "+L";
case LargeUtf8:
return "U";
case List:
return "+l";
case Map:
return "+m";
case Null:
return "n";
case Struct:
return "+s";
case Time:
{
ArrowType.Time type = (ArrowType.Time) arrowType;
if (type.getUnit() == TimeUnit.SECOND && type.getBitWidth() == 32) {
return "tts";
} else if (type.getUnit() == TimeUnit.MILLISECOND && type.getBitWidth() == 32) {
return "ttm";
} else if (type.getUnit() == TimeUnit.MICROSECOND && type.getBitWidth() == 64) {
return "ttu";
} else if (type.getUnit() == TimeUnit.NANOSECOND && type.getBitWidth() == 64) {
return "ttn";
} else {
throw new UnsupportedOperationException(
String.format(
"Time type with unit %s and bitwidth %d is unsupported",
type.getUnit(), type.getBitWidth()));
}
}
case Timestamp:
{
String format;
ArrowType.Timestamp type = (ArrowType.Timestamp) arrowType;
switch (type.getUnit()) {
case SECOND:
format = "tss";
break;
case MILLISECOND:
format = "tsm";
break;
case MICROSECOND:
format = "tsu";
break;
case NANOSECOND:
format = "tsn";
break;
default:
throw new UnsupportedOperationException(
String.format("Timestamp type with unit %s is unsupported", type.getUnit()));
}
String timezone = type.getTimezone();
return String.format("%s:%s", format, timezone == null ? "" : timezone);
}
case Union:
ArrowType.Union type = (ArrowType.Union) arrowType;
String typeIDs =
Arrays.stream(type.getTypeIds())
.mapToObj(String::valueOf)
.collect(Collectors.joining(","));
switch (type.getMode()) {
case Dense:
return String.format("+ud:%s", typeIDs);
case Sparse:
return String.format("+us:%s", typeIDs);
default:
throw new UnsupportedOperationException(
String.format("Union type with mode %s is unsupported", type.getMode()));
}
case Utf8:
return "u";
case Utf8View:
return "vu";
case BinaryView:
return "vz";
case ListView:
return "+vl";
case LargeListView:
return "+vL";
case RunEndEncoded:
return "+r";
case NONE:
throw new IllegalArgumentException("Arrow type ID is NONE");
default:
throw new UnsupportedOperationException(
String.format("Unknown type id %s", arrowType.getTypeID()));
}
}