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

Method exec

src/org/apache/pig/scripting/js/JsFunction.java:197–232  ·  view source on GitHub ↗
(Tuple tuple)

Source from the content-addressed store, hash-verified

195 ///////////////////////////
196
197 @Override
198 public Object exec(Tuple tuple) throws IOException {
199 Schema inputSchema = this.getInputSchema();
200 if (LOG.isDebugEnabled()) {
201 LOG.debug( "CALL " + stringify(outputSchema) + " " + functionName + " " + stringify(inputSchema));
202 }
203 // UDF always take a tuple: unwrapping when not necessary to simplify UDFs
204 if (inputSchema.size() == 1 && inputSchema.getField(0).type == DataType.TUPLE) {
205 inputSchema = inputSchema.getField(0).schema;
206 }
207
208 Scriptable params = pigTupleToJS(tuple, inputSchema, 0);
209
210 Object[] passedParams = new Object[inputSchema.size()];
211 for (int j = 0; j < passedParams.length; j++) {
212 passedParams[j] = params.get(inputSchema.getField(j).alias, params);
213 }
214
215 Object result = jsScriptEngine.jsCall(functionName, passedParams);
216 if (LOG.isDebugEnabled()) {
217 LOG.debug( "call "+functionName+"("+Arrays.toString(passedParams)+") => "+toString(result));
218 }
219
220 // We wrap the result with an object in the following cases:
221 // 1. Result is not an object type.
222 // 2. OutputSchema is a tuple type.
223 if (!(result instanceof NativeObject) || outputSchema.getField(0).type == DataType.TUPLE) {
224 Scriptable wrapper = jsScriptEngine.jsNewObject();
225 wrapper.put(outputSchema.getField(0).alias, wrapper, result);
226 result = wrapper;
227 }
228 Tuple evalTuple = jsToPigTuple((Scriptable)result, outputSchema, 0);
229 Object eval = outputSchema.size() == 1 ? evalTuple.get(0) : evalTuple;
230 LOG.debug(eval);
231 return eval;
232 }
233
234 @Override
235 public Schema outputSchema(Schema input) {

Callers

nothing calls this directly

Calls 13

stringifyMethod · 0.95
sizeMethod · 0.95
getFieldMethod · 0.95
pigTupleToJSMethod · 0.95
getMethod · 0.95
toStringMethod · 0.95
jsToPigTupleMethod · 0.95
getInputSchemaMethod · 0.80
debugMethod · 0.80
jsCallMethod · 0.80
jsNewObjectMethod · 0.80
sizeMethod · 0.65

Tested by

no test coverage detected