use of com.alibaba.alink.operator.stream.source.TableSourceStreamOp in project Alink by alibaba.
the class TestUtil method printTable.
public static void printTable(Table table) throws Exception {
TableImpl tableImpl = (TableImpl) table;
if (tableImpl.getTableEnvironment() instanceof StreamTableEnvironment) {
new TableSourceStreamOp(table).print();
StreamOperator.execute();
} else {
new TableSourceBatchOp(table).print();
}
}
use of com.alibaba.alink.operator.stream.source.TableSourceStreamOp in project Alink by alibaba.
the class MaxAbsTest method test.
@Test
public void test() throws Exception {
BatchOperator batchData = new TableSourceBatchOp(GenerateData.getBatchTable());
StreamOperator streamData = new TableSourceStreamOp(GenerateData.getStreamTable());
MaxAbsScalerModel model = new MaxAbsScaler().setSelectedCols("f0", "f1").setOutputCols("f0_1", "f1_1").fit(batchData);
model.transform(batchData).lazyCollect();
model.transform(streamData).print();
MaxAbsScalerTrainBatchOp op = new MaxAbsScalerTrainBatchOp().setSelectedCols("f0", "f1").linkFrom(batchData);
List<Row> rows = new MaxAbsScalerPredictBatchOp().linkFrom(op, batchData).collect();
rows.sort(StandardScalerTest.compare);
assertEquals(rows.get(0), Row.of(null, null));
StandardScalerTest.assertRow(rows.get(1), Row.of(-0.25, -1.));
StandardScalerTest.assertRow(rows.get(2), Row.of(0.25, 0.666));
StandardScalerTest.assertRow(rows.get(3), Row.of(1.0, 0.6666));
new MaxAbsScalerPredictStreamOp(op).linkFrom(streamData).print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.stream.source.TableSourceStreamOp in project Alink by alibaba.
the class VectorMaxAbsTest method test.
@Test
public void test() throws Exception {
BatchOperator batchData = new TableSourceBatchOp(GenerateData.getDenseBatch());
StreamOperator streamData = new TableSourceStreamOp(GenerateData.getDenseStream());
VectorMaxAbsScalerTrainBatchOp op = new VectorMaxAbsScalerTrainBatchOp().setSelectedCol("vec").linkFrom(batchData);
List<Row> rows = new VectorMaxAbsScalerPredictBatchOp().setOutputCol("res").linkFrom(op, batchData).collect();
VectorStandardScalerTest.assertDv(VectorUtil.getDenseVector(rows.get(0).getField(1)), new DenseVector(new double[] { 0.25, 0.6666 }));
VectorStandardScalerTest.assertDv(VectorUtil.getDenseVector(rows.get(1).getField(1)), new DenseVector(new double[] { -0.25, -1. }));
VectorStandardScalerTest.assertDv(VectorUtil.getDenseVector(rows.get(2).getField(1)), new DenseVector(new double[] { 1., 0.6666 }));
new VectorMaxAbsScalerPredictStreamOp(op).setOutputCol("res").linkFrom(streamData).print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.stream.source.TableSourceStreamOp in project Alink by alibaba.
the class VectorMinMaxTest method test.
@Test
public void test() throws Exception {
BatchOperator batchData = new TableSourceBatchOp(GenerateData.getDenseBatch());
StreamOperator streamData = new TableSourceStreamOp(GenerateData.getDenseStream());
VectorMinMaxScalerTrainBatchOp op = new VectorMinMaxScalerTrainBatchOp().setSelectedCol("vec").linkFrom(batchData);
List<Row> rows = new VectorMinMaxScalerPredictBatchOp().linkFrom(op, batchData).collect();
assertEquals(rows.get(0).getField(0), new DenseVector(new double[] { 0.4, 1.0 }));
assertEquals(rows.get(1), Row.of(new DenseVector(new double[] { 0., 0.0 })));
assertEquals(rows.get(2), Row.of(new DenseVector(new double[] { 1.0, 1.0 })));
new VectorMinMaxScalerPredictStreamOp(op).linkFrom(streamData).print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.stream.source.TableSourceStreamOp in project Alink by alibaba.
the class DerbyCatalogTest method sinkStream.
@Test
public void sinkStream() throws Exception {
Row[] rows = new Row[] { Row.of(0L, "string", new Date(0), new BigDecimal("0.00"), 0.0, 0.0f, 0, (short) 0, new Time(0), new Timestamp(0), new byte[] { 0, 1 }) };
MemSourceStreamOp memSourceStreamOp = new MemSourceStreamOp(Arrays.asList(rows), new TableSchema(new String[] { "col_long", "col_string", "col_date", "col_bigdecimal", "col_double", "col_float", "col_int", "col_short", "col_time", "col_timestamp", "col_varcharforbit" }, new TypeInformation<?>[] { Types.LONG, Types.STRING, Types.SQL_DATE, Types.BIG_DEC, Types.DOUBLE, Types.FLOAT, Types.INT, Types.SHORT, Types.SQL_TIME, Types.SQL_TIMESTAMP, Types.PRIMITIVE_ARRAY(Types.BYTE) }));
derby.sinkStream(new ObjectPath(DERBY_SCHEMA, DERBY_DB_TABLE), memSourceStreamOp.getOutputTable(), new Params(), memSourceStreamOp.getMLEnvironmentId());
StreamOperator.execute();
new TableSourceStreamOp(derby.sourceStream(new ObjectPath(DERBY_SCHEMA, DERBY_DB_TABLE), new Params(), MLEnvironmentFactory.DEFAULT_ML_ENVIRONMENT_ID)).print();
StreamOperator.execute();
}
Aggregations