Search in sources :

Example 1 with MemSourceStreamOp

use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.

the class Chap01 method c_5_3.

static void c_5_3() throws Exception {
    MemSourceStreamOp pred_set = new MemSourceStreamOp(new Integer[] { 2018, 2019 }, "x");
    BatchOperator<?> lr_model = new AkSourceBatchOp().setFilePath(DATA_DIR + "gmv_reg.model");
    LinearRegPredictStreamOp predictor = new LinearRegPredictStreamOp(lr_model).setPredictionCol("pred");
    pred_set.select("x, x*x AS x2").link(predictor).print();
    StreamOperator.execute();
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) LinearRegPredictStreamOp(com.alibaba.alink.operator.stream.regression.LinearRegPredictStreamOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp)

Example 2 with MemSourceStreamOp

use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.

the class UDFStreamOpTest method testEmptyFunc.

@Test(expected = IllegalArgumentException.class)
public void testEmptyFunc() throws Exception {
    MemSourceStreamOp src = new MemSourceStreamOp(new Object[][] { new Object[] { "1", "a", 1L }, new Object[] { "2", "b33", 2L } }, new String[] { "c0", "c1", "c2" });
    UDFStreamOp udfOp = new UDFStreamOp().setSelectedCols("c1", "c2").setReservedCols(new String[] {}).setOutputCol("c2");
    udfOp.linkFrom(src);
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) Test(org.junit.Test)

Example 3 with MemSourceStreamOp

use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.

the class UDTFStreamOpTest method testUdtf.

@Test
public void testUdtf() throws Exception {
    MemSourceStreamOp src = new MemSourceStreamOp(new Object[][] { new Object[] { "1", "a b", 1L }, new Object[] { "2", "b33 bb44", 2L }, new Object[] { "3", "", 3L } }, new String[] { "c0", "c1", "c2" });
    UDTFStreamOp udtfOp = new UDTFStreamOp().setFunc(new Split(" ")).setSelectedCols("c1", "c2").setReservedCols(new String[] { "c1", "c2" }).setOutputCols("c1", "length");
    udtfOp.linkFrom(src);
    Assert.assertArrayEquals(new String[] { "c2", "c1", "length" }, udtfOp.getColNames());
    udtfOp.print();
    StreamOperator.execute();
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) Test(org.junit.Test)

Example 4 with MemSourceStreamOp

use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.

the class SoftmaxTest method pipelineTest.

@Test
public void pipelineTest() throws Exception {
    BatchOperator<?> vecdata = new MemSourceBatchOp(Arrays.asList(vecrows), veccolNames);
    StreamOperator<?> svecdata = new MemSourceStreamOp(Arrays.asList(vecrows), veccolNames);
    Pipeline pl = new Pipeline().add(softmax).add(vsoftmax).add(svsoftmax).add(vssoftmax);
    PipelineModel model = pl.fit(vecdata);
    BatchOperator<?> result = model.transform(vecdata).select(new String[] { "label", "predLr", "vpredLr", "svpredLr" });
    List<Row> data = result.lazyPrint(100).collect();
    for (Row row : data) {
        for (int i = 1; i < 3; ++i) {
            Assert.assertEquals(row.getField(0), row.getField(i));
        }
    }
    // below is stream test code
    // below is stream test code.
    CollectSinkStreamOp sop = model.transform(svecdata).select(new String[] { "label", "predLr", "vpredLr", "svpredLr" }).link(new CollectSinkStreamOp());
    StreamOperator.execute();
    List<Row> rows = sop.getAndRemoveValues();
    for (Row row : rows) {
        for (int i = 1; i < 3; ++i) {
            Assert.assertEquals(row.getField(0), row.getField(i));
        }
    }
}
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) Pipeline(com.alibaba.alink.pipeline.Pipeline) PipelineModel(com.alibaba.alink.pipeline.PipelineModel) Test(org.junit.Test)

Example 5 with MemSourceStreamOp

use of com.alibaba.alink.operator.stream.source.MemSourceStreamOp in project Alink by alibaba.

the class StreamingKMeansStreamOpTest method before.

@Before
public void before() {
    Row[] trainDataArray = new Row[] { Row.of(0, "0 0 0"), Row.of(1, "0.1 0.1 0.1"), Row.of(2, "0.2 0.2 0.2"), Row.of(3, "9 9 9"), Row.of(4, "9.1 9.1 9.1"), Row.of(5, "9.2 9.2 9.2") };
    Row[] predictDataArray = new Row[numElementsToPredict];
    for (int i = 0; i < predictDataArray.length; i++) {
        predictDataArray[i] = Row.of(DenseVector.rand(3));
    }
    trainDataBatchOp = new MemSourceBatchOp(Arrays.asList(trainDataArray), new String[] { "id", "vec" });
    predictDataStreamOp = new MemSourceStreamOp(Arrays.asList(predictDataArray), new String[] { "vec" });
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) Row(org.apache.flink.types.Row) Before(org.junit.Before)

Aggregations

MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)101 Row (org.apache.flink.types.Row)86 Test (org.junit.Test)78 CollectSinkStreamOp (com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp)60 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)55 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)19 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)18 TableSchema (org.apache.flink.table.api.TableSchema)18 RowComparator (com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator)15 ArrayList (java.util.ArrayList)13 Timestamp (java.sql.Timestamp)12 OverCountWindowStreamOp (com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp)10 Pipeline (com.alibaba.alink.pipeline.Pipeline)7 StringNearestNeighborBatchOpTest (com.alibaba.alink.operator.batch.similarity.StringNearestNeighborBatchOpTest)6 TextApproxNearestNeighborBatchOpTest (com.alibaba.alink.operator.batch.similarity.TextApproxNearestNeighborBatchOpTest)6 PipelineModel (com.alibaba.alink.pipeline.PipelineModel)6 HashMap (java.util.HashMap)6 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)5 Before (org.junit.Before)5 MTable (com.alibaba.alink.common.MTable)3