This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 1f20fd627 ORC-1696: Fix ClassCastException when reading avro decimal
type in bechmark
1f20fd627 is described below
commit 1f20fd627570b15cbcbed175a9caf6aec56102ee
Author: sychen <[email protected]>
AuthorDate: Mon Apr 22 01:04:52 2024 -0700
ORC-1696: Fix ClassCastException when reading avro decimal type in bechmark
### What changes were proposed in this pull request?
This PR aims to fix `ClassCastException` when reading avro decimal type in
bechmark.
### Why are the changes needed?
ORC-1191 Forcing `object` to `double`, but object type is `ByteBuffer`,
which causes scan to fail.
```bash
java -jar core/target/orc-benchmarks-core-*-uber.jar scan data
```
```java
Exception in thread "main" java.lang.ClassCastException: class
java.nio.HeapByteBuffer cannot be cast to class java.lang.Double
(java.nio.HeapByteBuffer and java.lang.Double are in module java.base of loader
'bootstrap')
at
org.apache.orc.bench.core.convert.avro.AvroReader$DecimalConverter.convert(AvroReader.java:204)
at
org.apache.orc.bench.core.convert.avro.AvroReader.nextBatch(AvroReader.java:69)
at
org.apache.orc.bench.core.convert.ScanVariants.run(ScanVariants.java:92)
at org.apache.orc.bench.core.Driver.main(Driver.java:64)
```
### How was this patch tested?
local test
```bash
java -jar core/target/orc-benchmarks-core-*-uber.jar scan data
```
output
```
data/generated/taxi/avro.snappy rows: 22758236 batches: 22225
```
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #1898 from cxzl25/ORC-1696.
Authored-by: sychen <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit d4f13dc284fc12b7ff109493652473faec8724d3)
Signed-off-by: Dongjoon Hyun <[email protected]>
---
.../org/apache/orc/bench/core/convert/avro/AvroReader.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git
a/java/bench/core/src/java/org/apache/orc/bench/core/convert/avro/AvroReader.java
b/java/bench/core/src/java/org/apache/orc/bench/core/convert/avro/AvroReader.java
index 97b58a8fe..2756ca1dd 100644
---
a/java/bench/core/src/java/org/apache/orc/bench/core/convert/avro/AvroReader.java
+++
b/java/bench/core/src/java/org/apache/orc/bench/core/convert/avro/AvroReader.java
@@ -41,6 +41,7 @@ import org.apache.orc.TypeDescription;
import org.apache.orc.bench.core.convert.BatchReader;
import java.io.IOException;
+import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.List;
@@ -201,7 +202,11 @@ public class AvroReader implements BatchReader {
cv.isNull[row] = true;
} else {
DecimalColumnVector tc = (DecimalColumnVector) cv;
- tc.vector[row].set(HiveDecimal.create(Math.round((double) value *
multiplier)));
+ if (value instanceof ByteBuffer) {
+ tc.vector[row].set(getHiveDecimalFromByteBuffer((ByteBuffer) value,
scale));
+ } else {
+ tc.vector[row].set(HiveDecimal.create(Math.round((double) value *
multiplier)));
+ }
}
}
}
@@ -289,6 +294,13 @@ public class AvroReader implements BatchReader {
}
}
+ static HiveDecimal getHiveDecimalFromByteBuffer(ByteBuffer byteBuffer,
+ int scale) {
+ byte[] result = getBytesFromByteBuffer(byteBuffer);
+ HiveDecimal dec = HiveDecimal.create(new BigInteger(result), scale);
+ return dec;
+ }
+
static byte[] getBytesFromByteBuffer(ByteBuffer byteBuffer) {
byteBuffer.rewind();
byte[] result = new byte[byteBuffer.limit()];