Search in sources :

Example 51 with CollectSinkStreamOp

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

the class VectorPolynomialExpandTest method pipelineStreamTest.

@Test
public void pipelineStreamTest() throws Exception {
    StreamOperator streamOperator = new VectorPolynomialExpand().setDegree(2).setOutputCol("outv").setSelectedCol("c1").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(2).getField(4)), new DenseVector(new double[] { 2.0, 4.0, 3.0, 6.0, 9.0 }));
    assertEquals(VectorUtil.getVector(result.get(1).getField(4)), new DenseVector(new double[] { 3.0, 9.0, 2.0, 6.0, 4.0, 3.0, 9.0, 6.0, 9.0 }));
    assertEquals(VectorUtil.getVector(result.get(0).getField(4)), new DenseVector(new double[] { 3.0, 9.0, 2.0, 6.0, 4.0, 3.0, 9.0, 6.0, 9.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) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) DenseVector(com.alibaba.alink.common.linalg.DenseVector) Test(org.junit.Test)

Example 52 with CollectSinkStreamOp

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

the class VectorSlicerTest method pipelineStreamTest.

@Test
public void pipelineStreamTest() throws Exception {
    StreamOperator streamOperator = new VectorSlicer().setSelectedCol("c0").setOutputCol("slicer_result").setIndices(new int[] { 1, 5 }).transform((StreamOperator) getData(false));
    CollectSinkStreamOp collectSinkStreamOp = new CollectSinkStreamOp().linkFrom(streamOperator);
    StreamOperator.execute();
    List<Row> result = collectSinkStreamOp.getAndRemoveValues();
    result.sort(new RowComparator(0));
    assertEquals(VectorUtil.getSparseVector(result.get(0).getField(4)), new SparseVector(2, new int[] { 0, 1 }, new double[] { 2.0, 4.3 }));
    assertEquals(VectorUtil.getSparseVector(result.get(1).getField(4)), new SparseVector(2, new int[] { 0 }, new double[] { 2.0 }));
    assertEquals(VectorUtil.getSparseVector(result.get(2).getField(4)), new SparseVector(2, new int[] { 0 }, new double[] { 2.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 53 with CollectSinkStreamOp

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

the class BinarizerTest method test.

@Test
public void test() throws Exception {
    Row[] rows = new Row[] { Row.of(1, 1.218, 16.0, "1.560 -0.605"), Row.of(2, 2.949, 4.0, "0.346 2.158"), Row.of(3, 3.627, 2.0, "1.380 0.231"), Row.of(4, 0.273, 15.0, "0.520 1.151"), Row.of(5, 4.199, 7.0, "0.795 -0.226") };
    List<Row> expectedRows = Arrays.asList(Row.of(1, 1.0), Row.of(2, 0.0), Row.of(3, 0.0), Row.of(4, 1.0), Row.of(5, 0.0));
    BatchOperator<?> data = new MemSourceBatchOp(rows, new String[] { "id", "label", "censor", "features" });
    StreamOperator<?> dataStream = new MemSourceStreamOp(rows, new String[] { "id", "label", "censor", "features" });
    Binarizer op = new Binarizer().setSelectedCol("censor").setThreshold(8.0);
    // batch
    List<Row> list = op.transform(data).select("id, censor").collect();
    AlinkTestBase.assertListRowEqual(expectedRows, list, 0);
    CollectSinkStreamOp resS = op.transform(dataStream).select("id, censor").link(new CollectSinkStreamOp());
    StreamOperator.execute();
    AlinkTestBase.assertListRowEqual(expectedRows, resS.getAndRemoveValues(), 0);
}
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) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 54 with CollectSinkStreamOp

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

the class ReadImageToTensorStreamOpTest method testReadImageToTensorStreamOp.

@Test
public void testReadImageToTensorStreamOp() throws Exception {
    List<Row> data = Collections.singletonList(Row.of("sphx_glr_plot_scripted_tensor_transforms_001.png"));
    MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(data, "path string");
    CollectSinkStreamOp collectSinkStreamOp = new ReadImageToTensorStreamOp().setRootFilePath("http://alink-test-datatset.oss-cn-hangzhou-zmf.aliyuncs.com/images/").setRelativeFilePathCol("path").setOutputCol("tensor").linkFrom(memSourceStreamOp).link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> rows = collectSinkStreamOp.getAndRemoveValues();
    Assert.assertEquals(1, rows.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 55 with CollectSinkStreamOp

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

the class KeywordsExtractionStreamOpTest method testKeywordsExtractionStream.

@Test
public void testKeywordsExtractionStream() throws Exception {
    Row[] array = new Row[] { Row.of(1, text), Row.of(1, text), Row.of(1, text), Row.of(1, text) };
    List<Row> expected = Arrays.asList(Row.of(1, "基于 算法 建模"), Row.of(1, "基于 算法 建模"), Row.of(1, "基于 算法 建模"), Row.of(1, "基于 算法 建模"));
    MemSourceStreamOp words = new MemSourceStreamOp(Arrays.asList(array), new String[] { "ID", "text" });
    KeywordsExtractionStreamOp op = new KeywordsExtractionStreamOp().setSelectedCol("text").setTopN(3).linkFrom(words);
    CollectSinkStreamOp sink = new CollectSinkStreamOp().linkFrom(op);
    StreamOperator.execute();
    assertListRowEqualWithoutOrder(expected, 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)

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