DanielMorales9 commented on code in PR #32688:
URL: https://github.com/apache/beam/pull/32688#discussion_r1791946498
##########
sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/IcebergUtils.java:
##########
@@ -282,12 +306,24 @@ private static void copyFieldIntoRecord(Record rec,
Types.NestedField field, Row
Optional.ofNullable(value.getDouble(name)).ifPresent(v ->
rec.setField(name, v));
break;
case DATE:
- throw new UnsupportedOperationException("Date fields not yet
supported");
+ Optional.ofNullable(value.getLogicalTypeValue(name, LocalDate.class))
+ .ifPresent(v -> rec.setField(name, v));
+ break;
case TIME:
- throw new UnsupportedOperationException("Time fields not yet
supported");
+ Optional.ofNullable(value.getLogicalTypeValue(name, LocalTime.class))
+ .ifPresent(v -> rec.setField(name, v));
+ break;
case TIMESTAMP:
- Optional.ofNullable(value.getDateTime(name))
- .ifPresent(v -> rec.setField(name, v.getMillis()));
+ Object val = value.getValue(name);
+ if (val instanceof Instant) { // case Schema.FieldType.DATETIME
+ rec.setField(name, DateTimeUtil.timestampFromMicros(((Instant)
val).getMillis()));
Review Comment:
`DateTimeUtil.timestampFromMicros` expect microseconds, but you're passing
milliseconds. If it expects microseconds, you may need to convert milliseconds
to microseconds.
Counter-proof:
```
import org.apache.iceberg.util.DateTimeUtil;
import org.joda.time.Instant;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.time.LocalDateTime;
import java.time.ZoneId;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@RunWith(JUnit4.class)
public class DateTimeUtilsTest {
@Test
public void when_DatetimeUtils_TimestampFromMicros_Receives_A_Millis() {
String timestampStr = "2024-10-07T12:34:56Z";
Instant instant = Instant.parse(timestampStr);
LocalDateTime actual =
DateTimeUtil.timestampFromMicros(instant.getMillis());
java.time.Instant javaInstant =
java.time.Instant.parse(timestampStr);
LocalDateTime expected = LocalDateTime.ofInstant(javaInstant,
ZoneId.of("UTC"));
assertThat(actual, equalTo(expected));
}
}
```
Outcome:
```
java.lang.AssertionError:
Expected: <2024-10-07T12:34:56>
but: was <1970-01-21T00:05:04.496>
--
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]