如何在IBM Streams Java Application Api中使用RScript运算符?

时间:2015-11-09 09:57:29

标签: java r api infosphere-spl ibm-streams

我正在IBM Streams中探索Java Application Api,因此看起来很有希望。我能够创建拓扑并在分布式模式下独立运行它们。

现在我试图了解如何从Java拓扑中调用R脚本。我想的一种方法是在我的Java拓扑中使用com.ibm.streams.rproject :: RScript运算符。

这是我的完整代码:

SPLStream tuples = testTupleStream(topology);

        //tuples.print();
        topology.createSubmissionParameter("rCommand", "/usr/local/bin/R --vanilla");



        // Filter on the vi attribute, passing the value 321.
        Map<String,Object> params = new HashMap<>();
        params.put("rObjects", "first, second");
        params.put("rScriptFileName", "./etc/print.r");
        params.put("streamAttributes", "number1, number2");

        //params.put("filter", SPL.createValue(" vi == 321 ", MetaType.BOOLEAN));
        SPL.createSubmissionParameter(topology, "rsample", SPL.createValue(true, MetaType.BOOLEAN), true);

        //String toolkitRoot = "/opt/ibm/InfoSphere_Streams/4.0.1.0/toolkits";
        //SPL.addToolkit(tuples, new File(toolkitRoot));
        SPLStream int32Filtered = SPL.invokeOperator("rsampleoperator","com.ibm.streams.rproject::RScript", tuples, tuples.getSchema(), params);
        int32Filtered.print();

但是当我在拓扑结构上运行时,我收到以下错误:

        09 Nov 2015 04:09:53.234 [5407] ERROR #splapptrc,J[5],P[5],rsampleoperator,spl_pe M[PEImpl.cpp:process:841]  - CDISR5079E: An exception occurred during the processing of the processing element. The error is: An operator was attempting to access the data directory and no data directory has been specified..
09 Nov 2015 04:09:53.241 [5407] ERROR #splapptrc,J[5],P[5],rsampleoperator,spl_operator M[PEImpl.cpp:process:872]  - CDISR5053E: Runtime failures occurred in the following operators: rsampleoperator.

你能告诉我我做错了什么吗? 在Java API中使用SPL操作符的任何见解都会有帮助吗?

由于 Sudheer

1 个答案:

答案 0 :(得分:0)

由于这是Java Application API,我认为您必须将数据目录属性设置为作业属性的一部分:

http://ibmstreams.github.io/streamsx.topology/doc/javadoc/com/ibm/streamsx/topology/context/JobProperties.html

然后可以在提交作业时将属性传递给上下文:StreamsContext.submit(com.ibm.streamsx.topology.Topology,java.util.Map)

还有一个Java Application API开发指南,您可以在这里找到它: http://ibmstreams.github.io/streamsx.documentation/docs/4.1/java/java-appapi-devguide/

希望这有帮助。

萨曼莎