MaxGekk commented on a change in pull request #28406:
URL: https://github.com/apache/spark/pull/28406#discussion_r418217773



##########
File path: 
sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/VectorizedPlainValuesReader.java
##########
@@ -96,6 +124,33 @@ public final void readLongs(int total, WritableColumnVector 
c, int rowId) {
     }
   }
 
+  // A fork of `readLongs` to rebase the timestamp values. For performance 
reasons, this method
+  // iterates the values twice: check if we need to rebase first, then go to 
the optimized branch
+  // if rebase is not needed.
+  @Override
+  public final void readLongsWithRebase(int total, WritableColumnVector c, int 
rowId) {
+    int requiredBytes = total * 8;
+    ByteBuffer buffer = getBuffer(requiredBytes);
+    boolean rebase = false;
+    for (int i = 0; i < total; i += 1) {

Review comment:
       The byte code of the loop is:
   ```
       LINENUMBER 136 L6
       ILOAD 6
       ALOAD 5
       ALOAD 5
       INVOKEVIRTUAL java/nio/ByteBuffer.position ()I
       ILOAD 7
       BIPUSH 8
       IMUL
       IADD
       INVOKEVIRTUAL java/nio/ByteBuffer.getLong (I)J
       INVOKESTATIC 
org/apache/spark/sql/catalyst/util/RebaseDateTime.lastSwitchJulianTs ()J
       LCMP
       IFGE L7
       ICONST_1
       GOTO L8
   ```
   We could avoid mul like 
   ```java
       int pos = buffer.position();
       int endPos = pos + total * 8;
       long threshold = RebaseDateTime.lastSwitchJulianTs();
       while (pos < endPos) {
         rebase |= buffer.getLong(pos) < threshold;
         pos += 8;
       }
   ```
   Would it be faster?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to