@Udf(description = "Converts a string representation of a date in the given format"
      + " into the number of milliseconds since 1970-01-01 00:00:00 UTC/GMT."
      + " 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.")
  public long stringToTimestamp(
      @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) {
    // NB: We do not perform a null here preferring to throw an exception as
    // there is no sentinel value for a "null" Date.
    try {
      final StringToTimestampParser timestampParser = parsers.get(formatPattern);
      return timestampParser.parse(formattedTimestamp);
    } catch (final ExecutionException | RuntimeException e) {
      throw new KsqlFunctionException("Failed to parse timestamp '" + formattedTimestamp
           + "' with formatter '" + formatPattern
          + "': " + e.getMessage(), e);
    }
  }
@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 long result = udf.stringToTimestamp(sourceDate, pattern);
            final long expectedResult = new SimpleDateFormat(pattern).parse(sourceDate).getTime();
            assertThat(result, is(expectedResult));
          } catch (final Exception e) {
            fail(e.getMessage());
          }
        });
  }