Skip to content

Commit

Permalink
refactor(avro schema): extract AvroSchemaLogicalType
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Apr 18, 2024
1 parent 26a8d99 commit 474edd0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.asyncapi.v3.schema.avro.v1._9_0;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
Expand Down Expand Up @@ -149,35 +148,4 @@ public BuilderVariant metadata(@Nullable Map<String, Object> metadata) {

}

public static class LogicalType {

@JsonProperty("decimal")
public static final String DECIMAL = "decimal";

@JsonProperty("big-decimal")
public static final String BIG_DECIMAL = "big-decimal";

@JsonProperty("uuid")
public static final String UUID = "uuid";

@JsonProperty("date")
public static final String DATE = "date";

@JsonProperty("time-millis")
public static final String TIME_MILLIS = "time-millis";

@JsonProperty("time-micros")
public static final String TIME_MICROS = "time-micros";

@JsonProperty("timestamp-millis")
public static final String TIMESTAMP_MILLIS = "timestamp-millis";

@JsonProperty("timestamp-micros")
public static final String TIMESTAMP_MICROS = "timestamp-micros";

@JsonProperty("duration")
public static final String DURATION = "duration";

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.asyncapi.v3.schema.avro.v1._9_0;

import com.fasterxml.jackson.annotation.JsonProperty;

public class AvroSchemaLogicalType {

@JsonProperty("decimal")
public static final String DECIMAL = "decimal";

@JsonProperty("big-decimal")
public static final String BIG_DECIMAL = "big-decimal";

@JsonProperty("uuid")
public static final String UUID = "uuid";

@JsonProperty("date")
public static final String DATE = "date";

@JsonProperty("time-millis")
public static final String TIME_MILLIS = "time-millis";

@JsonProperty("time-micros")
public static final String TIME_MICROS = "time-micros";

@JsonProperty("timestamp-millis")
public static final String TIMESTAMP_MILLIS = "timestamp-millis";

@JsonProperty("timestamp-micros")
public static final String TIMESTAMP_MICROS = "timestamp-micros";

@JsonProperty("duration")
public static final String DURATION = "duration";

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.asyncapi.v3.schema.avro

import com.asyncapi.v3.schema.avro.v1._9_0.*
import com.asyncapi.v3.schema.avro.v1._9_0.AvroSchema.LogicalType
import com.asyncapi.v3.schema.avro.v1._9_0.AvroSchemaLogicalType
import com.asyncapi.v3.schema.avro.v1._9_0.AvroSchemaType

class AvroSchemasProvider {

Expand Down Expand Up @@ -72,7 +73,7 @@ class AvroSchemasProvider {
AvroSchemaType.NULL,
AvroSchema.builder()
.type(AvroSchemaType.LONG)
.logicalType(LogicalType.TIMESTAMP_MILLIS)
.logicalType(AvroSchemaLogicalType.TIMESTAMP_MILLIS)
.build()
)
)
Expand Down Expand Up @@ -187,7 +188,7 @@ class AvroSchemasProvider {
.type(
AvroSchema.builder()
.type(AvroSchemaType.STRING)
.logicalType(AvroSchema.LogicalType.UUID)
.logicalType(AvroSchemaLogicalType.UUID)
.build()
)
.build(),
Expand All @@ -196,7 +197,7 @@ class AvroSchemasProvider {
.type(
AvroSchema.builder()
.type(AvroSchemaType.LONG)
.logicalType(AvroSchema.LogicalType.TIMESTAMP_MILLIS)
.logicalType(AvroSchemaLogicalType.TIMESTAMP_MILLIS)
.build()
)
.build(),
Expand Down Expand Up @@ -230,7 +231,7 @@ class AvroSchemasProvider {
.type(
AvroSchema.builder()
.type(AvroSchemaType.LONG)
.logicalType(AvroSchema.LogicalType.TIMESTAMP_MILLIS)
.logicalType(AvroSchemaLogicalType.TIMESTAMP_MILLIS)
.build()
)
.build(),
Expand Down Expand Up @@ -930,7 +931,7 @@ class AvroSchemasProvider {
.type(
AvroSchema.builder()
.type(AvroSchemaType.INT)
.logicalType(AvroSchema.LogicalType.DATE)
.logicalType(AvroSchemaLogicalType.DATE)
.build()
)
.name("d")
Expand All @@ -939,7 +940,7 @@ class AvroSchemasProvider {
.type(
AvroSchema.builder()
.type(AvroSchemaType.INT)
.logicalType(AvroSchema.LogicalType.TIME_MILLIS)
.logicalType(AvroSchemaLogicalType.TIME_MILLIS)
.build()
)
.name("t")
Expand All @@ -948,7 +949,7 @@ class AvroSchemasProvider {
.type(
AvroSchema.builder()
.type(AvroSchemaType.LONG)
.logicalType(AvroSchema.LogicalType.TIMESTAMP_MILLIS)
.logicalType(AvroSchemaLogicalType.TIMESTAMP_MILLIS)
.build()
)
.name("ts")
Expand All @@ -957,7 +958,7 @@ class AvroSchemasProvider {
.type(
AvroSchema.builder()
.type(AvroSchemaType.BYTES)
.logicalType(AvroSchema.LogicalType.BIG_DECIMAL)
.logicalType(AvroSchemaLogicalType.BIG_DECIMAL)
.build()
)
.name("bd")
Expand Down Expand Up @@ -1008,7 +1009,7 @@ class AvroSchemasProvider {
AvroSchemaType.NULL,
AvroSchema.builder()
.type(AvroSchemaType.BYTES)
.logicalType(LogicalType.DECIMAL)
.logicalType(AvroSchemaLogicalType.DECIMAL)
.precision(31)
.scale(8)
.build()
Expand Down Expand Up @@ -1046,7 +1047,7 @@ class AvroSchemasProvider {
AvroSchemaUnion(
AvroSchemaType.STRING, AvroSchema.builder()
.type(AvroSchemaType.LONG)
.logicalType(LogicalType.TIMESTAMP_MILLIS)
.logicalType(AvroSchemaLogicalType.TIMESTAMP_MILLIS)
.build()
)
)
Expand Down

0 comments on commit 474edd0

Please sign in to comment.