Skip to content

Commit adbaeab

Browse files
author
Feng Liu
committed
init
1 parent 17edfec commit adbaeab

File tree

1 file changed

+43
-62
lines changed

1 file changed

+43
-62
lines changed

sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/ColumnVector.java

Lines changed: 43 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.spark.sql.execution.vectorized;
1818

19+
import org.apache.spark.api.java.function.Function;
1920
import org.apache.spark.sql.catalyst.InternalRow;
2021
import org.apache.spark.sql.catalyst.util.ArrayData;
2122
import org.apache.spark.sql.catalyst.util.MapData;
@@ -99,73 +100,18 @@ public ArrayData copy() {
99100
@Override
100101
public Object[] array() {
101102
DataType dt = data.dataType();
103+
Function<Integer, Object> getAtMethod = (Function<Integer, Object>) i -> get(i, dt);
102104
Object[] list = new Object[length];
103-
104-
if (dt instanceof BooleanType) {
105-
for (int i = 0; i < length; i++) {
106-
if (!data.isNullAt(offset + i)) {
107-
list[i] = data.getBoolean(offset + i);
108-
}
109-
}
110-
} else if (dt instanceof ByteType) {
111-
for (int i = 0; i < length; i++) {
112-
if (!data.isNullAt(offset + i)) {
113-
list[i] = data.getByte(offset + i);
114-
}
115-
}
116-
} else if (dt instanceof ShortType) {
117-
for (int i = 0; i < length; i++) {
118-
if (!data.isNullAt(offset + i)) {
119-
list[i] = data.getShort(offset + i);
120-
}
121-
}
122-
} else if (dt instanceof IntegerType) {
123-
for (int i = 0; i < length; i++) {
124-
if (!data.isNullAt(offset + i)) {
125-
list[i] = data.getInt(offset + i);
126-
}
127-
}
128-
} else if (dt instanceof FloatType) {
129-
for (int i = 0; i < length; i++) {
130-
if (!data.isNullAt(offset + i)) {
131-
list[i] = data.getFloat(offset + i);
132-
}
133-
}
134-
} else if (dt instanceof DoubleType) {
105+
try {
135106
for (int i = 0; i < length; i++) {
136107
if (!data.isNullAt(offset + i)) {
137-
list[i] = data.getDouble(offset + i);
108+
list[i] = getAtMethod.call(i);
138109
}
139110
}
140-
} else if (dt instanceof LongType) {
141-
for (int i = 0; i < length; i++) {
142-
if (!data.isNullAt(offset + i)) {
143-
list[i] = data.getLong(offset + i);
144-
}
145-
}
146-
} else if (dt instanceof DecimalType) {
147-
DecimalType decType = (DecimalType)dt;
148-
for (int i = 0; i < length; i++) {
149-
if (!data.isNullAt(offset + i)) {
150-
list[i] = getDecimal(i, decType.precision(), decType.scale());
151-
}
152-
}
153-
} else if (dt instanceof StringType) {
154-
for (int i = 0; i < length; i++) {
155-
if (!data.isNullAt(offset + i)) {
156-
list[i] = getUTF8String(i).toString();
157-
}
158-
}
159-
} else if (dt instanceof CalendarIntervalType) {
160-
for (int i = 0; i < length; i++) {
161-
if (!data.isNullAt(offset + i)) {
162-
list[i] = getInterval(i);
163-
}
164-
}
165-
} else {
166-
throw new UnsupportedOperationException("Type " + dt);
111+
return list;
112+
} catch(Exception e) {
113+
throw new RuntimeException("Could not get the array", e);
167114
}
168-
return list;
169115
}
170116

171117
@Override
@@ -237,7 +183,42 @@ public MapData getMap(int ordinal) {
237183

238184
@Override
239185
public Object get(int ordinal, DataType dataType) {
240-
throw new UnsupportedOperationException();
186+
if (dataType instanceof BooleanType) {
187+
return getBoolean(ordinal);
188+
} else if (dataType instanceof ByteType) {
189+
return getByte(ordinal);
190+
} else if (dataType instanceof ShortType) {
191+
return getShort(ordinal);
192+
} else if (dataType instanceof IntegerType) {
193+
return getInt(ordinal);
194+
} else if (dataType instanceof LongType) {
195+
return getLong(ordinal);
196+
} else if (dataType instanceof FloatType) {
197+
return getFloat(ordinal);
198+
} else if (dataType instanceof DoubleType) {
199+
return getDouble(ordinal);
200+
} else if (dataType instanceof StringType) {
201+
return getUTF8String(ordinal);
202+
} else if (dataType instanceof BinaryType) {
203+
return getBinary(ordinal);
204+
} else if (dataType instanceof DecimalType) {
205+
DecimalType t = (DecimalType) dataType;
206+
return getDecimal(ordinal, t.precision(), t.scale());
207+
} else if (dataType instanceof DateType) {
208+
return getInt(ordinal);
209+
} else if (dataType instanceof TimestampType) {
210+
return getLong(ordinal);
211+
} else if (dataType instanceof ArrayType) {
212+
return getArray(ordinal);
213+
} else if (dataType instanceof StructType) {
214+
return getStruct(ordinal, ((StructType)dataType).fields().length);
215+
} else if (dataType instanceof MapType) {
216+
return getMap(ordinal);
217+
} else if (dataType instanceof CalendarIntervalType) {
218+
return getInterval(ordinal);
219+
} else {
220+
throw new UnsupportedOperationException("Datatype not supported " + dataType);
221+
}
241222
}
242223

243224
@Override

0 commit comments

Comments
 (0)