public PartitionMetadata from(Struct row) {
    return PartitionMetadata.newBuilder()
        .setPartitionToken(row.getString(COLUMN_PARTITION_TOKEN))
        .setParentTokens(Sets.newHashSet(row.getStringList(COLUMN_PARENT_TOKENS)))
        .setStartTimestamp(row.getTimestamp(COLUMN_START_TIMESTAMP))
        .setEndTimestamp(row.getTimestamp(COLUMN_END_TIMESTAMP))
        .setHeartbeatMillis(row.getLong(COLUMN_HEARTBEAT_MILLIS))
        .setState(State.valueOf(row.getString(COLUMN_STATE)))
        .setWatermark(row.getTimestamp(COLUMN_WATERMARK))
        .setCreatedAt(row.getTimestamp(COLUMN_CREATED_AT))
        .setScheduledAt(
            !row.isNull(COLUMN_SCHEDULED_AT) ? row.getTimestamp(COLUMN_SCHEDULED_AT) : null)
        .setRunningAt(!row.isNull(COLUMN_RUNNING_AT) ? row.getTimestamp(COLUMN_RUNNING_AT) : null)
        .setFinishedAt(
            !row.isNull(COLUMN_FINISHED_AT) ? row.getTimestamp(COLUMN_FINISHED_AT) : null)
        .build();
  }
@Test
  public void testMapPartitionMetadataFromResultSet() {
    final Struct row =
        Struct.newBuilder()
            .set(COLUMN_PARTITION_TOKEN)
            .to("token")
            .set(COLUMN_PARENT_TOKENS)
            .toStringArray(Collections.singletonList("parentToken"))
            .set(COLUMN_START_TIMESTAMP)
            .to(Timestamp.ofTimeMicroseconds(10L))
            .set(COLUMN_END_TIMESTAMP)
            .to(Timestamp.ofTimeMicroseconds(20L))
            .set(COLUMN_HEARTBEAT_MILLIS)
            .to(5_000L)
            .set(COLUMN_STATE)
            .to(State.RUNNING.name())
            .set(COLUMN_WATERMARK)
            .to(Timestamp.ofTimeMicroseconds(30L))
            .set(COLUMN_CREATED_AT)
            .to(Timestamp.ofTimeMicroseconds(40L))
            .set(COLUMN_SCHEDULED_AT)
            .to(Timestamp.ofTimeMicroseconds(50L))
            .set(COLUMN_RUNNING_AT)
            .to(Timestamp.ofTimeMicroseconds(60L))
            .set(COLUMN_FINISHED_AT)
            .to(Timestamp.ofTimeMicroseconds(70L))
            .build();

    final PartitionMetadata partition = mapper.from(row);

    assertEquals(
        new PartitionMetadata(
            "token",
            Sets.newHashSet("parentToken"),
            Timestamp.ofTimeMicroseconds(10L),
            Timestamp.ofTimeMicroseconds(20L),
            5_000L,
            State.RUNNING,
            Timestamp.ofTimeMicroseconds(30),
            Timestamp.ofTimeMicroseconds(40),
            Timestamp.ofTimeMicroseconds(50),
            Timestamp.ofTimeMicroseconds(60),
            Timestamp.ofTimeMicroseconds(70)),
        partition);
  }