laraschmidt commented on a change in pull request #16875:
URL: https://github.com/apache/beam/pull/16875#discussion_r816207375
##########
File path:
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java
##########
@@ -411,26 +426,76 @@ public static Object rowFromProto(SchemaApi.Row row,
FieldType fieldType) {
.build();
case ROW:
return builder.setRowValue(rowToProto((Row) value)).build();
+ case DATETIME:
+ return builder
+ .setLogicalTypeValue(logicalTypeToProtoViaCoder(FieldType.INT64,
fieldType, value))
+ .build();
+ case DECIMAL:
+ return builder
+ .setLogicalTypeValue(logicalTypeToProtoViaCoder(FieldType.BYTES,
fieldType, value))
+ .build();
case LOGICAL_TYPE:
+ return builder
+
.setLogicalTypeValue(logicalTypeToProto(fieldType.getLogicalType(), value))
+ .build();
default:
return builder.setAtomicValue(primitiveRowFieldToProto(fieldType,
value)).build();
}
}
+ /** Returns if the given field is null and throws exception if it is and
can't be. */
+ static boolean isNullFieldValueFromProto(FieldType fieldType, boolean
hasNonNullValue) {
+ if (!hasNonNullValue && !fieldType.getNullable()) {
+ throw new RuntimeException("FieldTypeValue has no value but the field
cannot be null.");
+ }
+ return !hasNonNullValue;
+ }
+
static Object fieldValueFromProto(FieldType fieldType, SchemaApi.FieldValue
value) {
switch (fieldType.getTypeName()) {
case ARRAY:
+ if (isNullFieldValueFromProto(fieldType, value.hasArrayValue())) {
+ return null;
+ }
return arrayValueFromProto(fieldType.getCollectionElementType(),
value.getArrayValue());
case ITERABLE:
+ if (isNullFieldValueFromProto(fieldType, value.hasIterableValue())) {
+ return null;
+ }
return iterableValueFromProto(
fieldType.getCollectionElementType(), value.getIterableValue());
case MAP:
+ if (isNullFieldValueFromProto(fieldType, value.hasMapValue())) {
+ return null;
+ }
return mapFromProto(
fieldType.getMapKeyType(), fieldType.getMapValueType(),
value.getMapValue());
case ROW:
+ if (isNullFieldValueFromProto(fieldType, value.hasRowValue())) {
+ return null;
+ }
return rowFromProto(value.getRowValue(), fieldType);
case LOGICAL_TYPE:
+ if (isNullFieldValueFromProto(fieldType, value.hasLogicalTypeValue()))
{
+ return null;
+ }
+ return logicalTypeFromProto(fieldType.getLogicalType(), value);
+ case DATETIME:
+ if (isNullFieldValueFromProto(fieldType, value.hasLogicalTypeValue()))
{
+ return null;
+ }
+ return logicalTypeFromProtoViaCoder(
+ FieldType.INT64, fieldType, value.getLogicalTypeValue());
+ case DECIMAL:
+ if (isNullFieldValueFromProto(fieldType, value.hasLogicalTypeValue()))
{
+ return null;
+ }
+ return logicalTypeFromProtoViaCoder(
+ FieldType.BYTES, fieldType, value.getLogicalTypeValue());
Review comment:
No because they are not actual logical types. There's no LogicalType
defined for them which means we cannot call the ToBaseType and ToInputType on
them to convert like normal logical types. Instead they use the logical type
schema/row format but are not actual logical types.
--
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]