0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 package org.apache.spark.sql.catalyst.expressions;
0019
0020 import org.apache.spark.sql.types.*;
0021
0022 public final class SpecializedGettersReader {
0023 private SpecializedGettersReader() {}
0024
0025 public static Object read(
0026 SpecializedGetters obj,
0027 int ordinal,
0028 DataType dataType,
0029 boolean handleNull,
0030 boolean handleUserDefinedType) {
0031 if (handleNull && (obj.isNullAt(ordinal) || dataType instanceof NullType)) {
0032 return null;
0033 }
0034 if (dataType instanceof BooleanType) {
0035 return obj.getBoolean(ordinal);
0036 }
0037 if (dataType instanceof ByteType) {
0038 return obj.getByte(ordinal);
0039 }
0040 if (dataType instanceof ShortType) {
0041 return obj.getShort(ordinal);
0042 }
0043 if (dataType instanceof IntegerType) {
0044 return obj.getInt(ordinal);
0045 }
0046 if (dataType instanceof LongType) {
0047 return obj.getLong(ordinal);
0048 }
0049 if (dataType instanceof FloatType) {
0050 return obj.getFloat(ordinal);
0051 }
0052 if (dataType instanceof DoubleType) {
0053 return obj.getDouble(ordinal);
0054 }
0055 if (dataType instanceof StringType) {
0056 return obj.getUTF8String(ordinal);
0057 }
0058 if (dataType instanceof DecimalType) {
0059 DecimalType dt = (DecimalType) dataType;
0060 return obj.getDecimal(ordinal, dt.precision(), dt.scale());
0061 }
0062 if (dataType instanceof DateType) {
0063 return obj.getInt(ordinal);
0064 }
0065 if (dataType instanceof TimestampType) {
0066 return obj.getLong(ordinal);
0067 }
0068 if (dataType instanceof CalendarIntervalType) {
0069 return obj.getInterval(ordinal);
0070 }
0071 if (dataType instanceof BinaryType) {
0072 return obj.getBinary(ordinal);
0073 }
0074 if (dataType instanceof StructType) {
0075 return obj.getStruct(ordinal, ((StructType) dataType).size());
0076 }
0077 if (dataType instanceof ArrayType) {
0078 return obj.getArray(ordinal);
0079 }
0080 if (dataType instanceof MapType) {
0081 return obj.getMap(ordinal);
0082 }
0083 if (handleUserDefinedType && dataType instanceof UserDefinedType) {
0084 return obj.get(ordinal, ((UserDefinedType)dataType).sqlType());
0085 }
0086
0087 throw new UnsupportedOperationException("Unsupported data type " + dataType.simpleString());
0088 }
0089 }