converts a bag to javascript object based on a schema @param bag the bag to convert @param schema the schema to use for conversion @param depth call depth used for debugging messages @return the resulting javascript object @throws FrontendException @throws ExecException
(DataBag bag, Schema schema, int depth)
| 304 | * @throws ExecException |
| 305 | */ |
| 306 | private Scriptable pigBagToJS(DataBag bag, Schema schema, int depth) throws FrontendException, ExecException { |
| 307 | debugConvertPigToJS(depth, "Bag", bag, schema); |
| 308 | if (schema.size() == 1 && schema.getField(0).type == DataType.TUPLE) { |
| 309 | // unwrapping as bags always contain a tuple |
| 310 | schema = schema.getField(0).schema; |
| 311 | } |
| 312 | Scriptable array = jsScriptEngine.jsNewArray(bag.size()); |
| 313 | array.setParentScope(jsScriptEngine.getScope()); |
| 314 | int i= 0; |
| 315 | for (Tuple t : bag) { |
| 316 | array.put(i++, array, pigTupleToJS(t, schema, depth + 1)); |
| 317 | } |
| 318 | debugReturn(depth, array); |
| 319 | return array; |
| 320 | } |
| 321 | |
| 322 | ///////////////////////// |
| 323 | // Conversion JS to Pig |
no test coverage detected