Search in sources :

Example 1 with StreamOperator

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

the class Chap06 method c_2_4.

public static void c_2_4() throws Exception {
    StreamOperator items = Chap24.getStreamSourceItems();
    items = items.select("item_id, title").filter("item_id<4");
    items.print();
    StreamOperator.execute();
    StreamOperator<?> words = items.link(new UDTFStreamOp().setFunc(new WordCount()).setSelectedCols("title").setOutputCols("word", "cnt").setReservedCols("item_id"));
    words.print();
    StreamOperator.execute();
    StreamOperator.registerFunction("word_count", new WordCount());
    items.registerTableName("items");
    StreamOperator.sqlQuery("SELECT item_id, word, cnt FROM items, " + "LATERAL TABLE(word_count(title)) as T(word, cnt)").print();
    StreamOperator.execute();
}
Also used : UDTFStreamOp(com.alibaba.alink.operator.stream.utils.UDTFStreamOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator)

Example 2 with StreamOperator

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

the class AkSourceSinkTest method testStreamSink.

public void testStreamSink() throws Exception {
    StreamOperator data = Iris.getStreamData();
    data.link(new AkSinkStreamOp().setFilePath(new File(path, "af1s").getAbsolutePath()).setOverwriteSink(true));
    data.link(new AkSinkStreamOp().setFilePath(new File(path, "ad2s").getAbsolutePath()).setNumFiles(2).setOverwriteSink(true));
    StreamOperator.execute();
}
Also used : AkSinkStreamOp(com.alibaba.alink.operator.stream.sink.AkSinkStreamOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) File(java.io.File)

Example 3 with StreamOperator

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

the class AkSourceSinkTest method testStreamSource.

@Test
public void testStreamSource() throws Exception {
    StreamOperator data1 = new AkSourceStreamOp().setFilePath(new File(path, "af1s").getAbsolutePath());
    StreamOperator data3 = new AkSourceStreamOp().setFilePath(new File(path, "ad2s").getAbsolutePath());
    data1.sample(0.1).print();
    data3.sample(0.1).print();
    StreamOperator.execute();
}
Also used : AkSourceStreamOp(com.alibaba.alink.operator.stream.source.AkSourceStreamOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) File(java.io.File) Test(org.junit.Test)

Example 4 with StreamOperator

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

the class PipelineModelTest method test.

@Test
public void test() throws Exception {
    BatchOperator source = getTrainSource();
    StreamOperator streamSource = getTrainStreamSource();
    Pipeline pipeline = getPipeline();
    PipelineModel pipelineModel = pipeline.fit(source);
    pipelineModel.transform(source).print();
    pipelineModel.transform(streamSource).print();
    StreamOperator.execute();
}
Also used : StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) Test(org.junit.Test)

Example 5 with StreamOperator

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

the class NaiveBayesTrainBatchOpTest method testNaiveBayes.

@Test
public void testNaiveBayes() throws Exception {
    String[] feature = new String[] { "f0", "f4" };
    String label = "label";
    BatchOperator batchData = (BatchOperator) getData(true);
    NaiveBayesTrainBatchOp op = new NaiveBayesTrainBatchOp().setCategoricalCols("f0", "f4").setSmoothing(0.0).setWeightCol("weight").setFeatureCols(feature).setLabelCol(label).linkFrom(batchData);
    op.getModelInfoBatchOp().lazyPrintModelInfo();
    op.lazyPrint(-1);
    NaiveBayesPredictBatchOp predict = new NaiveBayesPredictBatchOp().setPredictionCol("predict").setPredictionDetailCol("detail").setReservedCols("label");
    BatchOperator res = predict.linkFrom(op, batchData);
    res.select(new String[] { "label", "predict" }).lazyCollect();
    StreamOperator streamData = (StreamOperator) getData(false);
    new NaiveBayesPredictStreamOp(op).setPredictionCol("predict").linkFrom(streamData).print();
    // StreamOperator.execute();
    new NaiveBayes().setFeatureCols(feature).setLabelCol(label).setPredictionCol("predict").fit(batchData).transform(batchData).collect();
}
Also used : NaiveBayesPredictStreamOp(com.alibaba.alink.operator.stream.classification.NaiveBayesPredictStreamOp) NaiveBayes(com.alibaba.alink.pipeline.classification.NaiveBayes) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) Test(org.junit.Test)

Aggregations

StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)51 Test (org.junit.Test)39 Row (org.apache.flink.types.Row)37 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)35 CollectSinkStreamOp (com.alibaba.alink.operator.stream.sink.CollectSinkStreamOp)25 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)19 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)17 RowComparator (com.alibaba.alink.operator.common.dataproc.SortUtils.RowComparator)16 HashMap (java.util.HashMap)9 StringNearestNeighborBatchOpTest (com.alibaba.alink.operator.batch.similarity.StringNearestNeighborBatchOpTest)6 TextApproxNearestNeighborBatchOpTest (com.alibaba.alink.operator.batch.similarity.TextApproxNearestNeighborBatchOpTest)6 TableSourceBatchOp (com.alibaba.alink.operator.batch.source.TableSourceBatchOp)6 TableSourceStreamOp (com.alibaba.alink.operator.stream.source.TableSourceStreamOp)6 DenseVector (com.alibaba.alink.common.linalg.DenseVector)4 TableSchema (org.apache.flink.table.api.TableSchema)4 SparseVector (com.alibaba.alink.common.linalg.SparseVector)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 BaseSinkBatchOp (com.alibaba.alink.operator.batch.sink.BaseSinkBatchOp)2