use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class AutoArimaStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
MemSourceStreamOp source = new MemSourceStreamOp(mTableData, new String[] { "id", "ts", "val" });
CollectSinkStreamOp resultOp = source.link(new OverCountWindowStreamOp().setPartitionCols("id").setTimeCol("ts").setPrecedingRows(5).setClause("mtable_agg_preceding(ts, val) as data")).link(new AutoArimaStreamOp().setValueCol("data").setPredictionCol("predict").setPredictNum(12)).link(new LookupValueInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("predict").setOutputCol("out")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> sResult = resultOp.getAndRemoveValues();
sResult.sort(new RowComparator(1));
Assert.assertEquals(10, sResult.size());
Assert.assertEquals(11.0, (Double) sResult.get(2).getField(5), 10e-5);
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class HoltWintersStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
MemSourceStreamOp source = new MemSourceStreamOp(mTableData, new String[] { "id", "ts", "val" });
CollectSinkStreamOp resultOp = source.link(new OverCountWindowStreamOp().setPartitionCols("id").setTimeCol("ts").setPrecedingRows(5).setClause("mtable_agg_preceding(ts, val) as data")).link(new HoltWintersStreamOp().setValueCol("data").setPredictionCol("predict").setPredictNum(12)).link(new LookupValueInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("predict").setOutputCol("out")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> sResult = resultOp.getAndRemoveValues();
sResult.sort(new RowComparator(1));
Assert.assertEquals(10, sResult.size());
Assert.assertEquals(12.0000, (Double) sResult.get(3).getField(5), 10e-5);
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class LookupValueInTimeSeriesStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(new Timestamp(1), 10.0), Row.of(new Timestamp(2), 11.0), Row.of(new Timestamp(3), 12.0), Row.of(new Timestamp(4), 13.0), Row.of(new Timestamp(5), 14.0), Row.of(new Timestamp(6), 15.0), Row.of(new Timestamp(7), 16.0), Row.of(new Timestamp(8), 17.0), Row.of(new Timestamp(9), 18.0), Row.of(new Timestamp(10), 19.0));
MTable mtable = new MTable(mTableData, "ts timestamp, val double");
MemSourceStreamOp source = new MemSourceStreamOp(new Object[][] { { 1, new Timestamp(5), mtable } }, new String[] { "id", "ts", "data" });
CollectSinkStreamOp resultOp = source.link(new LookupValueInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("data").setOutputCol("out")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> sResult = resultOp.getAndRemoveValues();
Assert.assertEquals(1, sResult.size());
Assert.assertEquals(14.0000, (Double) sResult.get(0).getField(3), 10e-5);
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class ShiftStreamOpTest method test.
@Test
public void test() throws Exception {
List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
MemSourceStreamOp source = new MemSourceStreamOp(mTableData, new String[] { "id", "ts", "val" });
CollectSinkStreamOp resultOp = source.link(new OverCountWindowStreamOp().setPartitionCols("id").setTimeCol("ts").setPrecedingRows(5).setClause("mtable_agg_preceding(ts, val) as data")).link(new ShiftStreamOp().setValueCol("data").setShiftNum(7).setPredictNum(12).setPredictionCol("predict")).link(new LookupValueInTimeSeriesStreamOp().setTimeCol("ts").setTimeSeriesCol("predict").setOutputCol("out").setReservedCols("ts")).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> sResult = resultOp.getAndRemoveValues();
sResult.sort(new RowComparator(1));
Assert.assertEquals(10, sResult.size());
Assert.assertEquals("10.0", sResult.get(1).getField(1).toString());
}
use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.
the class WriteTensorToImageStreamOpTest method testWriteTensorToImageStreamOp.
@Test
public void testWriteTensorToImageStreamOp() throws Exception {
List<Row> data = Collections.singletonList(Row.of("sphx_glr_plot_scripted_tensor_transforms_001.png"));
MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "path string");
ReadImageToTensorStreamOp readImageToTensorStreamOp = new ReadImageToTensorStreamOp().setRootFilePath("http://alink-test-datatset.oss-cn-hangzhou-zmf.aliyuncs.com/images/").setRelativeFilePathCol("path").setOutputCol("tensor");
WriteTensorToImageStreamOp writeTensorToImageStreamOp = new WriteTensorToImageStreamOp().setRootFilePath("/tmp/write_tensor_to_image").setTensorCol("tensor").setImageType(ImageType.PNG).setRelativeFilePathCol("path");
CollectSinkStreamOp collectSinkStreamOp = memSourceStreamOp.link(readImageToTensorStreamOp).link(writeTensorToImageStreamOp).link(new CollectSinkStreamOp());
StreamOperator.execute();
List<Row> rows = collectSinkStreamOp.getAndRemoveValues();
Assert.assertEquals(1, rows.size());
}
Aggregations