Search in sources :

Example 1 with OverCountWindowStreamOp

use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp 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);
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) RowComparator(com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator) Row(org.apache.flink.types.Row) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 2 with OverCountWindowStreamOp

use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp 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);
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) RowComparator(com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator) Row(org.apache.flink.types.Row) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 3 with OverCountWindowStreamOp

use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp 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());
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) RowComparator(com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator) Row(org.apache.flink.types.Row) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 4 with OverCountWindowStreamOp

use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.

the class DeepARPredictStreamOpTest method testDeepARTrainBatchOp.

@Test
public void testDeepARTrainBatchOp() throws Exception {
    BatchOperator.setParallelism(1);
    List<Row> data = Arrays.asList(Row.of(0, Timestamp.valueOf("2021-11-01 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-02 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-03 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-04 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-05 00:00:00"), 100.0));
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(data, "id int, ts timestamp, series double");
    MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "id int, ts timestamp, series double");
    DeepARTrainBatchOp deepARTrainBatchOp = new DeepARTrainBatchOp().setTimeCol("ts").setSelectedCol("series").setNumEpochs(10).setWindow(2).setStride(1).linkFrom(memSourceBatchOp);
    OverCountWindowStreamOp overCountWindowStreamOp = new OverCountWindowStreamOp().setClause("MTABLE_AGG_PRECEDING(ts, series) as mtable_agg_series").setTimeCol("ts").setPrecedingRows(2);
    DeepARPredictStreamOp deepARPredictStreamOp = new DeepARPredictStreamOp(deepARTrainBatchOp).setPredictNum(2).setPredictionCol("pred").setValueCol("mtable_agg_series");
    deepARPredictStreamOp.linkFrom(overCountWindowStreamOp.linkFrom(memSourceStreamOp).filter("ts = TO_TIMESTAMP('2021-11-05 00:00:00')")).print();
    StreamOperator.execute();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) DeepARPredictStreamOp(com.alibaba.alink.operator.stream.timeseries.DeepARPredictStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 5 with OverCountWindowStreamOp

use of com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp in project Alink by alibaba.

the class LSTNetPredictStreamOpTest method testLSTNetTrainBatchOp.

@Test
public void testLSTNetTrainBatchOp() throws Exception {
    BatchOperator.setParallelism(1);
    List<Row> data = Arrays.asList(Row.of(0, Timestamp.valueOf("2021-11-01 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-02 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-03 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-04 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-06 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-07 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-08 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-09 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-10 00:00:00"), 900.0), Row.of(0, Timestamp.valueOf("2021-11-11 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-12 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-13 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-14 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-15 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-16 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-17 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-18 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-19 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-20 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-21 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-22 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-23 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-24 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-25 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-26 00:00:00"), 900.0), Row.of(0, Timestamp.valueOf("2021-11-27 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-28 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-29 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-30 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-12-01 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-12-02 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-12-03 00:00:00"), 200.0));
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(data, "id int, ts timestamp, series double");
    MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "id int, ts timestamp, series double");
    LSTNetTrainBatchOp lstNetTrainBatchOp = new LSTNetTrainBatchOp().setTimeCol("ts").setSelectedCol("series").setNumEpochs(10).setWindow(24).setHorizon(1).linkFrom(memSourceBatchOp);
    OverCountWindowStreamOp overCountWindowStreamOp = new OverCountWindowStreamOp().setClause("MTABLE_AGG_PRECEDING(ts, series) as mtable_agg_series").setTimeCol("ts").setPrecedingRows(24);
    LSTNetPredictStreamOp lstNetPredictStreamOp = new LSTNetPredictStreamOp(lstNetTrainBatchOp).setPredictNum(1).setPredictionCol("pred").setReservedCols().setValueCol("mtable_agg_series");
    lstNetPredictStreamOp.linkFrom(overCountWindowStreamOp.linkFrom(memSourceStreamOp).filter("ts = TO_TIMESTAMP('2021-12-03 00:00:00')")).print();
    StreamOperator.execute();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) Row(org.apache.flink.types.Row) LSTNetPredictStreamOp(com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp) Test(org.junit.Test)

Aggregations

OverCountWindowStreamOp (com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp)12 Test (org.junit.Test)12 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)10 Row (org.apache.flink.types.Row)10 Timestamp (java.sql.Timestamp)8 CollectSinkStreamOp (com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp)6 RowComparator (com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator)5 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)3 LSTNetPredictStreamOp (com.alibaba.alink.operator.stream.timeseries.LSTNetPredictStreamOp)3 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)2 AppendIdBatchOp (com.alibaba.alink.operator.batch.dataproc.AppendIdBatchOp)2 RandomTableSourceBatchOp (com.alibaba.alink.operator.batch.source.RandomTableSourceBatchOp)2 SelectBatchOp (com.alibaba.alink.operator.batch.sql.SelectBatchOp)2 AppendIdStreamOp (com.alibaba.alink.operator.stream.dataproc.AppendIdStreamOp)2 AkSinkStreamOp (com.alibaba.alink.operator.stream.sink.AkSinkStreamOp)2 RandomTableSourceStreamOp (com.alibaba.alink.operator.stream.source.RandomTableSourceStreamOp)2 SelectStreamOp (com.alibaba.alink.operator.stream.sql.SelectStreamOp)2 Path (org.apache.flink.core.fs.Path)2 ColumnsToVectorBatchOp (com.alibaba.alink.operator.batch.dataproc.format.ColumnsToVectorBatchOp)1 ProphetTrainBatchOp (com.alibaba.alink.operator.batch.timeseries.ProphetTrainBatchOp)1