(Tuple tuple)
| 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) { |
nothing calls this directly
no test coverage detected