bvaradar commented on code in PR #14312:
URL: https://github.com/apache/hudi/pull/14312#discussion_r2557272090
##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaType.java:
##########
@@ -106,39 +105,85 @@ public enum HoodieSchemaType {
*/
BOOLEAN(Schema.Type.BOOLEAN),
+ DECIMAL(Schema.Type.BYTES),
Review Comment:
I was thinking of introducing separate enum class HoodieLogicalType in the
same way we have currently defined (AvroLogicalTypeEnum) but this makes sense
to keep it consolidated in one enum.
Side note (for future reference): We would need to accomodate type
extensibility by plugging in modules without having to add types here everytime
while keeping core types as-is.
##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchema.java:
##########
@@ -389,6 +517,9 @@ public HoodieSchemaType getType() {
* @return Option containing the schema name, or Option.empty() if none
*/
public Option<String> getName() {
+ if (avroSchema.getLogicalType() != null) {
+ return Option.of(type.name().toLowerCase(Locale.ENGLISH));
Review Comment:
Question : Does this locale parameter needs to be there ?
##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchema.java:
##########
@@ -931,4 +1062,204 @@ public HoodieSchema build() {
return new HoodieSchema(avroSchema);
}
}
+
+ public static class Decimal extends HoodieSchema {
+ private final int precision;
+ private final int scale;
+ private final Option<Integer> fixedSize;
+
+ /**
+ * Creates a new HoodieSchema wrapping the given Avro schema.
+ *
+ * @param avroSchema the Avro schema to wrap, cannot be null
+ * @throws IllegalArgumentException if avroSchema is null or does not have
a valid decimal logical type
+ */
+ private Decimal(Schema avroSchema) {
+ super(avroSchema);
+ LogicalType logicalType = avroSchema.getLogicalType();
+ if (!(logicalType instanceof LogicalTypes.Decimal)) {
+ throw new IllegalArgumentException("Decimal schema does not have a
decimal logical type: " + avroSchema);
+ }
+ this.precision = ((LogicalTypes.Decimal) logicalType).getPrecision();
+ this.scale = ((LogicalTypes.Decimal) logicalType).getScale();
+ if (avroSchema.getType() == Schema.Type.FIXED) {
+ this.fixedSize = Option.of(avroSchema.getFixedSize());
+ } else {
+ this.fixedSize = Option.empty();
+ }
+ }
+
+ public int getPrecision() {
+ return precision;
+ }
+
+ public int getScale() {
+ return scale;
+ }
+
+ @Override
+ public Option<String> getName() {
+ return Option.of(String.format("decimal(%d,%d)", precision, scale));
+ }
+
+ @Override
+ public int getFixedSize() {
+ if (fixedSize.isPresent()) {
+ return fixedSize.get();
+ } else {
+ throw new IllegalStateException("Cannot get fixed size from non-fixed
decimal schema");
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ if (!super.equals(o)) {
+ return false;
+ }
+ Decimal decimal = (Decimal) o;
+ return precision == decimal.precision && scale == decimal.scale &&
Objects.equals(fixedSize, decimal.fixedSize);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), precision, scale, fixedSize);
+ }
+ }
+
+ public static class Timestamp extends HoodieSchema {
+ private final boolean isUtcAdjusted;
+ private final TimePrecision precision;
Review Comment:
Is TimePrecision a new Class ? Don't see it
--
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]