@Udf(description = "Converts a TIMESTAMP value into the"
      + " string representation of the timestamp in the given format. Single quotes in the"
      + " timestamp format can be escaped with '', for example: 'yyyy-MM-dd''T''HH:mm:ssX'"
      + " The system default time zone is used when no time zone is explicitly provided."
      + " The format pattern should be in the format expected"
      + " by java.time.format.DateTimeFormatter")
  public String formatTimestamp(
      @UdfParameter(
          description = "TIMESTAMP value.") final Timestamp timestamp,
      @UdfParameter(
          description = "The format pattern should be in the format expected by"
              + " java.time.format.DateTimeFormatter.") final String formatPattern) {
    return formatTimestamp(timestamp, formatPattern, ZoneId.of("GMT").getId());
  }
@Test
  public void shouldRoundTripWithParseTimestamp() {
    final String pattern = "yyyy-MM-dd HH:mm:ss.SSS'Freya'";
    final ParseTimestamp parseTimestamp = new ParseTimestamp();
    IntStream.range(-10_000, 20_000)
        .parallel()
        .forEach(idx -> {
          final Timestamp timestamp = new Timestamp(1538361611123L + idx);
          final String result = udf.formatTimestamp(timestamp, pattern);
          final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
          sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
          final String expectedResult = sdf.format(timestamp);
          assertThat(result, is(expectedResult));

          final Timestamp roundtripTimestamp = parseTimestamp.parseTimestamp(result, pattern);
          assertThat(roundtripTimestamp, is(timestamp));
        });
  }