yihua commented on code in PR #13711:
URL: https://github.com/apache/hudi/pull/13711#discussion_r2353694941
##########
hudi-common/src/main/java/org/apache/hudi/internal/schema/utils/SchemaChangeUtils.java:
##########
@@ -72,38 +72,59 @@ private static boolean isTypeUpdateAllowInternal(Type src,
Type dsr) {
switch (src.typeId()) {
case INT:
return dsr == Types.LongType.get() || dsr == Types.FloatType.get()
- || dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL;
+ || dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL || dsr.typeId() ==
Type.TypeID.DECIMAL_FIXED;
case LONG:
- return dsr == Types.FloatType.get() || dsr == Types.DoubleType.get()
|| dsr == Types.StringType.get() || dsr.typeId() == Type.TypeID.DECIMAL;
+ return dsr == Types.FloatType.get() || dsr == Types.DoubleType.get()
|| dsr == Types.StringType.get() || dsr.typeId() == Type.TypeID.DECIMAL ||
dsr.typeId() == Type.TypeID.DECIMAL_FIXED;
case FLOAT:
- return dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL;
+ return dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL || dsr.typeId() ==
Type.TypeID.DECIMAL_FIXED;
case DOUBLE:
- return dsr == Types.StringType.get() || dsr.typeId() ==
Type.TypeID.DECIMAL;
+ return dsr == Types.StringType.get() || dsr.typeId() ==
Type.TypeID.DECIMAL || dsr.typeId() == Type.TypeID.DECIMAL_FIXED;
case DATE:
case BINARY:
return dsr == Types.StringType.get();
+ case DECIMAL_BYTES:
+ return isDecimalBytesUpdateAllowInternal(src, dsr);
case DECIMAL:
- if (dsr.typeId() == Type.TypeID.DECIMAL) {
- Types.DecimalType decimalSrc = (Types.DecimalType)src;
- Types.DecimalType decimalDsr = (Types.DecimalType)dsr;
- if (decimalDsr.isWiderThan(decimalSrc)) {
- return true;
- }
- if (decimalDsr.precision() >= decimalSrc.precision() &&
decimalDsr.scale() == decimalSrc.scale()) {
- return true;
- }
- } else if (dsr.typeId() == Type.TypeID.STRING) {
- return true;
- }
- break;
+ case DECIMAL_FIXED:
+ return isDecimalFixedUpdateAllowInternal(src, dsr);
Review Comment:
Is there internal schema evolution test coverage on `DECIMAL_BYTES` and
`DECIMAL_FIXED`?
##########
hudi-common/src/main/java/org/apache/hudi/internal/schema/convert/AvroInternalSchemaConverter.java:
##########
@@ -567,32 +587,27 @@ private static Schema
visitInternalPrimitiveToBuildAvroPrimitiveType(Type.Primit
return Schema.createFixed(name, null, null, fixed.getFixedSize());
}
- case DECIMAL: {
- Types.DecimalType decimal = (Types.DecimalType) primitive;
+ case DECIMAL:
+ case DECIMAL_FIXED: {
+ Types.DecimalTypeFixed decimal = (Types.DecimalTypeFixed) primitive;
// NOTE: All schemas corresponding to Avro's type [[FIXED]] are
generated
// with the "fixed" name to stay compatible w/
[[SchemaConverters]]
String name = recordName + AVRO_NAME_DELIMITER + "fixed";
Schema fixedSchema = Schema.createFixed(name,
- null, null, computeMinBytesForPrecision(decimal.precision()));
+ null, null, decimal.getFixedSize());
Review Comment:
Is `decimal.getFixedSize()` the same as `computeMinBytesForPrecision`?
##########
hudi-common/src/main/java/org/apache/hudi/internal/schema/utils/SchemaChangeUtils.java:
##########
@@ -72,38 +72,59 @@ private static boolean isTypeUpdateAllowInternal(Type src,
Type dsr) {
switch (src.typeId()) {
case INT:
return dsr == Types.LongType.get() || dsr == Types.FloatType.get()
- || dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL;
+ || dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL || dsr.typeId() ==
Type.TypeID.DECIMAL_FIXED;
case LONG:
- return dsr == Types.FloatType.get() || dsr == Types.DoubleType.get()
|| dsr == Types.StringType.get() || dsr.typeId() == Type.TypeID.DECIMAL;
+ return dsr == Types.FloatType.get() || dsr == Types.DoubleType.get()
|| dsr == Types.StringType.get() || dsr.typeId() == Type.TypeID.DECIMAL ||
dsr.typeId() == Type.TypeID.DECIMAL_FIXED;
case FLOAT:
- return dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL;
+ return dsr == Types.DoubleType.get() || dsr == Types.StringType.get()
|| dsr.typeId() == Type.TypeID.DECIMAL || dsr.typeId() ==
Type.TypeID.DECIMAL_FIXED;
case DOUBLE:
- return dsr == Types.StringType.get() || dsr.typeId() ==
Type.TypeID.DECIMAL;
+ return dsr == Types.StringType.get() || dsr.typeId() ==
Type.TypeID.DECIMAL || dsr.typeId() == Type.TypeID.DECIMAL_FIXED;
case DATE:
case BINARY:
return dsr == Types.StringType.get();
+ case DECIMAL_BYTES:
+ return isDecimalBytesUpdateAllowInternal(src, dsr);
case DECIMAL:
- if (dsr.typeId() == Type.TypeID.DECIMAL) {
- Types.DecimalType decimalSrc = (Types.DecimalType)src;
- Types.DecimalType decimalDsr = (Types.DecimalType)dsr;
- if (decimalDsr.isWiderThan(decimalSrc)) {
- return true;
- }
- if (decimalDsr.precision() >= decimalSrc.precision() &&
decimalDsr.scale() == decimalSrc.scale()) {
- return true;
- }
- } else if (dsr.typeId() == Type.TypeID.STRING) {
- return true;
- }
- break;
+ case DECIMAL_FIXED:
+ return isDecimalFixedUpdateAllowInternal(src, dsr);
case STRING:
- return dsr == Types.DateType.get() || dsr.typeId() ==
Type.TypeID.DECIMAL || dsr == Types.BinaryType.get();
+ return dsr == Types.DateType.get() || dsr.typeId() ==
Type.TypeID.DECIMAL || dsr.typeId() == Type.TypeID.DECIMAL_FIXED || dsr ==
Types.BinaryType.get();
default:
return false;
}
+ }
+
+ private static boolean isDecimalBytesUpdateAllowInternal(Type src, Type dsr)
{
Review Comment:
nit: is `dsr` a typo, i.e., it should be `dst`?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]