Default implementation of format of tuple (each filed is delimited by tab) @param tuple @return Default format of Tuple
(Tuple tuple)
| 44 | * @return Default format of Tuple |
| 45 | */ |
| 46 | @SuppressWarnings("unchecked") |
| 47 | public static String format(Tuple tuple) { |
| 48 | StringBuilder sb = new StringBuilder(); |
| 49 | sb.append('('); |
| 50 | for (int i = 0; i < tuple.size(); ++i) { |
| 51 | try { |
| 52 | Object d = tuple.get(i); |
| 53 | if (d != null) { |
| 54 | if (d instanceof Map) { |
| 55 | sb.append(DataType.mapToString((Map<String, Object>) d)); |
| 56 | } else if (d instanceof Tuple) { |
| 57 | Tuple t = (Tuple) d; |
| 58 | sb.append(TupleFormat.format(t)); |
| 59 | } else if (d instanceof DataBag){ |
| 60 | DataBag bag=(DataBag)d; |
| 61 | sb.append(BagFormat.format(bag)); |
| 62 | } |
| 63 | else { |
| 64 | sb.append(d.toString()); |
| 65 | } |
| 66 | } else { |
| 67 | sb.append(""); |
| 68 | } |
| 69 | if (i != tuple.size() - 1) |
| 70 | sb.append(","); |
| 71 | } catch (ExecException e) { |
| 72 | e.printStackTrace(); |
| 73 | mLog.warn("Exception when format tuple", e); |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | sb.append(')'); |
| 78 | return sb.toString(); |
| 79 | } |
| 80 | } |