Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-12385] Handle VARCHAR and other SQL specific logical types in AvroUtils #14858

Closed
wants to merge 7 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,18 @@ private static org.apache.avro.Schema getFieldSchema(
.map(x -> getFieldSchema(x.getType(), x.getName(), namespace))
.collect(Collectors.toList()));
break;

case "NVARCHAR":
anantdamle marked this conversation as resolved.
Show resolved Hide resolved
case "VARCHAR":
case "LONGNVARCHAR":
case "LONGVARCHAR":
baseType = org.apache.avro.Schema.create(Type.STRING);
anantdamle marked this conversation as resolved.
Show resolved Hide resolved
break;

case "DATE":
baseType = LogicalTypes.date().addToSchema(org.apache.avro.Schema.create(Type.INT));
break;

default:
throw new RuntimeException(
"Unhandled logical type " + fieldType.getLogicalType().getIdentifier());
Expand Down Expand Up @@ -1017,6 +1029,16 @@ private static org.apache.avro.Schema getFieldSchema(
typeWithNullability.type.getTypes().get(oneOfValue.getCaseType().getValue()),
oneOfValue.getValue());
}

case "NVARCHAR":
anantdamle marked this conversation as resolved.
Show resolved Hide resolved
case "VARCHAR":
case "LONGNVARCHAR":
case "LONGVARCHAR":
return new Utf8((String) value);

case "DATE":
return Days.daysBetween(Instant.EPOCH, (Instant) value).getDays();

default:
throw new RuntimeException(
"Unhandled logical type " + fieldType.getLogicalType().getIdentifier());
Expand Down