You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/12/08 11:38:27 UTC

[GitHub] [hive] maheshk114 opened a new pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

maheshk114 opened a new pull request #1753:
URL: https://github.com/apache/hive/pull/1753


   …
   
   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] pgaref commented on a change in pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

Posted by GitBox <gi...@apache.org>.
pgaref commented on a change in pull request #1753:
URL: https://github.com/apache/hive/pull/1753#discussion_r540839969



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -328,6 +345,13 @@ private void serializeUnionWrite(
     serializeWrite.finishUnion();
   }
 
+  class VectorSerializeStructWriter extends VectorSerializeWriter {
+    @Override
+    void serialize(Object colInfo, Field field, int adjustedBatchIndex) throws IOException {
+      serializeStructWrite((StructColumnVector)colInfo, field, adjustedBatchIndex);
+    }
+  }
+
   private void serializeStructWrite(

Review comment:
       Nit: would be cleaner if serializeStructWrite method is be part of the VectorSerializeStructWriter class

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -355,6 +379,13 @@ private void serializeStructWrite(
     serializeWrite.finishStruct();
   }
 
+  class VectorSerializeMapWriter extends VectorSerializeWriter {
+    @Override
+    void serialize(Object colInfo, Field field, int adjustedBatchIndex) throws IOException {
+      serializeMapWrite((MapColumnVector)colInfo, field, adjustedBatchIndex);
+    }
+  }
+
   private void serializeMapWrite(

Review comment:
       Nit: serializeMapWrite part of VectorSerializeMapWriter class?

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java
##########
@@ -564,173 +621,337 @@ public void init() throws HiveException {
     init(0);
   }
 
-  private void storePrimitiveRowColumn(ColumnVector colVector, Field field,
-      int batchIndex, boolean canRetainByteRef) throws IOException {
-
-    switch (field.getPrimitiveCategory()) {
-    case VOID:
+  class VectorVoidDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       VectorizedBatchUtil.setNullColIsNullValue(colVector, batchIndex);
-      return;
-    case BOOLEAN:
-      ((LongColumnVector) colVector).vector[batchIndex] = (deserializeRead.currentBoolean ? 1 : 0);
-      break;
-    case BYTE:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertVoid();
+    }
+  }
+
+  class VectorBooleanDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      ((LongColumnVector) colVector).vector[batchIndex] =
+              (deserializeRead.currentBoolean ? 1 : 0);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertBoolean(field.getConversionWritable());
+    }
+  }
+
+  class VectorByteDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentByte;
-      break;
-    case SHORT:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertByte(field.getConversionWritable());
+    }
+  }
+
+  class VectorShortDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentShort;
-      break;
-    case INT:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertShort(field.getConversionWritable());
+    }
+  }
+
+  class VectorIntDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentInt;
-      break;
-    case LONG:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertInt(field.getConversionWritable());
+    }
+  }
+
+  class VectorLongDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentLong;
-      break;
-    case TIMESTAMP:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertLong(field.getConversionWritable());
+    }
+  }
+
+  class VectorTimestampDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((TimestampColumnVector) colVector).set(
-          batchIndex, deserializeRead.currentTimestampWritable.getTimestamp().toSqlTimestamp());
-      break;
-    case DATE:
-      ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentDateWritable.getDays();
-      break;
-    case FLOAT:
+              batchIndex, deserializeRead.currentTimestampWritable.getTimestamp().toSqlTimestamp());
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertTimestamp(field.getConversionWritable());
+    }
+  }
+
+  class VectorDateDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      ((LongColumnVector) colVector).vector[batchIndex] =
+              deserializeRead.currentDateWritable.getDays();
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertDate(field.getConversionWritable());
+    }
+  }
+
+  class VectorFloatDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((DoubleColumnVector) colVector).vector[batchIndex] = deserializeRead.currentFloat;
-      break;
-    case DOUBLE:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertFloat(field.getConversionWritable());
+    }
+  }
+
+  class VectorDoubleDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((DoubleColumnVector) colVector).vector[batchIndex] = deserializeRead.currentDouble;
-      break;
-    case BINARY:
-    case STRING:
-      {
-        final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
-        if (deserializeRead.currentExternalBufferNeeded) {
-          bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
-          deserializeRead.copyToExternalBuffer(
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertDouble(field.getConversionWritable());
+    }
+  }
+
+  private void storeString(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+          throws IOException {
+    final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
+    if (deserializeRead.currentExternalBufferNeeded) {
+      bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
+      deserializeRead.copyToExternalBuffer(
               bytesColVec.getValPreallocatedBytes(), bytesColVec.getValPreallocatedStart());
-          bytesColVec.setValPreallocated(
+      bytesColVec.setValPreallocated(
               batchIndex,
               deserializeRead.currentExternalBufferNeededLen);
-        } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
-          bytesColVec.setRef(
+    } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
+      bytesColVec.setRef(
               batchIndex,
               deserializeRead.currentBytes,
               deserializeRead.currentBytesStart,
               deserializeRead.currentBytesLength);
-        } else {
-          bytesColVec.setVal(
+    } else {
+      bytesColVec.setVal(
               batchIndex,
               deserializeRead.currentBytes,
               deserializeRead.currentBytesStart,
               deserializeRead.currentBytesLength);
-        }
-      }
-      break;
-    case VARCHAR:
-      {
-        // Use the basic STRING bytes read to get access, then use our optimal truncate/trim method
-        // that does not use Java String objects.
-        final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
-        if (deserializeRead.currentExternalBufferNeeded) {
-          // Write directly into our BytesColumnVector value buffer.
-          bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
-          final byte[] convertBuffer = bytesColVec.getValPreallocatedBytes();
-          final int convertBufferStart = bytesColVec.getValPreallocatedStart();
-          deserializeRead.copyToExternalBuffer(
-              convertBuffer,
-              convertBufferStart);
-          bytesColVec.setValPreallocated(
-              batchIndex,
-              StringExpr.truncate(
-                  convertBuffer,
-                  convertBufferStart,
-                  deserializeRead.currentExternalBufferNeededLen,
-                  field.getMaxLength()));
-        } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
-          bytesColVec.setRef(
-              batchIndex,
-              deserializeRead.currentBytes,
-              deserializeRead.currentBytesStart,
-              StringExpr.truncate(
-                  deserializeRead.currentBytes,
-                  deserializeRead.currentBytesStart,
-                  deserializeRead.currentBytesLength,
-                  field.getMaxLength()));
-        } else {
-          bytesColVec.setVal(
-              batchIndex,
-              deserializeRead.currentBytes,
-              deserializeRead.currentBytesStart,
-              StringExpr.truncate(
-                  deserializeRead.currentBytes,
-                  deserializeRead.currentBytesStart,
-                  deserializeRead.currentBytesLength,
-                  field.getMaxLength()));
-        }
+    }
+  }
+
+  class VectorBinaryDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      storeString(colVector, field, batchIndex, canRetainByteRef);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertBinary(field.getConversionWritable(), batchIndex);
+    }
+  }
+
+  class VectorStringDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      storeString(colVector, field, batchIndex, canRetainByteRef);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertString(field.getConversionWritable(), batchIndex);
+    }
+  }
+
+  class VectorVarcharDeserializer extends VectorBatchDeserializer {

Review comment:
       Looks like VectorVarcharDeserializer and VectorCharDeserializer share the same store method -- so maybe make them inherit from a common base class and only Override convert method?

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -383,6 +414,13 @@ private void serializeMapWrite(
     serializeWrite.finishMap();
   }
 
+  class VectorSerializeListWriter extends VectorSerializeWriter {
+    @Override
+    void serialize(Object colInfo, Field field, int adjustedBatchIndex) throws IOException {
+      serializeListWrite((ListColumnVector)colInfo, field, adjustedBatchIndex);
+    }
+  }
+
   private void serializeListWrite(

Review comment:
       Nit: serializeListWrite part of VectorSerializeListWriter?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] maheshk114 commented on a change in pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

Posted by GitBox <gi...@apache.org>.
maheshk114 commented on a change in pull request #1753:
URL: https://github.com/apache/hive/pull/1753#discussion_r542159449



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java
##########
@@ -564,173 +621,337 @@ public void init() throws HiveException {
     init(0);
   }
 
-  private void storePrimitiveRowColumn(ColumnVector colVector, Field field,
-      int batchIndex, boolean canRetainByteRef) throws IOException {
-
-    switch (field.getPrimitiveCategory()) {
-    case VOID:
+  class VectorVoidDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       VectorizedBatchUtil.setNullColIsNullValue(colVector, batchIndex);
-      return;
-    case BOOLEAN:
-      ((LongColumnVector) colVector).vector[batchIndex] = (deserializeRead.currentBoolean ? 1 : 0);
-      break;
-    case BYTE:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertVoid();
+    }
+  }
+
+  class VectorBooleanDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      ((LongColumnVector) colVector).vector[batchIndex] =
+              (deserializeRead.currentBoolean ? 1 : 0);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertBoolean(field.getConversionWritable());
+    }
+  }
+
+  class VectorByteDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentByte;
-      break;
-    case SHORT:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertByte(field.getConversionWritable());
+    }
+  }
+
+  class VectorShortDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentShort;
-      break;
-    case INT:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertShort(field.getConversionWritable());
+    }
+  }
+
+  class VectorIntDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentInt;
-      break;
-    case LONG:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertInt(field.getConversionWritable());
+    }
+  }
+
+  class VectorLongDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentLong;
-      break;
-    case TIMESTAMP:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertLong(field.getConversionWritable());
+    }
+  }
+
+  class VectorTimestampDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((TimestampColumnVector) colVector).set(
-          batchIndex, deserializeRead.currentTimestampWritable.getTimestamp().toSqlTimestamp());
-      break;
-    case DATE:
-      ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentDateWritable.getDays();
-      break;
-    case FLOAT:
+              batchIndex, deserializeRead.currentTimestampWritable.getTimestamp().toSqlTimestamp());
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertTimestamp(field.getConversionWritable());
+    }
+  }
+
+  class VectorDateDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      ((LongColumnVector) colVector).vector[batchIndex] =
+              deserializeRead.currentDateWritable.getDays();
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertDate(field.getConversionWritable());
+    }
+  }
+
+  class VectorFloatDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((DoubleColumnVector) colVector).vector[batchIndex] = deserializeRead.currentFloat;
-      break;
-    case DOUBLE:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertFloat(field.getConversionWritable());
+    }
+  }
+
+  class VectorDoubleDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((DoubleColumnVector) colVector).vector[batchIndex] = deserializeRead.currentDouble;
-      break;
-    case BINARY:
-    case STRING:
-      {
-        final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
-        if (deserializeRead.currentExternalBufferNeeded) {
-          bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
-          deserializeRead.copyToExternalBuffer(
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertDouble(field.getConversionWritable());
+    }
+  }
+
+  private void storeString(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+          throws IOException {
+    final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
+    if (deserializeRead.currentExternalBufferNeeded) {
+      bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
+      deserializeRead.copyToExternalBuffer(
               bytesColVec.getValPreallocatedBytes(), bytesColVec.getValPreallocatedStart());
-          bytesColVec.setValPreallocated(
+      bytesColVec.setValPreallocated(
               batchIndex,
               deserializeRead.currentExternalBufferNeededLen);
-        } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
-          bytesColVec.setRef(
+    } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
+      bytesColVec.setRef(
               batchIndex,
               deserializeRead.currentBytes,
               deserializeRead.currentBytesStart,
               deserializeRead.currentBytesLength);
-        } else {
-          bytesColVec.setVal(
+    } else {
+      bytesColVec.setVal(
               batchIndex,
               deserializeRead.currentBytes,
               deserializeRead.currentBytesStart,
               deserializeRead.currentBytesLength);
-        }
-      }
-      break;
-    case VARCHAR:
-      {
-        // Use the basic STRING bytes read to get access, then use our optimal truncate/trim method
-        // that does not use Java String objects.
-        final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
-        if (deserializeRead.currentExternalBufferNeeded) {
-          // Write directly into our BytesColumnVector value buffer.
-          bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
-          final byte[] convertBuffer = bytesColVec.getValPreallocatedBytes();
-          final int convertBufferStart = bytesColVec.getValPreallocatedStart();
-          deserializeRead.copyToExternalBuffer(
-              convertBuffer,
-              convertBufferStart);
-          bytesColVec.setValPreallocated(
-              batchIndex,
-              StringExpr.truncate(
-                  convertBuffer,
-                  convertBufferStart,
-                  deserializeRead.currentExternalBufferNeededLen,
-                  field.getMaxLength()));
-        } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
-          bytesColVec.setRef(
-              batchIndex,
-              deserializeRead.currentBytes,
-              deserializeRead.currentBytesStart,
-              StringExpr.truncate(
-                  deserializeRead.currentBytes,
-                  deserializeRead.currentBytesStart,
-                  deserializeRead.currentBytesLength,
-                  field.getMaxLength()));
-        } else {
-          bytesColVec.setVal(
-              batchIndex,
-              deserializeRead.currentBytes,
-              deserializeRead.currentBytesStart,
-              StringExpr.truncate(
-                  deserializeRead.currentBytes,
-                  deserializeRead.currentBytesStart,
-                  deserializeRead.currentBytesLength,
-                  field.getMaxLength()));
-        }
+    }
+  }
+
+  class VectorBinaryDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      storeString(colVector, field, batchIndex, canRetainByteRef);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertBinary(field.getConversionWritable(), batchIndex);
+    }
+  }
+
+  class VectorStringDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      storeString(colVector, field, batchIndex, canRetainByteRef);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertString(field.getConversionWritable(), batchIndex);
+    }
+  }
+
+  class VectorVarcharDeserializer extends VectorBatchDeserializer {

Review comment:
       i think the code duplication is not much and the classes are too simple. creating a common class will be over engineering.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] rbalamohan commented on a change in pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

