This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git
The following commit(s) were added to refs/heads/main by this push:
new 1db9a10d fix: Optimize getDecimal for small precision (#758)
1db9a10d is described below
commit 1db9a10d487b24505d405f1b77ecdb06d8f43d21
Author: KAZUYUKI TANIMURA <[email protected]>
AuthorDate: Mon Aug 5 14:32:23 2024 -0700
fix: Optimize getDecimal for small precision (#758)
---
.../main/java/org/apache/comet/vector/CometDelegateVector.java | 5 +++++
common/src/main/java/org/apache/comet/vector/CometDictionary.java | 4 ++++
.../main/java/org/apache/comet/vector/CometDictionaryVector.java | 5 +++++
.../src/main/java/org/apache/comet/vector/CometPlainVector.java | 5 +++++
common/src/main/java/org/apache/comet/vector/CometVector.java | 8 ++++++--
spark/src/test/resources/tpcds-micro-benchmarks/add_decimals.sql | 2 ++
.../org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala | 1 +
7 files changed, 28 insertions(+), 2 deletions(-)
diff --git
a/common/src/main/java/org/apache/comet/vector/CometDelegateVector.java
b/common/src/main/java/org/apache/comet/vector/CometDelegateVector.java
index 2287e202..75e62ea0 100644
--- a/common/src/main/java/org/apache/comet/vector/CometDelegateVector.java
+++ b/common/src/main/java/org/apache/comet/vector/CometDelegateVector.java
@@ -107,6 +107,11 @@ public class CometDelegateVector extends CometVector {
return delegate.getLong(rowId);
}
+ @Override
+ public long getLongDecimal(int rowId) {
+ return delegate.getLongDecimal(rowId);
+ }
+
@Override
public float getFloat(int rowId) {
return delegate.getFloat(rowId);
diff --git a/common/src/main/java/org/apache/comet/vector/CometDictionary.java
b/common/src/main/java/org/apache/comet/vector/CometDictionary.java
index b610d5f3..cacfbada 100644
--- a/common/src/main/java/org/apache/comet/vector/CometDictionary.java
+++ b/common/src/main/java/org/apache/comet/vector/CometDictionary.java
@@ -68,6 +68,10 @@ public class CometDictionary implements AutoCloseable {
return values.getLong(index);
}
+ public long decodeToLongDecimal(int index) {
+ return values.getLongDecimal(index);
+ }
+
public float decodeToFloat(int index) {
return values.getFloat(index);
}
diff --git
a/common/src/main/java/org/apache/comet/vector/CometDictionaryVector.java
b/common/src/main/java/org/apache/comet/vector/CometDictionaryVector.java
index a74f4ff6..a49255e7 100644
--- a/common/src/main/java/org/apache/comet/vector/CometDictionaryVector.java
+++ b/common/src/main/java/org/apache/comet/vector/CometDictionaryVector.java
@@ -97,6 +97,11 @@ public class CometDictionaryVector extends
CometDecodedVector {
return values.decodeToLong(indices.getInt(i));
}
+ @Override
+ public long getLongDecimal(int i) {
+ return values.decodeToLongDecimal(indices.getInt(i));
+ }
+
@Override
public float getFloat(int i) {
return values.decodeToFloat(indices.getInt(i));
diff --git a/common/src/main/java/org/apache/comet/vector/CometPlainVector.java
b/common/src/main/java/org/apache/comet/vector/CometPlainVector.java
index c368c3b3..65cc876b 100644
--- a/common/src/main/java/org/apache/comet/vector/CometPlainVector.java
+++ b/common/src/main/java/org/apache/comet/vector/CometPlainVector.java
@@ -90,6 +90,11 @@ public class CometPlainVector extends CometDecodedVector {
return Platform.getLong(null, valueBufferAddress + rowId * 8L);
}
+ @Override
+ public long getLongDecimal(int rowId) {
+ return Platform.getLong(null, valueBufferAddress + rowId * 16L);
+ }
+
@Override
public float getFloat(int rowId) {
return Platform.getFloat(null, valueBufferAddress + rowId * 4L);
diff --git a/common/src/main/java/org/apache/comet/vector/CometVector.java
b/common/src/main/java/org/apache/comet/vector/CometVector.java
index 8b32b39a..8e4c4edf 100644
--- a/common/src/main/java/org/apache/comet/vector/CometVector.java
+++ b/common/src/main/java/org/apache/comet/vector/CometVector.java
@@ -87,8 +87,8 @@ public abstract class CometVector extends ColumnVector {
public Decimal getDecimal(int i, int precision, int scale) {
if (!useDecimal128 && precision <= Decimal.MAX_INT_DIGITS() && type
instanceof IntegerType) {
return createDecimal(getInt(i), precision, scale);
- } else if (!useDecimal128 && precision <= Decimal.MAX_LONG_DIGITS()) {
- return createDecimal(getLong(i), precision, scale);
+ } else if (precision <= Decimal.MAX_LONG_DIGITS()) {
+ return createDecimal(useDecimal128 ? getLongDecimal(i) : getLong(i),
precision, scale);
} else {
byte[] bytes = getBinaryDecimal(i);
BigInteger bigInteger = new BigInteger(bytes);
@@ -166,6 +166,10 @@ public abstract class CometVector extends ColumnVector {
throw new UnsupportedOperationException("Not yet supported");
}
+ public long getLongDecimal(int rowId) {
+ throw new UnsupportedOperationException("Not yet supported");
+ }
+
@Override
public float getFloat(int rowId) {
throw new UnsupportedOperationException("Not yet supported");
diff --git a/spark/src/test/resources/tpcds-micro-benchmarks/add_decimals.sql
b/spark/src/test/resources/tpcds-micro-benchmarks/add_decimals.sql
new file mode 100644
index 00000000..690c0034
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/add_decimals.sql
@@ -0,0 +1,2 @@
+SELECT ss_net_profit + ss_net_profit
+FROM store_sales
\ No newline at end of file
diff --git
a/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala
b/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala
index d86aa385..b09e0486 100644
---
a/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala
+++
b/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala
@@ -54,6 +54,7 @@ object CometTPCDSMicroBenchmark extends
CometTPCQueryBenchmarkBase {
val queries: Seq[String] = Seq(
"scan_decimal",
+ "add_decimals",
"add_many_decimals",
"add_many_integers",
"agg_high_cardinality",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]