1
0

[HUDI-934] Add processing logic for the decimal LogicalType (#1677)

This commit is contained in:
Yajun Luo
2020-06-02 19:50:55 +08:00
committed by GitHub
parent 742c204099
commit a9a97d6af4

View File

@@ -26,6 +26,7 @@ import org.apache.hudi.common.util.collection.Pair;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.HoodieIOException;
import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.generic.GenericArray;
@@ -36,6 +37,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
import org.apache.hadoop.hive.serde2.ColumnProjectionUtils;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
import org.apache.hadoop.io.ArrayWritable;
import org.apache.hadoop.io.BooleanWritable;
import org.apache.hadoop.io.BytesWritable;
@@ -300,6 +302,14 @@ public abstract class AbstractRealtimeRecordReader {
throw new IllegalArgumentException("Only support union with null");
}
case FIXED:
if (schema.getLogicalType() != null && schema.getLogicalType().getName().equals("decimal")) {
LogicalTypes.Decimal decimal = (LogicalTypes.Decimal) LogicalTypes.fromSchema(schema);
HiveDecimalWritable writable = new HiveDecimalWritable(((GenericFixed) value).bytes(),
decimal.getScale());
return HiveDecimalWritable.enforcePrecisionScale(writable,
decimal.getPrecision(),
decimal.getScale());
}
return new BytesWritable(((GenericFixed) value).bytes());
default:
return null;