MCPcopy Create free account
hub / github.com/apache/pig / pigTupleToJS

Method pigTupleToJS

src/org/apache/pig/scripting/js/JsFunction.java:251–277  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

execMethod · 0.95
pigBagToJSMethod · 0.95

Calls 10

debugConvertPigToJSMethod · 0.95
pigBagToJSMethod · 0.95
pigMapToJSMethod · 0.95
debugReturnMethod · 0.95
jsNewObjectMethod · 0.80
sizeMethod · 0.65
getMethod · 0.65
getFieldMethod · 0.45
getScopeMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected