Search in sources :

Example 56 with CollectSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.

the class VectorAssemblerTest method pipelineStreamTest.

@Test
public void pipelineStreamTest() throws Exception {
    StreamOperator streamOperator = new VectorAssembler().setSelectedCols(new String[] { "c0", "c1", "c2" }).setOutputCol("table2vec").transform((StreamOperator) getData(false));
    CollectSinkStreamOp collectSinkStreamOp = new CollectSinkStreamOp().linkFrom(streamOperator);
    StreamOperator.execute();
    List<Row> result = collectSinkStreamOp.getAndRemoveValues();
    result.sort(new RowComparator(0));
    assertEquals(VectorUtil.getVector(result.get(0).getField(4)), VectorUtil.getDenseVector("0.0 2.0 3.0 0.0 0.0 4.3 3.0 2.0 3.0 1.0 4.0 6.0 8.0"));
    assertEquals(VectorUtil.getVector(result.get(1).getField(4)), new SparseVector(15, new int[] { 1, 2, 7, 8, 9, 10, 11, 12, 13, 14 }, new double[] { 2.0, 3.0, 4.3, 3.0, 2.0, 3.0, 1.0, 4.0, 6.0, 8.0 }));
    assertEquals(VectorUtil.getVector(result.get(2).getField(4)), new SparseVector(14, new int[] { 1, 2, 7, 8, 9, 10, 11, 12, 13 }, new double[] { 2.0, 3.0, 4.3, 2.0, 3.0, 1.0, 4.0, 6.0, 8.0 }));
}
Also used : CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) RowComparator(com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator) Row(org.apache.flink.types.Row) SparseVector(com.alibaba.alink.common.linalg.SparseVector) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) Test(org.junit.Test)

Example 57 with CollectSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.

the class EvalMultiClassStreamOpTest method testPredMulti.

