Skip to content

Commit b568ba4

Browse files
cloud-fandongjoon-hyun
authored andcommitted
[SPARK-45157][SQL] Avoid repeated if checks in [On|Off|HeapColumnVector
### What changes were proposed in this pull request? This is a small followup of #42850. `getBytes` checks if the `dictionary` is null or not, then call `getByte` which also checks if the `dictionary` is null or not. This PR avoids the repeated if checks by copying one line code from `getByte` to `getBytes`. The same applies to other `getXXX` methods. ### Why are the changes needed? Make the perf-critical path more efficient. ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? existing tests ### Was this patch authored or co-authored using generative AI tooling? No Closes #42903 from cloud-fan/vector. Authored-by: Wenchen Fan <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 076cb7a commit b568ba4

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public byte[] getBytes(int rowId, int count) {
218218
Platform.copyMemory(null, data + rowId, array, Platform.BYTE_ARRAY_OFFSET, count);
219219
} else {
220220
for (int i = 0; i < count; i++) {
221-
array[i] = getByte(rowId + i);
221+
array[i] = (byte) dictionary.decodeToInt(dictionaryIds.getDictId(rowId + i));
222222
}
223223
}
224224
return array;
@@ -279,7 +279,7 @@ public short[] getShorts(int rowId, int count) {
279279
Platform.copyMemory(null, data + rowId * 2L, array, Platform.SHORT_ARRAY_OFFSET, count * 2L);
280280
} else {
281281
for (int i = 0; i < count; i++) {
282-
array[i] = getShort(rowId + i);
282+
array[i] = (short) dictionary.decodeToInt(dictionaryIds.getDictId(rowId + i));
283283
}
284284
}
285285
return array;
@@ -345,7 +345,7 @@ public int[] getInts(int rowId, int count) {
345345
Platform.copyMemory(null, data + rowId * 4L, array, Platform.INT_ARRAY_OFFSET, count * 4L);
346346
} else {
347347
for (int i = 0; i < count; i++) {
348-
array[i] = getInt(rowId + i);
348+
array[i] = dictionary.decodeToInt(dictionaryIds.getDictId(rowId + i));
349349
}
350350
}
351351
return array;
@@ -423,7 +423,7 @@ public long[] getLongs(int rowId, int count) {
423423
Platform.copyMemory(null, data + rowId * 8L, array, Platform.LONG_ARRAY_OFFSET, count * 8L);
424424
} else {
425425
for (int i = 0; i < count; i++) {
426-
array[i] = getLong(rowId + i);
426+
array[i] = dictionary.decodeToLong(dictionaryIds.getDictId(rowId + i));
427427
}
428428
}
429429
return array;
@@ -487,7 +487,7 @@ public float[] getFloats(int rowId, int count) {
487487
Platform.copyMemory(null, data + rowId * 4L, array, Platform.FLOAT_ARRAY_OFFSET, count * 4L);
488488
} else {
489489
for (int i = 0; i < count; i++) {
490-
array[i] = getFloat(rowId + i);
490+
array[i] = dictionary.decodeToFloat(dictionaryIds.getDictId(rowId + i));
491491
}
492492
}
493493
return array;
@@ -553,7 +553,7 @@ public double[] getDoubles(int rowId, int count) {
553553
count * 8L);
554554
} else {
555555
for (int i = 0; i < count; i++) {
556-
array[i] = getDouble(rowId + i);
556+
array[i] = dictionary.decodeToDouble(dictionaryIds.getDictId(rowId + i));
557557
}
558558
}
559559
return array;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public byte[] getBytes(int rowId, int count) {
216216
System.arraycopy(byteData, rowId, array, 0, count);
217217
} else {
218218
for (int i = 0; i < count; i++) {
219-
array[i] = getByte(rowId + i);
219+
array[i] = (byte) dictionary.decodeToInt(dictionaryIds.getDictId(rowId + i));
220220
}
221221
}
222222
return array;
@@ -276,7 +276,7 @@ public short[] getShorts(int rowId, int count) {
276276
System.arraycopy(shortData, rowId, array, 0, count);
277277
} else {
278278
for (int i = 0; i < count; i++) {
279-
array[i] = getShort(rowId + i);
279+
array[i] = (short) dictionary.decodeToInt(dictionaryIds.getDictId(rowId + i));
280280
}
281281
}
282282
return array;
@@ -337,7 +337,7 @@ public int[] getInts(int rowId, int count) {
337337
System.arraycopy(intData, rowId, array, 0, count);
338338
} else {
339339
for (int i = 0; i < count; i++) {
340-
array[i] = getInt(rowId + i);
340+
array[i] = dictionary.decodeToInt(dictionaryIds.getDictId(rowId + i));
341341
}
342342
}
343343
return array;
@@ -409,7 +409,7 @@ public long[] getLongs(int rowId, int count) {
409409
System.arraycopy(longData, rowId, array, 0, count);
410410
} else {
411411
for (int i = 0; i < count; i++) {
412-
array[i] = getLong(rowId + i);
412+
array[i] = dictionary.decodeToLong(dictionaryIds.getDictId(rowId + i));
413413
}
414414
}
415415
return array;
@@ -466,7 +466,7 @@ public float[] getFloats(int rowId, int count) {
466466
System.arraycopy(floatData, rowId, array, 0, count);
467467
} else {
468468
for (int i = 0; i < count; i++) {
469-
array[i] = getFloat(rowId + i);
469+
array[i] = dictionary.decodeToFloat(dictionaryIds.getDictId(rowId + i));
470470
}
471471
}
472472
return array;
@@ -525,7 +525,7 @@ public double[] getDoubles(int rowId, int count) {
525525
System.arraycopy(doubleData, rowId, array, 0, count);
526526
} else {
527527
for (int i = 0; i < count; i++) {
528-
array[i] = getDouble(rowId + i);
528+
array[i] = dictionary.decodeToDouble(dictionaryIds.getDictId(rowId + i));
529529
}
530530
}
531531
return array;

0 commit comments

Comments
 (0)