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