converts a tuple to javascript object based on a schema @param tuple the tuple to convert @param schema the schema to use for conversion @param depth call depth used for debugging messages @return the resulting javascript object
(Tuple tuple, Schema schema, int depth)
| 249 | * @return the resulting javascript object |
| 250 | */ |
| 251 | @SuppressWarnings("unchecked") |
| 252 | private Scriptable pigTupleToJS(Tuple tuple, Schema schema, int depth) throws FrontendException, ExecException { |
| 253 | debugConvertPigToJS(depth, "Tuple", tuple, schema); |
| 254 | Scriptable object = null; |
| 255 | if (tuple != null) { |
| 256 | object = jsScriptEngine.jsNewObject(); |
| 257 | |
| 258 | for (int i = 0; i < schema.size(); i++) { |
| 259 | FieldSchema field = schema.getField(i); |
| 260 | Object value; |
| 261 | if (field.type == DataType.BAG) { |
| 262 | value = pigBagToJS((DataBag)tuple.get(i), field.schema, depth + 1); |
| 263 | } else if (field.type == DataType.TUPLE) { |
| 264 | value = pigTupleToJS((Tuple)tuple.get(i), field.schema, depth + 1); |
| 265 | } else if (field.type == DataType.MAP) { |
| 266 | value = pigMapToJS((Map<String, Object>)tuple.get(i), field.schema, depth + 1); |
| 267 | } else { |
| 268 | debugConvertPigToJS(depth+1, "value", tuple.get(i), field.schema); |
| 269 | value = Context.javaToJS(tuple.get(i), jsScriptEngine.getScope()); |
| 270 | debugReturn(depth + 1, value); |
| 271 | } |
| 272 | object.put(field.alias, object, value); |
| 273 | } |
| 274 | } |
| 275 | debugReturn(depth, object); |
| 276 | return object; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * converts a map to javascript object based on a schema |
no test coverage detected