Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dictionary decimal vector optimization #705

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions common/src/main/java/org/apache/comet/vector/CometDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

package org.apache.comet.vector;

import org.apache.arrow.vector.DecimalVector;
import org.apache.arrow.vector.ValueVector;
import org.apache.spark.sql.types.Decimal;
import org.apache.spark.unsafe.types.UTF8String;

/** A dictionary which maps indices (integers) to values. */
Expand Down Expand Up @@ -100,17 +102,21 @@ public void close() {
}

private void initialize() {
switch (values.getValueVector().getMinorType()) {
ValueVector vector = values.getValueVector();
switch (vector.getMinorType()) {
case DECIMAL:
// We only need to copy values for decimal type as random access
// to the dictionary is not efficient for decimal (it needs to copy
// the value to a new byte array everytime).
binaries = new ByteArrayWrapper[numValues];
for (int i = 0; i < numValues; i++) {
// Need copying here since we re-use byte array for decimal
byte[] bytes = new byte[DECIMAL_BYTE_WIDTH];
bytes = values.copyBinaryDecimal(i, bytes);
binaries[i] = new ByteArrayWrapper(bytes);
if (values.useDecimal128
kazuyukitanimura marked this conversation as resolved.
Show resolved Hide resolved
|| ((DecimalVector) vector).getPrecision() > Decimal.MAX_INT_DIGITS()) {
kazuyukitanimura marked this conversation as resolved.
Show resolved Hide resolved
// We only need to copy values for decimal 128 type as random access
// to the dictionary is not efficient for decimal (it needs to copy
// the value to a new byte array everytime).
binaries = new ByteArrayWrapper[numValues];
for (int i = 0; i < numValues; i++) {
// Need copying here since we re-use byte array for decimal
byte[] bytes = new byte[DECIMAL_BYTE_WIDTH];
bytes = values.copyBinaryDecimal(i, bytes);
binaries[i] = new ByteArrayWrapper(bytes);
}
}
break;
}
Expand Down
Loading