@Test
public void testPredMulti() throws Exception {
    Row[] predMultiArray = new Row[] { Row.of("prefix1", "prefix1"), Row.of("prefix1", "prefix1"), Row.of("prefix0", "prefix0"), Row.of("prefix0", "prefix2"), Row.of("prefix2", "prefix0"), Row.of("prefix1", "prefix2"), Row.of("prefix1", "prefix1"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix2"), Row.of("prefix0", "prefix2"), Row.of("prefix0", "prefix0"), Row.of("prefix1", "prefix1"), Row.of("prefix1", "prefix1"), Row.of("prefix1", "prefix1"), Row.of("prefix0", "prefix0"), Row.of("prefix0", "prefix2"), Row.of("prefix2", "prefix0"), Row.of("prefix1", "prefix2"), Row.of("prefix1", "prefix1"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix2"), Row.of("prefix0", "prefix2"), Row.of("prefix0", "prefix0"), Row.of("prefix1", "prefix1"), Row.of("prefix1", "prefix1"), Row.of("prefix1", "prefix1"), Row.of("prefix0", "prefix0"), Row.of("prefix0", "prefix2"), Row.of("prefix2", "prefix0"), Row.of("prefix1", "prefix2"), Row.of("prefix1", "prefix1"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix2"), Row.of("prefix0", "prefix2"), Row.of("prefix0", "prefix0"), Row.of("prefix1", "prefix1"), Row.of("prefix1", "prefix1"), Row.of("prefix1", "prefix1"), Row.of("prefix0", "prefix0"), Row.of("prefix0", "prefix2"), Row.of("prefix2", "prefix0"), Row.of("prefix1", "prefix2"), Row.of("prefix1", "prefix1"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix0"), Row.of("prefix2", "prefix2"), Row.of("prefix0", "prefix2"), Row.of("prefix0", "prefix0"), Row.of("prefix1", "prefix1") };
    for (int i = 0; i < 10; i += 1) {
        // 2 ^ 10 = 1024 times
        predMultiArray = ArrayUtils.addAll(predMultiArray, predMultiArray);
    }
    MemSourceStreamOp predMultiTmp = new MemSourceStreamOp(Arrays.asList(predMultiArray), new String[] { "label", "pred" });
    EvalMultiClassStreamOp op1 = new EvalMultiClassStreamOp().setTimeInterval(0.5).setLabelCol("label").setPredictionCol("pred").linkFrom(predMultiTmp);
    CollectSinkStreamOp sink = new CollectSinkStreamOp().linkFrom(op1);
    StreamOperator.execute();
    System.out.println(sink.getAndRemoveValues());
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 58 with CollectSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.

the class EvalMultiClassStreamOpTest method testDetailMulti.

@Test
public void testDetailMulti() throws Exception {
    Row[] detailMultiArray = new Row[] { Row.of("prefix0", "{\"prefix0\": 0.3, \"prefix1\": 0.2, \"prefix2\": 0.5}"), Row.of("prefix0", "{\"prefix0\": 0.4, \"prefix1\": 0.3, \"prefix2\": 0.3}"), Row.of("prefix1", "{\"prefix0\": 0.3, \"prefix1\": 0.4, \"prefix2\": 0.3}"), Row.of("prefix2", "{\"prefix0\": 0.5, \"prefix1\": 0.2, \"prefix2\": 0.3}"), Row.of("prefix2", "{\"prefix0\": 0.4, \"prefix1\": 0.3, \"prefix2\": 0.3}"), Row.of("prefix2", "{\"prefix0\": 0.4, \"prefix1\": 0.1, \"prefix2\": 0.5}"), Row.of("prefix2", "{\"prefix0\": 0.6, \"prefix1\": 0.1, \"prefix2\": 0.3}"), Row.of("prefix1", "{\"prefix0\": 0.4, \"prefix1\": 0.1, \"prefix2\": 0.5}"), Row.of("prefix1", "{\"prefix0\": 0.2, \"prefix1\": 0.5, \"prefix2\": 0.3}"), Row.of("prefix1", "{\"prefix0\": 0.2, \"prefix1\": 0.5, \"prefix2\": 0.3}"), Row.of("prefix1", "{\"prefix0\": 0.2, \"prefix1\": 0.5, \"prefix2\": 0.3}"), Row.of("prefix0", "{\"prefix0\": 0.4, \"prefix1\": 0.3, \"prefix2\": 0.3}"), Row.of("prefix0", "{\"prefix0\": 0.4, \"prefix1\": 0.1, \"prefix2\": 0.5}") };
    for (int i = 0; i < 10; i += 1) {
        // 2 ^ 10 times
        detailMultiArray = ArrayUtils.addAll(detailMultiArray, detailMultiArray);
    }
    MemSourceStreamOp detailMultiTmp = new MemSourceStreamOp(Arrays.asList(detailMultiArray), new String[] { "label", "detailInput" });
    EvalMultiClassStreamOp op1 = new EvalMultiClassStreamOp().setTimeInterval(0.01).setLabelCol("label").setPredictionDetailCol("detailInput").linkFrom(detailMultiTmp);
    CollectSinkStreamOp sink = new CollectSinkStreamOp().linkFrom(op1);
    StreamOperator.execute();
    System.out.println(sink.getAndRemoveValues());
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 59 with CollectSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.

the class OverTimeWindowStreamOpTest method testAgg.

@Test
public void testAgg() throws Exception {
    MemSourceStreamOp source = new MemSourceStreamOp(new Row[] { Row.of(1, "user2", Timestamp.valueOf("2021-01-01 00:01:01"), 30), Row.of(2, "user1", Timestamp.valueOf("2021-01-01 00:01:02"), 50), Row.of(3, "user2", Timestamp.valueOf("2021-01-01 00:03:01"), 30), Row.of(4, "user1", Timestamp.valueOf("2021-01-01 00:06:03"), 60), Row.of(5, "user2", Timestamp.valueOf("2021-01-01 00:06:00"), 40), Row.of(6, "user2", Timestamp.valueOf("2021-01-01 00:06:00"), 20), Row.of(7, "user2", Timestamp.valueOf("2021-01-01 00:07:00"), 70), Row.of(8, "user1", Timestamp.valueOf("2021-01-01 00:08:00"), 80), Row.of(9, "user1", Timestamp.valueOf("2021-01-01 00:09:00"), 40), Row.of(10, "user1", Timestamp.valueOf("2021-01-01 00:10:00"), 20), Row.of(11, "user1", Timestamp.valueOf("2021-01-01 00:11:00"), 30), Row.of(12, "user1", Timestamp.valueOf("2021-01-01 00:11:00"), 50) }, new String[] { "id", "user", "sell_time", "price" });
    CollectSinkStreamOp collectSinkStreamOp = source.link(new OverTimeWindowStreamOp().setTimeCol("sell_time").setPrecedingTime(120).setClause("listagg_preceding(price) as list_price, is_exist(price) as is_exist_p")).link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> results = collectSinkStreamOp.getAndRemoveValues();
    Assert.assertEquals(12, results.size());
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 60 with CollectSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp in project Alink by alibaba.

the class ArimaStreamOpTest 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 ArimaStreamOp().setValueCol("data").setOrder(new int[] { 1, 0, 1 }).setPredictNum(12).setPredictionCol("predict")).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(13.9992, (Double) sResult.get(4).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)

Aggregations

CollectSinkStreamOp (com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp)80 Test (org.junit.Test)76 Row (org.apache.flink.types.Row)72 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)60 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)30 RowComparator (com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator)25 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)25 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)20 Pipeline (com.alibaba.alink.pipeline.Pipeline)9 PipelineModel (com.alibaba.alink.pipeline.PipelineModel)9 Timestamp (java.sql.Timestamp)8 SparseVector (com.alibaba.alink.common.linalg.SparseVector)6 StringNearestNeighborBatchOpTest (com.alibaba.alink.operator.batch.similarity.StringNearestNeighborBatchOpTest)6 TextApproxNearestNeighborBatchOpTest (com.alibaba.alink.operator.batch.similarity.TextApproxNearestNeighborBatchOpTest)6 OverCountWindowStreamOp (com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 MTable (com.alibaba.alink.common.MTable)3 DenseVector (com.alibaba.alink.common.linalg.DenseVector)3 TableSchema (org.apache.flink.table.api.TableSchema)3