@Udf
  public String lpad(
      @UdfParameter(description = "String to be padded") final String input,
      @UdfParameter(description = "Target length") final Integer targetLen,
      @UdfParameter(description = "Padding string") final String padding) {

    if (input == null) {
      return null;
    }
    if (padding == null || padding.isEmpty() || targetLen == null || targetLen < 0) {
      return null;
    }
    final StringBuilder sb = new StringBuilder(targetLen + padding.length());
    final int padUpTo = Math.max(targetLen - input.length(), 0);
    for (int i = 0; i < padUpTo; i += padding.length()) {
      sb.append(padding);
    }
    sb.setLength(padUpTo);
    sb.append(input);
    sb.setLength(targetLen);
    return sb.toString();
  }
@Test
  public void shouldPadInputString() {
    final String result = udf.lpad("foo", 7, "Bar");
    assertThat(result, is("BarBfoo"));
  }