Search in sources :

Example 6 with BatchObject

use of com.alibaba.otter.shared.etl.model.BatchObject in project otter by alibaba.

the class OtterTransformerFactory method transform.

/**
     * 转化FileBatch对象
     */
public Map<Class, BatchObject> transform(FileBatch fileBatch) {
    final Identity identity = translateIdentity(fileBatch.getIdentity());
    List<FileData> fileDatas = fileBatch.getFiles();
    Map<Class, BatchObject> result = new HashMap<Class, BatchObject>();
    // 初始化默认值
    result.put(FileData.class, initBatchObject(identity, FileData.class));
    for (FileData fileData : fileDatas) {
        // 进行转化
        Long tableId = fileData.getTableId();
        Pipeline pipeline = configClientService.findPipeline(identity.getPipelineId());
        // 针对每个同步数据,可能会存在多路复制的情况
        List<DataMediaPair> dataMediaPairs = ConfigHelper.findDataMediaPairByMediaId(pipeline, tableId);
        for (DataMediaPair pair : dataMediaPairs) {
            if (!pair.getSource().getId().equals(tableId)) {
                // 过滤tableID不为源的同步
                continue;
            }
            Object item = fileDataTransformer.transform(fileData, new OtterTransformerContext(identity, pair, pipeline));
            if (item == null) {
                continue;
            }
            // 合并结果
            merge(identity, result, item);
        }
    }
    return result;
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) HashMap(java.util.HashMap) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) BatchObject(com.alibaba.otter.shared.etl.model.BatchObject) BatchObject(com.alibaba.otter.shared.etl.model.BatchObject) Identity(com.alibaba.otter.shared.etl.model.Identity) FileData(com.alibaba.otter.shared.etl.model.FileData)

Example 7 with BatchObject

use of com.alibaba.otter.shared.etl.model.BatchObject in project otter by alibaba.

the class OtterTransformerFactory method merge.

// =============================== helper method
// ============================
// 将生成的item对象合并到结果对象中
private synchronized void merge(Identity identity, Map<Class, BatchObject> data, Object item) {
    Class clazz = item.getClass();
    BatchObject batchObject = data.get(clazz);
    // 初始化一下对象
    if (batchObject == null) {
        batchObject = initBatchObject(identity, clazz);
        data.put(clazz, batchObject);
    }
    // 进行merge处理
    if (batchObject instanceof RowBatch) {
        ((RowBatch) batchObject).merge((EventData) item);
    } else if (batchObject instanceof FileBatch) {
        ((FileBatch) batchObject).getFiles().add((FileData) item);
    } else {
        throw new TransformException("no support Data[" + clazz.getName() + "]");
    }
}
Also used : FileBatch(com.alibaba.otter.shared.etl.model.FileBatch) RowBatch(com.alibaba.otter.shared.etl.model.RowBatch) BatchObject(com.alibaba.otter.shared.etl.model.BatchObject) TransformException(com.alibaba.otter.node.etl.transform.exception.TransformException) FileData(com.alibaba.otter.shared.etl.model.FileData)

Aggregations

BatchObject (com.alibaba.otter.shared.etl.model.BatchObject)7 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)5 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)5 Identity (com.alibaba.otter.shared.etl.model.Identity)5 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)3 DbDataMedia (com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)3 EventData (com.alibaba.otter.shared.etl.model.EventData)3 FileData (com.alibaba.otter.shared.etl.model.FileData)3 RowBatch (com.alibaba.otter.shared.etl.model.RowBatch)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 PipelineParameter (com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter)2 FileBatch (com.alibaba.otter.shared.etl.model.FileBatch)2 HashMap (java.util.HashMap)2 AggregationItem (com.alibaba.otter.node.etl.common.jmx.StageAggregation.AggregationItem)1 PipeKey (com.alibaba.otter.node.etl.common.pipe.PipeKey)1 SetlFuture (com.alibaba.otter.node.etl.extract.SetlFuture)1 TransformException (com.alibaba.otter.node.etl.transform.exception.TransformException)1 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)1 DbBatch (com.alibaba.otter.shared.etl.model.DbBatch)1