|
22 | 22 | import io.cdap.cdap.api.common.Bytes; |
23 | 23 | import io.cdap.wrangler.api.Arguments; |
24 | 24 | import io.cdap.wrangler.api.Directive; |
25 | | -import io.cdap.wrangler.api.DirectiveExecutionException; |
26 | | -import io.cdap.wrangler.api.DirectiveParseException; |
27 | | -import io.cdap.wrangler.api.ErrorRowException; |
28 | 25 | import io.cdap.wrangler.api.ExecutorContext; |
29 | 26 | import io.cdap.wrangler.api.Row; |
30 | 27 | import io.cdap.wrangler.api.parser.ColumnName; |
@@ -53,27 +50,23 @@ public UsageDefinition define() { |
53 | 50 | } |
54 | 51 |
|
55 | 52 | @Override |
56 | | - public void initialize(Arguments args) |
57 | | - throws DirectiveParseException { |
| 53 | + public void initialize(Arguments args) { |
58 | 54 | column = ((ColumnName) args.value("column")).value(); |
59 | 55 | } |
60 | 56 |
|
61 | 57 | @Override |
62 | | - public List<Row> execute(List<Row> rows, ExecutorContext context) |
63 | | - throws DirectiveExecutionException, ErrorRowException { |
| 58 | + public List<Row> execute(List<Row> rows, ExecutorContext context) { |
64 | 59 | for (Row row : rows) { |
65 | 60 | int idx = row.find(column); |
66 | 61 | if (idx != -1) { |
67 | 62 | Object object = row.getValue(idx); |
68 | 63 | if (object instanceof String) { |
69 | | - if (object != null) { |
70 | | - String value = (String) object; |
71 | | - String reversed = new StringBuffer(value).reverse().toString(); |
72 | | - row.setValue(idx, reversed); |
73 | | - } |
| 64 | + String value = (String) object; |
| 65 | + String reversed = new StringBuilder(value).reverse().toString(); |
| 66 | + row.setValue(idx, reversed); |
74 | 67 | } else if (object instanceof byte[]) { |
75 | | - String value = Bytes.toString((byte[])object); |
76 | | - String reversed = new StringBuffer(value).reverse().toString(); |
| 68 | + String value = Bytes.toString((byte[]) object); |
| 69 | + String reversed = new StringBuilder(value).reverse().toString(); |
77 | 70 | row.setValue(idx, reversed); |
78 | 71 | } |
79 | 72 | } |
|
0 commit comments