gaborgsomogyi commented on a change in pull request #24016: [MINOR][SQL]
Deduplicate huge if statements in get between specialized getters
URL: https://github.com/apache/spark/pull/24016#discussion_r264229805
##########
File path:
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeArrayData.java
##########
@@ -137,46 +138,7 @@ public boolean isNullAt(int ordinal) {
@Override
public Object get(int ordinal, DataType dataType) {
- if (isNullAt(ordinal) || dataType instanceof NullType) {
- return null;
- } else if (dataType instanceof BooleanType) {
- return getBoolean(ordinal);
- } else if (dataType instanceof ByteType) {
- return getByte(ordinal);
- } else if (dataType instanceof ShortType) {
- return getShort(ordinal);
- } else if (dataType instanceof IntegerType) {
- return getInt(ordinal);
- } else if (dataType instanceof LongType) {
- return getLong(ordinal);
- } else if (dataType instanceof FloatType) {
- return getFloat(ordinal);
- } else if (dataType instanceof DoubleType) {
- return getDouble(ordinal);
- } else if (dataType instanceof DecimalType) {
- DecimalType dt = (DecimalType) dataType;
- return getDecimal(ordinal, dt.precision(), dt.scale());
- } else if (dataType instanceof DateType) {
- return getInt(ordinal);
- } else if (dataType instanceof TimestampType) {
- return getLong(ordinal);
- } else if (dataType instanceof BinaryType) {
- return getBinary(ordinal);
- } else if (dataType instanceof StringType) {
- return getUTF8String(ordinal);
- } else if (dataType instanceof CalendarIntervalType) {
- return getInterval(ordinal);
- } else if (dataType instanceof StructType) {
- return getStruct(ordinal, ((StructType) dataType).size());
- } else if (dataType instanceof ArrayType) {
- return getArray(ordinal);
- } else if (dataType instanceof MapType) {
- return getMap(ordinal);
- } else if (dataType instanceof UserDefinedType) {
- return get(ordinal, ((UserDefinedType)dataType).sqlType());
- } else {
- throw new UnsupportedOperationException("Unsupported data type " +
dataType.simpleString());
- }
+ return reader.read(this, ordinal, dataType);
Review comment:
At the first glance it looks odd to pass the this pointer with the same
type. Maybe it should be a static function only? Not sure.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]