Search in sources :

Example 6 with CollectSinkStreamOp

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

the class VectorFunctionStreamOpTest method testVectorFunctionSparse.

@Test
public void testVectorFunctionSparse() throws Exception {
    List<Row> df = new ArrayList<>();
    df.add(Row.of("$8$1:3,2:4,4:7", "$8$1:3,2:4,4:7"));
    StreamOperator<?> data = new MemSourceStreamOp(df, "vec1 string, vec2 string");
    VectorFunctionStreamOp vecFunc = new VectorFunctionStreamOp().setSelectedCol("vec1").setFuncName("normL2").setReservedCols(new String[] {}).setOutputCol("vec_normL2");
    StreamOperator<?> res = vecFunc.linkFrom(data);
    CollectSinkStreamOp sop = res.link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> list = sop.getAndRemoveValues();
    for (Row row : list) {
        Assert.assertEquals((double) row.getField(0), 8.6023, 0.001);
    }
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) ArrayList(java.util.ArrayList) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 7 with CollectSinkStreamOp

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

the class VectorFunctionStreamOpTest method testVectorFunctionDense.

@Test
public void testVectorFunctionDense() throws Exception {
    List<Row> df = new ArrayList<>();
    df.add(Row.of("3 4 7", "2 3 4"));
    StreamOperator<?> data = new MemSourceStreamOp(df, "vec1 string, vec2 string");
    VectorFunctionStreamOp vecFunc = new VectorFunctionStreamOp().setSelectedCol("vec1").setFuncName("normL2Square").setReservedCols(new String[] {}).setOutputCol("vec_normL2");
    StreamOperator<?> res = vecFunc.linkFrom(data);
    CollectSinkStreamOp sop = res.link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> list = sop.getAndRemoveValues();
    for (Row row : list) {
        Assert.assertEquals((double) row.getField(0), 74.0, 0.001);
    }
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) ArrayList(java.util.ArrayList) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 8 with CollectSinkStreamOp

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

the class EvalBinaryClassStreamOpTest method testDetailBinary.

@Test
public void testDetailBinary() throws Exception {
    Row[] detailBinaryArray = new Row[] { Row.of("prefix1", "{\"prefix1\": 0.1, \"prefix0\": 0.9}"), Row.of("prefix1", "{\"prefix1\": 0.8, \"prefix0\": 0.2}"), Row.of("prefix1", "{\"prefix1\": 0.4, \"prefix0\": 0.6}"), Row.of("prefix0", "{\"prefix1\": 0.75, \"prefix0\": 0.25}"), Row.of("prefix0", "{\"prefix1\": 0.6, \"prefix0\": 0.4}"), Row.of("prefix1", "{\"prefix1\": 0.65, \"prefix0\": 0.35}"), Row.of("prefix1", "{\"prefix1\": 0.55, \"prefix0\": 0.45}"), Row.of("prefix0", "{\"prefix1\": 0.1, \"prefix0\": 0.9}"), Row.of("prefix0", "{\"prefix1\": 0.3, \"prefix0\": 0.7}"), Row.of("prefix1", "{\"prefix1\": 0.25, \"prefix0\": 0.75}"), Row.of("prefix0", "{\"prefix1\": 0.2, \"prefix0\": 0.8}"), Row.of("prefix1", "{\"prefix1\": 0.1, \"prefix0\": 0.9}") };
    MemSourceStreamOp detailBinaryTmp = new MemSourceStreamOp(Arrays.asList(detailBinaryArray), new String[] { "label", "detailInput" });
    EvalBinaryClassStreamOp op1 = new EvalBinaryClassStreamOp().setLabelCol("label").setPositiveLabelValueString("prefix0").setTimeInterval(0.001).setPredictionDetailCol("detailInput").linkFrom(detailBinaryTmp);
    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 9 with CollectSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp 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 10 with CollectSinkStreamOp

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

the class FilterStreamOpTest method test.

@Test
public void test() throws Exception {
    Row[] testArray = new Row[] { Row.of("a", 1, 1.1), Row.of("b", -2, 0.9), Row.of("c", 100, -0.01), Row.of("d", -99, 100.9), Row.of("a", 1, 1.1), Row.of("b", -2, 0.9), Row.of("c", 100, -0.01), Row.of("d", -99, 100.9) };
    String[] colNames = new String[] { "col1", "col2", "col3" };
    MemSourceStreamOp inOp = new MemSourceStreamOp(Arrays.asList(testArray), colNames);
    String filter = "col1='a'";
    FilterStreamOp filterStreamOp = new FilterStreamOp(filter);
    CollectSinkStreamOp op = inOp.link(filterStreamOp).link(new CollectSinkStreamOp());
    StreamOperator.execute();
    Assert.assertEquals(2, op.getAndRemoveValues().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)

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