TableSchemaParserFunction implements Function<String,Pair<String,String>> { @Override public Pair<String, String> apply(final String tableSchema) { Preconditions.checkNotNull(tableSchema); Preconditions.checkArgument(!tableSchema.isEmpty(), "HBase Table name is empty!!"); final String tokens[] = Iterables.toArray(Splitter.on(TABLE_COLUMN_DELIMITER). trimResults().omitEmptyStrings().split(tableSchema) , String.class); final String tableName = tokens[0]; String columns = null; if(tokens.length > 1) { columns = tokens[1]; } return new Pair<String, String>(tableName, columns); }  @Override Pair<String, String> apply(final String tableSchema);  }
@Test public void testTableSchema() { final String loadTableSchema = "EMPLOYEE/col1,col2"; final Pair<String,String> pair = function.apply(loadTableSchema); assertEquals("EMPLOYEE", pair.getFirst()); assertEquals(pair.getSecond(),Joiner.on(',').join("col1","col2")); }
@Test(expected=IllegalArgumentException.class) public void testEmptyTableSchema() { final String loadTableSchema = ""; function.apply(loadTableSchema); }
@Test public void testTableOnlySchema() { final String loadTableSchema = "EMPLOYEE"; final Pair<String,String> pair = function.apply(loadTableSchema); assertEquals("EMPLOYEE", pair.getFirst()); assertNull(pair.getSecond()); }