@Test public void test() { SubString udf = new SubString(null); assertTrue(udf.evaluate("abc", 0, 2).equals("ab")); assertTrue(udf.evaluate("abc", 1, 2).equals("ab")); assertTrue(udf.evaluate("abc", -1, 1).equals("c")); assertTrue(udf.evaluate("abc", 2, -1).equals("")); assertTrue(udf.evaluate("abc\t", 3, 2).equals("c\t")); assertTrue(udf.evaluate("abcd\t", 2, 4).equals("bcd\t")); assertTrue(udf.evaluate("abcd ", 2, 4).equals("bcd ")); assertTrue(udf.evaluate("abcd", 0, 2).equals("ab")); }
public String evaluate(String s, int pos, int len) { if (s == null) { return null; } if (len <= 0) { return ""; } int[] idx = makeIndex(pos, len, s.length()); if (idx == null) { return ""; } return new String(s.toString().substring(idx[0], idx[1])); }
SubString extends UDF { public String evaluate(String s, int pos, int len) { if (s == null) { return null; } if (len <= 0) { return ""; } int[] idx = makeIndex(pos, len, s.length()); if (idx == null) { return ""; } return new String(s.toString().substring(idx[0], idx[1])); } }
SubString extends UDF { public String evaluate(String s, int pos, int len) { if (s == null) { return null; } if (len <= 0) { return ""; } int[] idx = makeIndex(pos, len, s.length()); if (idx == null) { return ""; } return new String(s.toString().substring(idx[0], idx[1])); } SubString(Map<String, String> config); }
SubString extends UDF { public String evaluate(String s, int pos, int len) { if (s == null) { return null; } if (len <= 0) { return ""; } int[] idx = makeIndex(pos, len, s.length()); if (idx == null) { return ""; } return new String(s.toString().substring(idx[0], idx[1])); } SubString(Map<String, String> config); String evaluate(String s, int pos, int len); String evaluate(String s, int pos); }
SubString extends UDF { public String evaluate(String s, int pos, int len) { if (s == null) { return null; } if (len <= 0) { return ""; } int[] idx = makeIndex(pos, len, s.length()); if (idx == null) { return ""; } return new String(s.toString().substring(idx[0], idx[1])); } SubString(Map<String, String> config); String evaluate(String s, int pos, int len); String evaluate(String s, int pos);  }