Abacn commented on code in PR #31802:
URL: https://github.com/apache/beam/pull/31802#discussion_r1672837669


##########
sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java:
##########
@@ -48,8 +50,38 @@ static List<Schema.Field> mapFieldPositions(CSVFormat 
format, Schema schema) {
    * Parse the given {@link String} cell of the CSV record based on the given 
field's {@link
    * Schema.FieldType}.
    */
-  // TODO(https://github.com/apache/beam/issues/31719): implement method.
   static Object parseCell(String cell, Schema.Field field) {
-    return "";
+    Schema.FieldType fieldType = field.getType();
+    try {
+      switch (fieldType.getTypeName()) {
+        case STRING:
+          return cell;
+        case INT16:
+          return Short.parseShort(cell);
+        case INT32:
+          return Integer.parseInt(cell);
+        case INT64:
+          return Long.parseLong(cell);
+        case BOOLEAN:
+          return Boolean.parseBoolean(cell);
+        case BYTE:
+          return Byte.parseByte(cell);
+        case DECIMAL:
+          return new BigDecimal(cell);
+        case DOUBLE:
+          return Double.parseDouble(cell);
+        case FLOAT:
+          return Float.parseFloat(cell);
+        case DATETIME:
+          return Instant.parse(cell);
+        default:
+          throw new IllegalArgumentException(

Review Comment:
   Consider UnsupportedOperationException ? Otherwise it will be caught in 
outer try block and throw again, which is redundant



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

Reply via email to