Search in sources :

Example 1 with RowComparator

use of com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator in project Alink by alibaba.

the class OverTimeWindowStreamOpTest method test.

@Test
public void test() throws Exception {
    MemSourceStreamOp source = new MemSourceStreamOp(new Row[] { Row.of(1, "user2", Timestamp.valueOf("2021-01-01 00:01:01"), 20), 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 sink = source.select("*, CEIL(sell_time TO MINUTE) AS " + ModelStreamUtils.MODEL_STREAM_TIMESTAMP_COLUMN_NAME).link(new OverTimeWindowStreamOp().setTimeCol(ModelStreamUtils.MODEL_STREAM_TIMESTAMP_COLUMN_NAME).setPrecedingTime(1).setClause("COUNT(*) AS " + ModelStreamUtils.MODEL_STREAM_COUNT_COLUMN_NAME)).link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> result = sink.getAndRemoveValues();
    result.sort(new RowComparator(0));
    Assert.assertEquals(12, result.size());
    Assert.assertEquals(1, result.get(0).getField(0));
    Assert.assertEquals(2L, result.get(0).getField(5));
    Assert.assertEquals(6, result.get(5).getField(0));
    Assert.assertEquals(2L, result.get(6).getField(5));
    Assert.assertEquals(12, result.get(11).getField(0));
    Assert.assertEquals(2L, result.get(11).getField(5));
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) RowComparator(com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 2 with RowComparator

use of com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator 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 3 with RowComparator

use of com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator 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 4 with RowComparator

use of com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator 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 5 with RowComparator

use of com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator in project Alink by alibaba.

the class StringSimilarityPairwiseTest method testStringSimilarityPairwise.

@Test
public void testStringSimilarityPairwise() throws Exception {
    List<Row> df = Arrays.asList(Row.of(0, "abcde", "aabce"), Row.of(1, "aacedw", "aabbed"), Row.of(2, "cdefa", "bbcefa"), Row.of(3, "bdefh", "ddeac"), Row.of(4, "acedm", "aeefbc"));
    BatchOperator<?> inOp1 = new MemSourceBatchOp(df, "id int, text1 string, text2 string");
    StreamOperator<?> inOp2 = new MemSourceStreamOp(df, "id int, text1 string, text2 string");
    StringSimilarityPairwise stringSimilarityPairwise = new StringSimilarityPairwise().setSelectedCols("text1", "text2").setMetric("LEVENSHTEIN").setOutputCol("output");
    stringSimilarityPairwise.transform(inOp1).print();
    CollectSinkStreamOp collectSinkStreamOp = new CollectSinkStreamOp().linkFrom(stringSimilarityPairwise.transform(inOp2));
    StreamOperator.execute();
    List<Row> list = collectSinkStreamOp.getAndRemoveValues();
    list.sort(new RowComparator(0));
    for (int i = 0; i < list.size(); i++) {
        System.out.println("\"" + list.get(i).toString() + "\",");
    }
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) RowComparator(com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

RowComparator (com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator)31 Row (org.apache.flink.types.Row)31 Test (org.junit.Test)26 CollectSinkStreamOp (com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp)25 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)16 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)15 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)9 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)8 OverCountWindowStreamOp (com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp)5 Timestamp (java.sql.Timestamp)5 TableSchema (org.apache.flink.table.api.TableSchema)4 SparseVector (com.alibaba.alink.common.linalg.SparseVector)3 DenseVector (com.alibaba.alink.common.linalg.DenseVector)2 Binarizer (com.alibaba.alink.pipeline.feature.Binarizer)2 LinearModelData (com.alibaba.alink.operator.common.linear.LinearModelData)1 LinearModelDataConverter (com.alibaba.alink.operator.common.linear.LinearModelDataConverter)1 SoftmaxTrainParams (com.alibaba.alink.params.classification.SoftmaxTrainParams)1 LinearTrainParams (com.alibaba.alink.params.shared.linear.LinearTrainParams)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1