Posted by GitBox <gi...@apache.org>.
rbalamohan commented on a change in pull request #1753:
URL: https://github.com/apache/hive/pull/1753#discussion_r538916121



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -61,27 +61,16 @@
   private Field root;
 
   private static class Field {
-    Field[] children;
-
-    boolean isPrimitive;
-    Category category;
-    PrimitiveCategory primitiveCategory;
-    TypeInfo typeInfo;
-
-    int count;
-
-    ObjectInspector objectInspector;
-    int outputColumnNum;
-
+    Field[] children = null;
+    boolean isPrimitive = false;
+    Category category = null;
+    PrimitiveCategory primitiveCategory = null;
+    TypeInfo typeInfo = null;
+    int count = 0;
+    ObjectInspector objectInspector = null;
+    int outputColumnNum = -1;
+    VectorSerializeWriter writer = null;
     Field() {

Review comment:
       Can be removed.

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java
##########
@@ -933,12 +1207,20 @@ private void storeUnionRowColumn(ColumnVector colVector,
     unionColVector.isNull[batchIndex] = false;
     unionColVector.tags[batchIndex] = tag;
 
-    storeComplexFieldRowColumn(
+    deserializer.storeComplexFieldRowColumn(
         colVectorFields[tag],
         unionHelper.getFields()[tag],
         batchIndex,
         canRetainByteRef);
-    deserializeRead.finishComplexVariableFieldsType();
+    deserializer.deserializeRead.finishComplexVariableFieldsType();
+  }
+
+  abstract static class VectorBatchDeserializer {
+    abstract void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef,
+                            VectorDeserializeRow deserializer) throws IOException;

Review comment:
       Why VectorDeserializerRow needs be passed here again? ("this" references in other places as well). If you remove "static" class declaration in VectorBatchDeserializer children, you may not need to pass this.  And the patch would become lot lesser changes?

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -274,44 +315,25 @@ private void serializeWrite(
       return;
     }
     isAllNulls = false;
+    field.writer.serialize(colVector, field, adjustedBatchIndex, this);
+  }
 
-    if (field.isPrimitive) {
-      serializePrimitiveWrite(colVector, field, adjustedBatchIndex);
-      return;
-    }
-    final Category category = field.category;
-    switch (category) {
-    case LIST:
-      serializeListWrite(
-          (ListColumnVector) colVector,
-          field,
-          adjustedBatchIndex);
-      break;
-    case MAP:
-      serializeMapWrite(
-          (MapColumnVector) colVector,
-          field,
-          adjustedBatchIndex);
-      break;
-    case STRUCT:
-      serializeStructWrite(
-          (StructColumnVector) colVector,
-          field,
-          adjustedBatchIndex);
-      break;
-    case UNION:
-      serializeUnionWrite(
-          (UnionColumnVector) colVector,
-          field,
-          adjustedBatchIndex);
-      break;
-    default:
-      throw new RuntimeException("Unexpected category " + category);
+  abstract static class VectorSerializeWriter {
+    abstract void serialize(Object colVector, Field field, int adjustedBatchIndex,
+                            VectorSerializeRow serializeRow) throws IOException;

Review comment:
       Same as earlier. VectorSerializeRow need not be passed here. Patch may need lesser changes if you remove static declaration on children.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] maheshk114 commented on a change in pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

Posted by GitBox <gi...@apache.org>.
maheshk114 commented on a change in pull request #1753:
URL: https://github.com/apache/hive/pull/1753#discussion_r542159016



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -383,6 +414,13 @@ private void serializeMapWrite(
     serializeWrite.finishMap();
   }
 
+  class VectorSerializeListWriter extends VectorSerializeWriter {
+    @Override
+    void serialize(Object colInfo, Field field, int adjustedBatchIndex) throws IOException {
+      serializeListWrite((ListColumnVector)colInfo, field, adjustedBatchIndex);
+    }
+  }
+
   private void serializeListWrite(

Review comment:
       done




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] maheshk114 commented on a change in pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

Posted by GitBox <gi...@apache.org>.
maheshk114 commented on a change in pull request #1753:
URL: https://github.com/apache/hive/pull/1753#discussion_r542159449



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java
##########
@@ -564,173 +621,337 @@ public void init() throws HiveException {
     init(0);
   }
 
-  private void storePrimitiveRowColumn(ColumnVector colVector, Field field,
-      int batchIndex, boolean canRetainByteRef) throws IOException {
-
-    switch (field.getPrimitiveCategory()) {
-    case VOID:
+  class VectorVoidDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       VectorizedBatchUtil.setNullColIsNullValue(colVector, batchIndex);
-      return;
-    case BOOLEAN:
-      ((LongColumnVector) colVector).vector[batchIndex] = (deserializeRead.currentBoolean ? 1 : 0);
-      break;
-    case BYTE:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertVoid();
+    }
+  }
+
+  class VectorBooleanDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      ((LongColumnVector) colVector).vector[batchIndex] =
+              (deserializeRead.currentBoolean ? 1 : 0);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertBoolean(field.getConversionWritable());
+    }
+  }
+
+  class VectorByteDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentByte;
-      break;
-    case SHORT:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertByte(field.getConversionWritable());
+    }
+  }
+
+  class VectorShortDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentShort;
-      break;
-    case INT:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertShort(field.getConversionWritable());
+    }
+  }
+
+  class VectorIntDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentInt;
-      break;
-    case LONG:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertInt(field.getConversionWritable());
+    }
+  }
+
+  class VectorLongDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentLong;
-      break;
-    case TIMESTAMP:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertLong(field.getConversionWritable());
+    }
+  }
+
+  class VectorTimestampDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((TimestampColumnVector) colVector).set(
-          batchIndex, deserializeRead.currentTimestampWritable.getTimestamp().toSqlTimestamp());
-      break;
-    case DATE:
-      ((LongColumnVector) colVector).vector[batchIndex] = deserializeRead.currentDateWritable.getDays();
-      break;
-    case FLOAT:
+              batchIndex, deserializeRead.currentTimestampWritable.getTimestamp().toSqlTimestamp());
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertTimestamp(field.getConversionWritable());
+    }
+  }
+
+  class VectorDateDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      ((LongColumnVector) colVector).vector[batchIndex] =
+              deserializeRead.currentDateWritable.getDays();
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertDate(field.getConversionWritable());
+    }
+  }
+
+  class VectorFloatDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((DoubleColumnVector) colVector).vector[batchIndex] = deserializeRead.currentFloat;
-      break;
-    case DOUBLE:
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertFloat(field.getConversionWritable());
+    }
+  }
+
+  class VectorDoubleDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
       ((DoubleColumnVector) colVector).vector[batchIndex] = deserializeRead.currentDouble;
