@Udf(description = "Converts a string representation of a date in the given format"
      + " into the TIMESTAMP value."
      + " Single quotes in the timestamp format can be escaped with '',"
      + " for example: 'yyyy-MM-dd''T''HH:mm:ssX'.")
  public Timestamp parseTimestamp(
      @UdfParameter(
          description = "The string representation of a date.") final String formattedTimestamp,
      @UdfParameter(
          description = "The format pattern should be in the format expected by"
              + " java.time.format.DateTimeFormatter.") final String formatPattern) {
    return parseTimestamp(formattedTimestamp, formatPattern, ZoneId.of("GMT").getId());
  }
@Test
  public void shouldWorkWithManyDifferentFormatters() {
    IntStream.range(0, 10_000)
        .parallel()
        .forEach(idx -> {
          try {
            final String sourceDate = "2018-12-01 10:12:13.456X" + idx;
            final String pattern = "yyyy-MM-dd HH:mm:ss.SSS'X" + idx + "'";
            final Timestamp result = udf.parseTimestamp(sourceDate, pattern);
            final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
            final Timestamp expectedResult = Timestamp.from(sdf.parse(sourceDate).toInstant());
            assertThat(result, is(expectedResult));
          } catch (final Exception e) {
            fail(e.getMessage());
          }
        });
  }