Search in sources :

Example 1 with RecommAdapterMT

use of com.alibaba.alink.operator.common.recommendation.RecommAdapterMT in project Alink by alibaba.

the class BaseRecommStreamOp method linkFrom.

@Override
public T linkFrom(StreamOperator<?>... inputs) {
    StreamOperator<?> in = checkAndGetFirst(inputs);
    TableSchema modelSchema = this.model.getSchema();
    try {
        DataBridge modelDataBridge = DirectReader.collect(model);
        DataBridgeModelSource modelSource = new DataBridgeModelSource(modelDataBridge);
        RecommMapper mapper = new RecommMapper(this.recommKernelBuilder, this.recommType, modelSchema, in.getSchema(), this.getParams());
        DataStream<Row> resultRows;
        if (getParams().get(ModelMapperParams.NUM_THREADS) <= 1) {
            resultRows = in.getDataStream().map(new RecommAdapter(mapper, modelSource));
        } else {
            resultRows = in.getDataStream().flatMap(new RecommAdapterMT(mapper, modelSource, getParams().get(ModelMapperParams.NUM_THREADS)));
        }
        TableSchema outputSchema = mapper.getOutputSchema();
        this.setOutput(resultRows, outputSchema);
        return (T) this;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : RecommAdapter(com.alibaba.alink.operator.common.recommendation.RecommAdapter) TableSchema(org.apache.flink.table.api.TableSchema) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) DataBridgeModelSource(com.alibaba.alink.common.model.DataBridgeModelSource) Row(org.apache.flink.types.Row) RecommMapper(com.alibaba.alink.operator.common.recommendation.RecommMapper) DataBridge(com.alibaba.alink.common.io.directreader.DataBridge)

Example 2 with RecommAdapterMT

use of com.alibaba.alink.operator.common.recommendation.RecommAdapterMT in project Alink by alibaba.

the class BaseRecommBatchOp method linkFrom.

@Override
public T linkFrom(BatchOperator<?>... inputs) {
    checkOpSize(2, inputs);
    try {
        BroadcastVariableModelSource modelSource = new BroadcastVariableModelSource(BROADCAST_MODEL_TABLE_NAME);
        RecommMapper mapper = new RecommMapper(this.recommKernelBuilder, this.recommType, inputs[0].getSchema(), inputs[1].getSchema(), this.getParams());
        DataSet<Row> modelRows = inputs[0].getDataSet().rebalance();
        DataSet<Row> resultRows;
        if (getParams().get(ModelMapperParams.NUM_THREADS) <= 1) {
            resultRows = inputs[1].getDataSet().map(new RecommAdapter(mapper, modelSource)).withBroadcastSet(modelRows, BROADCAST_MODEL_TABLE_NAME);
        } else {
            resultRows = inputs[1].getDataSet().flatMap(new RecommAdapterMT(mapper, modelSource, getParams().get(ModelMapperParams.NUM_THREADS))).withBroadcastSet(modelRows, BROADCAST_MODEL_TABLE_NAME);
        }
        TableSchema outputSchema = mapper.getOutputSchema();
        this.setOutput(resultRows, outputSchema);
        return (T) this;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : RecommAdapter(com.alibaba.alink.operator.common.recommendation.RecommAdapter) BroadcastVariableModelSource(com.alibaba.alink.common.model.BroadcastVariableModelSource) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) TableSchema(org.apache.flink.table.api.TableSchema) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) Row(org.apache.flink.types.Row) RecommMapper(com.alibaba.alink.operator.common.recommendation.RecommMapper)

Aggregations

RecommAdapter (com.alibaba.alink.operator.common.recommendation.RecommAdapter)2 RecommAdapterMT (com.alibaba.alink.operator.common.recommendation.RecommAdapterMT)2 RecommMapper (com.alibaba.alink.operator.common.recommendation.RecommMapper)2 TableSchema (org.apache.flink.table.api.TableSchema)2 Row (org.apache.flink.types.Row)2 DataBridge (com.alibaba.alink.common.io.directreader.DataBridge)1 BroadcastVariableModelSource (com.alibaba.alink.common.model.BroadcastVariableModelSource)1 DataBridgeModelSource (com.alibaba.alink.common.model.DataBridgeModelSource)1