-      break;
-    case BINARY:
-    case STRING:
-      {
-        final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
-        if (deserializeRead.currentExternalBufferNeeded) {
-          bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
-          deserializeRead.copyToExternalBuffer(
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertDouble(field.getConversionWritable());
+    }
+  }
+
+  private void storeString(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+          throws IOException {
+    final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
+    if (deserializeRead.currentExternalBufferNeeded) {
+      bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
+      deserializeRead.copyToExternalBuffer(
               bytesColVec.getValPreallocatedBytes(), bytesColVec.getValPreallocatedStart());
-          bytesColVec.setValPreallocated(
+      bytesColVec.setValPreallocated(
               batchIndex,
               deserializeRead.currentExternalBufferNeededLen);
-        } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
-          bytesColVec.setRef(
+    } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
+      bytesColVec.setRef(
               batchIndex,
               deserializeRead.currentBytes,
               deserializeRead.currentBytesStart,
               deserializeRead.currentBytesLength);
-        } else {
-          bytesColVec.setVal(
+    } else {
+      bytesColVec.setVal(
               batchIndex,
               deserializeRead.currentBytes,
               deserializeRead.currentBytesStart,
               deserializeRead.currentBytesLength);
-        }
-      }
-      break;
-    case VARCHAR:
-      {
-        // Use the basic STRING bytes read to get access, then use our optimal truncate/trim method
-        // that does not use Java String objects.
-        final BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
-        if (deserializeRead.currentExternalBufferNeeded) {
-          // Write directly into our BytesColumnVector value buffer.
-          bytesColVec.ensureValPreallocated(deserializeRead.currentExternalBufferNeededLen);
-          final byte[] convertBuffer = bytesColVec.getValPreallocatedBytes();
-          final int convertBufferStart = bytesColVec.getValPreallocatedStart();
-          deserializeRead.copyToExternalBuffer(
-              convertBuffer,
-              convertBufferStart);
-          bytesColVec.setValPreallocated(
-              batchIndex,
-              StringExpr.truncate(
-                  convertBuffer,
-                  convertBufferStart,
-                  deserializeRead.currentExternalBufferNeededLen,
-                  field.getMaxLength()));
-        } else if (canRetainByteRef && inputBytes == deserializeRead.currentBytes) {
-          bytesColVec.setRef(
-              batchIndex,
-              deserializeRead.currentBytes,
-              deserializeRead.currentBytesStart,
-              StringExpr.truncate(
-                  deserializeRead.currentBytes,
-                  deserializeRead.currentBytesStart,
-                  deserializeRead.currentBytesLength,
-                  field.getMaxLength()));
-        } else {
-          bytesColVec.setVal(
-              batchIndex,
-              deserializeRead.currentBytes,
-              deserializeRead.currentBytesStart,
-              StringExpr.truncate(
-                  deserializeRead.currentBytes,
-                  deserializeRead.currentBytesStart,
-                  deserializeRead.currentBytesLength,
-                  field.getMaxLength()));
-        }
+    }
+  }
+
+  class VectorBinaryDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      storeString(colVector, field, batchIndex, canRetainByteRef);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertBinary(field.getConversionWritable(), batchIndex);
+    }
+  }
+
+  class VectorStringDeserializer extends VectorBatchDeserializer {
+    @Override
+    void store(ColumnVector colVector, Field field, int batchIndex, boolean canRetainByteRef)
+            throws IOException {
+      storeString(colVector, field, batchIndex, canRetainByteRef);
+    }
+
+    @Override
+    Object convert(ColumnVector batch, int batchIndex, Field field) throws IOException {
+      return convertString(field.getConversionWritable(), batchIndex);
+    }
+  }
+
+  class VectorVarcharDeserializer extends VectorBatchDeserializer {

Review comment:
       char uses StringExpr.rightTrimAndTruncate and var char uses StringExpr.truncate(




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] maheshk114 commented on a change in pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

Posted by GitBox <gi...@apache.org>.
maheshk114 commented on a change in pull request #1753:
URL: https://github.com/apache/hive/pull/1753#discussion_r542158896



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -328,6 +345,13 @@ private void serializeUnionWrite(
     serializeWrite.finishUnion();
   }
 
+  class VectorSerializeStructWriter extends VectorSerializeWriter {
+    @Override
+    void serialize(Object colInfo, Field field, int adjustedBatchIndex) throws IOException {
+      serializeStructWrite((StructColumnVector)colInfo, field, adjustedBatchIndex);
+    }
+  }
+
   private void serializeStructWrite(

Review comment:
       done

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorSerializeRow.java
##########
@@ -355,6 +379,13 @@ private void serializeStructWrite(
     serializeWrite.finishStruct();
   }
 
+  class VectorSerializeMapWriter extends VectorSerializeWriter {
+    @Override
+    void serialize(Object colInfo, Field field, int adjustedBatchIndex) throws IOException {
+      serializeMapWrite((MapColumnVector)colInfo, field, adjustedBatchIndex);
+    }
+  }
+
   private void serializeMapWrite(

Review comment:
       done




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] maheshk114 merged pull request #1753: HIVE-24503 : Optimize vector row serde by avoiding type check at run time.

Posted by GitBox <gi...@apache.org>.
maheshk114 merged pull request #1753:
URL: https://github.com/apache/hive/pull/1753


   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org