(Scriptable object, Schema schema, int depth)
| 324 | ///////////////////////// |
| 325 | |
| 326 | private Tuple jsToPigTuple(Scriptable object, Schema schema, int depth) throws FrontendException, ExecException { |
| 327 | debugConvertJSToPig(depth, "Tuple", object, schema); |
| 328 | Tuple t = TupleFactory.getInstance().newTuple(schema.size()); |
| 329 | for (int i = 0; i < schema.size(); i++) { |
| 330 | FieldSchema field = schema.getField(i); |
| 331 | if (object.has(field.alias, jsScriptEngine.getScope())) { |
| 332 | Object attr = object.get(field.alias, object); |
| 333 | Object value; |
| 334 | if (field.type == DataType.BAG) { |
| 335 | value = jsToPigBag((Scriptable)attr, field.schema, depth + 1); |
| 336 | } else if (field.type == DataType.TUPLE) { |
| 337 | value = jsToPigTuple((Scriptable)attr, field.schema, depth + 1); |
| 338 | } else if (field.type == DataType.MAP) { |
| 339 | value = jsToPigMap((Scriptable)attr, field.schema, depth + 1); |
| 340 | } else if (attr instanceof NativeJavaObject) { |
| 341 | value = ((NativeJavaObject)attr).unwrap(); |
| 342 | } else if (attr instanceof Undefined) { |
| 343 | value = null; |
| 344 | } else { |
| 345 | value = attr; |
| 346 | } |
| 347 | t.set(i, value); |
| 348 | } else { |
| 349 | if (LOG.isDebugEnabled()) { |
| 350 | LOG.debug("X( "+field.alias+" NOT FOUND"); |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | debugReturn(depth, t); |
| 355 | return t; |
| 356 | } |
| 357 | |
| 358 | private Object jsToPigMap(Scriptable object, Schema schema, int depth) { |
| 359 | debugConvertJSToPig(depth, "Map", object, schema); |
no test coverage detected