Search in sources :

Example 1 with TableSourceStreamOp

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();
    }
}
Also used : TableImpl(org.apache.flink.table.api.internal.TableImpl) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) TableSourceStreamOp(com.alibaba.alink.operator.stream.source.TableSourceStreamOp) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp)

Example 2 with TableSourceStreamOp

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();
}
Also used : MaxAbsScaler(com.alibaba.alink.pipeline.dataproc.MaxAbsScaler) MaxAbsScalerPredictStreamOp(com.alibaba.alink.operator.stream.dataproc.MaxAbsScalerPredictStreamOp) MaxAbsScalerModel(com.alibaba.alink.pipeline.dataproc.MaxAbsScalerModel) TableSourceStreamOp(com.alibaba.alink.operator.stream.source.TableSourceStreamOp) Row(org.apache.flink.types.Row) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) Test(org.junit.Test)

Example 3 with TableSourceStreamOp

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();
}
Also used : TableSourceStreamOp(com.alibaba.alink.operator.stream.source.TableSourceStreamOp) Row(org.apache.flink.types.Row) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) DenseVector(com.alibaba.alink.common.linalg.DenseVector) VectorMaxAbsScalerPredictStreamOp(com.alibaba.alink.operator.stream.dataproc.vector.VectorMaxAbsScalerPredictStreamOp) Test(org.junit.Test)

Example 4 with TableSourceStreamOp

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();
}
Also used : VectorMinMaxScalerPredictStreamOp(com.alibaba.alink.operator.stream.dataproc.vector.VectorMinMaxScalerPredictStreamOp) TableSourceStreamOp(com.alibaba.alink.operator.stream.source.TableSourceStreamOp) Row(org.apache.flink.types.Row) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) DenseVector(com.alibaba.alink.common.linalg.DenseVector) Test(org.junit.Test)

Example 5 with TableSourceStreamOp

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();
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) ObjectPath(org.apache.flink.table.catalog.ObjectPath) TableSchema(org.apache.flink.table.api.TableSchema) Params(org.apache.flink.ml.api.misc.param.Params) Time(java.sql.Time) Timestamp(java.sql.Timestamp) Date(java.sql.Date) BigDecimal(java.math.BigDecimal) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) Row(org.apache.flink.types.Row) TableSourceStreamOp(com.alibaba.alink.operator.stream.source.TableSourceStreamOp) Test(org.junit.Test)

Aggregations

TableSourceStreamOp (com.alibaba.alink.operator.stream.source.TableSourceStreamOp)12 Row (org.apache.flink.types.Row)11 TableSourceBatchOp (com.alibaba.alink.operator.batch.source.TableSourceBatchOp)10 Test (org.junit.Test)8 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)6 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)6 DenseVector (com.alibaba.alink.common.linalg.DenseVector)3 Before (org.junit.Before)3 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)2 BigDecimal (java.math.BigDecimal)2 Date (java.sql.Date)2 Time (java.sql.Time)2 Timestamp (java.sql.Timestamp)2 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)2 Params (org.apache.flink.ml.api.misc.param.Params)2 TableSchema (org.apache.flink.table.api.TableSchema)2 ObjectPath (org.apache.flink.table.catalog.ObjectPath)2 AppendIdBatchOp (com.alibaba.alink.operator.batch.dataproc.AppendIdBatchOp)1 MaxAbsScalerPredictStreamOp (com.alibaba.alink.operator.stream.dataproc.MaxAbsScalerPredictStreamOp)1 MinMaxScalerPredictStreamOp (com.alibaba.alink.operator.stream.dataproc.MinMaxScalerPredictStreamOp)1