Search in sources :

Example 41 with CollectSinkStreamOp

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

the class CrossFeatureTest method testHash.

@Test
public void testHash() throws Exception {
    List<Row> expected = Arrays.asList(Row.of(1, "1.0", "1.0", 1.0, 1, VectorUtil.getVector("$36$21:1.0")), Row.of(2, "1.0", "1.0", 0.0, 1, VectorUtil.getVector("$36$3:1.0")), Row.of(3, "1.0", "0.0", 1.0, 1, VectorUtil.getVector("$36$33:1.0")), Row.of(4, "1.0", "0.0", 1.0, 1, VectorUtil.getVector("$36$33:1.0")), Row.of(5, "2.0", "3.0", null, 0, VectorUtil.getVector("$36$")), Row.of(6, "2.0", "3.0", 1.0, 0, VectorUtil.getVector("$36$16:1.0")), Row.of(7, "0.0", "1.0", 2.0, 0, VectorUtil.getVector("$36$3:1.0")), Row.of(8, "0.0", "1.0", 1.0, 0, VectorUtil.getVector("$36$8:1.0")));
    StreamOperator<?> data = new MemSourceStreamOp(Arrays.asList(array), vecColNames);
    HashCrossFeatureStreamOp hashCross = new HashCrossFeatureStreamOp().setNumFeatures(36).setSelectedCols("f0", "f1", "f2").setOutputCol("res").linkFrom(data);
    CollectSinkStreamOp sink = new CollectSinkStreamOp().linkFrom(hashCross);
    StreamOperator.execute();
    assertListRowEqual(expected, sink.getAndRemoveValues(), 0);
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) Row(org.apache.flink.types.Row) HashCrossFeatureStreamOp(com.alibaba.alink.operator.stream.feature.HashCrossFeatureStreamOp) Test(org.junit.Test)

Example 42 with CollectSinkStreamOp

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

the class FlattenMTableTest method test3.

@Test
public void test3() throws Exception {
    List<Row> rows = new ArrayList<>();
    rows.add(Row.of("a1", "{\"data\":{\"f0\":[\"11L\",\"12L\"],\"f1\":[2.0,2.0]},\"schema\":\"f0 VARCHAR,f1 " + "DOUBLE\"}"));
    rows.add(Row.of("a3", "{\"data\":{\"f0\":[\"13L\",\"14L\"],\"f1\":[2.0,2.0]},\"schema\":\"f0 VARCHAR,f1 " + "DOUBLE\"}"));
    StreamOperator<?> input = new MemSourceStreamOp(rows, "id string, mt string");
    FlattenMTableStreamOp flatten = new FlattenMTableStreamOp().setReservedCols("id").setSelectedCol("mt").setSchemaStr("f0 string, f1 int");
    CollectSinkStreamOp sop = flatten.linkFrom(input).link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> res = sop.getAndRemoveValues();
    for (Row row : res) {
        Assert.assertEquals(2, row.getField(2));
    }
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) FlattenMTableStreamOp(com.alibaba.alink.operator.stream.dataproc.FlattenMTableStreamOp) CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) ArrayList(java.util.ArrayList) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 43 with CollectSinkStreamOp

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

the class StreamingKMeansStreamOpTest method testStreamingKmeans.

@Test
public void testStreamingKmeans() throws Exception {
    BatchOperator<?> model = new KMeansTrainBatchOp().setVectorCol("vec").setK(2).linkFrom(trainDataBatchOp);
    StreamingKMeansStreamOp streamingKMeansStreamOp = new StreamingKMeansStreamOp(model).setPredictionCol("pred").setTimeInterval(1L).setHalfLife(1).setReservedCols("vec").linkFrom(predictDataStreamOp, predictDataStreamOp);
    CollectSinkStreamOp predSinkData = streamingKMeansStreamOp.link(new CollectSinkStreamOp());
    StreamOperator.execute();
    verifyExecutionResult(predSinkData.getAndRemoveValues());
}
Also used : CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) KMeansTrainBatchOp(com.alibaba.alink.operator.batch.clustering.KMeansTrainBatchOp) Test(org.junit.Test)

Example 44 with CollectSinkStreamOp

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

the class SplitStreamOpTest method testSplit.

@Test
public void testSplit() throws Exception {
    SplitStreamOp splitOp = new SplitStreamOp(0.5).linkFrom(inputDataOp);
    CollectSinkStreamOp collectSinkStreamOp1 = splitOp.link(new CollectSinkStreamOp());
    CollectSinkStreamOp collectSinkStreamOp2 = splitOp.getSideOutput(0).link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> output1 = collectSinkStreamOp1.getAndRemoveValues();
    List<Row> output2 = collectSinkStreamOp2.getAndRemoveValues();
    assertEquals(output1.size() + output2.size(), inputRows.length);
}
Also used : CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 45 with CollectSinkStreamOp

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

the class StratifiedSampleStreamOpTest method test.

@Test
public void test() throws Exception {
    StratifiedSampleStreamOp stratifiedSampleStreamOp = new StratifiedSampleStreamOp().setStrataCol(colNames[0]).setStrataRatio(0.5).linkFrom(inputDataOp);
    CollectSinkStreamOp outputStreamOp = stratifiedSampleStreamOp.link(new CollectSinkStreamOp());
    StreamOperator.execute();
    assertTrue(outputStreamOp.getAndRemoveValues().size() <= inputRows.length);
}
Also used : CollectSinkStreamOp(com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp) 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