Skip to content

Commit 62ab054

Browse files
committed
Optimize for fact that get() is only called on String columns.
1 parent c7f0b56 commit 62ab054

File tree

1 file changed

+7
-3
lines changed
  • sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions

1 file changed

+7
-3
lines changed

sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,15 @@ public Object apply(int i) {
186186
public Object get(int i) {
187187
assertIndexIsValid(i);
188188
final DataType dataType = schema.fields()[i].dataType();
189-
// TODO: complete this for the remaining types
189+
// The ordering of these `if` statements is intentional: internally, it looks like this only
190+
// gets invoked in JoinedRow when trying to access UTF8String columns. It's extremely unlikely
191+
// that internal code will call this on non-string-typed columns, but we support that anyways
192+
// just for the sake of completeness.
193+
// TODO: complete this for the remaining types?
190194
if (isNullAt(i)) {
191195
return null;
196+
} else if (dataType == StringType) {
197+
return getUTF8String(i);
192198
} else if (dataType == IntegerType) {
193199
return getInt(i);
194200
} else if (dataType == LongType) {
@@ -197,8 +203,6 @@ public Object get(int i) {
197203
return getDouble(i);
198204
} else if (dataType == FloatType) {
199205
return getFloat(i);
200-
} else if (dataType == StringType) {
201-
return getUTF8String(i);
202206
} else {
203207
throw new UnsupportedOperationException();
204208
}

0 commit comments

Comments
 (0)