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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations