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 2023/01/18 11:03:09 UTC

[GitHub] [hive] kasakrisz commented on a diff in pull request #3964: HIVE-26955: Select query fails when decimal column data type is change…

kasakrisz commented on code in PR #3964:
URL: https://github.com/apache/hive/pull/3964#discussion_r1073368036


##########
ql/src/java/org/apache/hadoop/hive/ql/io/parquet/convert/ETypeConverter.java:
##########
@@ -676,6 +676,39 @@ private int getScale(PrimitiveType type) {
               return logicalType.getScale();
             }
           };
+        case serdeConstants.VARCHAR_TYPE_NAME:
+          return new BinaryConverter<HiveVarcharWritable>(type, parent, index, hiveTypeInfo) {
+            @Override
+            protected HiveVarcharWritable convert(Binary binary) {
+              DecimalLogicalTypeAnnotation logicalType = (DecimalLogicalTypeAnnotation) type.getLogicalTypeAnnotation();
+              HiveDecimalWritable decimalWritable = HiveDecimalUtils.enforcePrecisionScale(
+                      new HiveDecimalWritable(binary.getBytes(), logicalType.getScale()),
+                      new DecimalTypeInfo(logicalType.getPrecision(), logicalType.getScale()));

Review Comment:
   These 4 lines are the same in all the new cases. Could you please extract it?
   Exmaple
   ```
   abstract class BinaryConverterToCharacterType<T extends Writable> extends BinaryConverter<T> {
       protected byte[] convertToBytes(Binary binary) {
         DecimalLogicalTypeAnnotation logicalType = (DecimalLogicalTypeAnnotation) type.getLogicalTypeAnnotation();
         return HiveDecimalUtils.enforcePrecisionScale(
                 new HiveDecimalWritable(binary.getBytes(), logicalType.getScale()),
                 new DecimalTypeInfo(logicalType.getPrecision(), logicalType.getScale())).toString().getBytes();
       }
   
       protected abstract T convert(Binary binary);
   }
   ```
   and extend it and call `convertToBytes` in `convert`



-- 
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.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

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