[ 
https://issues.apache.org/jira/browse/BEAM-13960?focusedWorklogId=734119&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734119
 ]

ASF GitHub Bot logged work on BEAM-13960:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 28/Feb/22 19:25
            Start Date: 28/Feb/22 19:25
    Worklog Time Spent: 10m 
      Work Description: TheNeuralBit commented on a change in pull request 
#16875:
URL: https://github.com/apache/beam/pull/16875#discussion_r816185122



##########
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:
       Sorry my question was why do we need an alternate method at all. 
Couldn't these calls use the standard `logicalTypeFromProto` to encode the base 
type in the same way?




-- 
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 734119)
    Time Spent: 5h 40m  (was: 5.5h)

> SchemaTranslation.RowToProto does not properly handle all types
> ---------------------------------------------------------------
>
>                 Key: BEAM-13960
>                 URL: https://issues.apache.org/jira/browse/BEAM-13960
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Lara Schmidt
>            Assignee: Lara Schmidt
>            Priority: P2
>          Time Spent: 5h 40m
>  Remaining Estimate: 0h
>
> It doesn't properly handle logical types, nulls, datetime or decimal.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to