public void execute(final ExecuteContext context) throws Exception { jruby.callMethod(script, "call", context); }
@Override public DependencyData newDependencyData(InputStream dependency, String name, long modified) { return container.callMethod(dependencyDataImplClass, "new", new Object[]{dependency, name, modified}, DependencyData.class); } }
@SuppressWarnings("unchecked") public static synchronized Map<String, Map<String, String>> invokeReduce(ScriptingContainer container, Object rubyReceiver, String key, Iterable<ObjectWritable> values, Map<String, Object> params) throws ScriptException { // TODO- see if we can possibly deprecate the one without params if (params == null) { return (Map<String, Map<String, String>>) container.callMethod(rubyReceiver, "reduce", key, values); } else { return (Map<String, Map<String, String>>) container.callMethod(rubyReceiver, "reduce", key, values, params); } }
public static synchronized RubyArray invokeMap(ScriptingContainer container, Object rubyReceiver, String rowKey, Map<String, String> columns, Emitter emitter, Map<String, Object> params) throws ScriptException { // TODO- see if we can possibly deprecate the one without params if (params == null) { return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns, emitter); } else { return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns, emitter, params); } }
@SuppressWarnings("unchecked") public static synchronized Map<String, Map<String, String>> invokeReduce(ScriptingContainer container, Object rubyReceiver, String key, List<Object> values, Map<String, Object> params) throws ScriptException { // TODO- see if we can possibly deprecate the one without params if (params == null) { return (Map<String, Map<String, String>>) container.callMethod(rubyReceiver, "reduce", key, values); } else { return (Map<String, Map<String, String>>) container.callMethod(rubyReceiver, "reduce", key, values, params); } } }
public static synchronized RubyArray invokeMap(ScriptingContainer container, Object rubyReceiver, String rowKey, Map<String, String> columns, Map<String, Object> params) throws ScriptException { // TODO- see if we can possibly deprecate the one without params if (params == null) { return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns); } else { return (RubyArray) container.callMethod(rubyReceiver, "map", rowKey, columns, params); } }
public void rakeMethod(String method, Object... args) throws BuildException { try { container.callMethod(rakeWrapper, method, args); } catch(Exception e) { throw new BuildException("Build failed: " + e.getMessage(), e); } } }
public void rakeMethod(String method, Object... args) throws BuildException { try { container.callMethod(rakeWrapper, method, args); } catch(Exception e) { throw new BuildException("Build failed: " + e.getMessage(), e); } } }
public void rakeMethod(String method, Object... args) throws BuildException { try { container.callMethod(rakeWrapper, method, args); } catch(Exception e) { throw new BuildException("Build failed: " + e.getMessage(), e); } } }
public void rakeMethod(String method, Object... args) throws BuildException { try { container.callMethod(rakeWrapper, method, args); } catch(Exception e) { throw new BuildException("Build failed: " + e.getMessage(), e); } } }
public Script parseScript(URL path) throws IOException { try { String template = IOUtils.toString(path.openStream(), "UTF-8"); return (Script) container.callMethod(scriptClass, "new", template); } catch (Exception e) { throw (IOException) new IOException("Failed to parse "+path).initCause(e); } } }
/** * This function intializes the object that receives method calls, and the class object that * has schema information. While this is only 3 lines, it is split out so that the schema * function can initialize it if necessary. The class object is pulled from the ruby script * registered at the path per the RubyFunctions helper methods. */ private void initialize() { classObject = RubyFunctions.getFunctions("accumulator", path).get(methodName); methodReceiver = rubyEngine.callMethod(classObject, "new"); isInitialized = true; }
/** * This method calls "get" on the AccumulatorPigUdf Ruby class that was specified. */ @Override public Object getValue() { IRubyObject rubyResult = rubyEngine.callMethod(methodReceiver, "get", IRubyObject.class); try { return PigJrubyLibrary.rubyToPig(rubyResult); } catch (ExecException e) { throw new RuntimeException("Unable to convert result from Ruby to Pig: " + rubyResult, e); } }
/** * create a new ruby object of the bundler command */ private static Object newScript(final ScriptingContainer scriptingContainer) { IRubyObject runnerClass = scriptingContainer.parse(PathType.CLASSPATH, "nexus/bundle_runner.rb").run(); return scriptingContainer.callMethod(runnerClass, "new", IRubyObject.class); }
/** * create a new ruby object of the bundler command */ private static Object newScript(final ScriptingContainer scriptingContainer) { IRubyObject runnerClass = scriptingContainer.parse(PathType.CLASSPATH, "nexus/bundle_runner.rb").run(); return scriptingContainer.callMethod(runnerClass, "new", IRubyObject.class); }
/** * This method uses the schema method of the function encapsulation object to get the Schema information for * the Ruby method. */ @Override public Schema outputSchema(Schema input) { if (!isInitialized) initialize(); RubySchema rs = PigJrubyLibrary.pigToRuby(ruby, input); return PigJrubyLibrary.rubyToPig(rubyEngine.callMethod(funcInfoEncapsulator, "schema", new Object[]{rs, funcReceiver}, RubySchema.class)); } }
/** * This provides the Schema of the output, and leverages the get_output_schema function on the class object * that is defined on the ruby side. */ @Override public Schema outputSchema(Schema input) { if (!isInitialized) initialize(); RubySchema rs = PigJrubyLibrary.pigToRuby(ruby, input); return PigJrubyLibrary.rubyToPig(rubyEngine.callMethod(classObject, "get_output_schema", rs, RubySchema.class)); } }
/** * This uses the "exec" method required of AccumulatorPigUdf Ruby classes. It streams the data bags * it receives through the exec method defined on the registered class. */ @Override public void accumulate(Tuple b) throws IOException { if (!isInitialized) initialize(); RubyDataBag db = new RubyDataBag(ruby, ruby.getClass("DataBag"), (DataBag)b.get(0)); rubyEngine.callMethod(methodReceiver, "exec", db, IRubyObject.class); }
@Override public Tuple exec(Tuple input) throws IOException { if (!isInitialized()) initialize(); try { IRubyObject inp = PigJrubyLibrary.pigToRuby(ruby, ((DataBag)input.get(0)).iterator().next().get(0)); IRubyObject rubyResult = rubyEngine.callMethod(getReceiver(), getStage(), inp, IRubyObject.class); return mTupleFactory.newTuple(PigJrubyLibrary.rubyToPig(rubyResult)); } catch (Exception e) { throw new IOException("Error executing initial function", e); } } }
@Override public Tuple exec(Tuple input) throws IOException { if (!isInitialized()) initialize(); try { RubyDataBag inp = new RubyDataBag(ruby, ruby.getClass("DataBag"), (DataBag)input.get(0)); IRubyObject rubyResult = rubyEngine.callMethod(getReceiver(), getStage(), inp, IRubyObject.class); return mTupleFactory.newTuple(PigJrubyLibrary.rubyToPig(rubyResult)); } catch (Exception e) { throw new IOException("Error executing intermediate function: ", e); } } }