Search in sources :

Example 1 with ColumnGroup

use of com.alibaba.otter.shared.common.model.config.data.ColumnGroup in project otter by alibaba.

the class DataColumnPairGroupServiceImpl method listByDataMediaPairIds.

@Override
public Map<Long, List<ColumnGroup>> listByDataMediaPairIds(Long... dataMediaPairIds) {
    Assert.assertNotNull(dataMediaPairIds);
    Map<Long, List<ColumnGroup>> dataColumnGroups = new HashMap<Long, List<ColumnGroup>>();
    try {
        List<DataColumnPairGroupDO> dataColumnPairGroupDos = dataColumnPairGroupDao.ListByDataMediaPairIds(dataMediaPairIds);
        if (CollectionUtils.isEmpty(dataColumnPairGroupDos)) {
            logger.debug("DEBUG ## couldn't query any dataColumnPairGroup, maybe hasn't create any dataColumnPairGroup.");
            return dataColumnGroups;
        }
        for (DataColumnPairGroupDO dataColumnPairGroupDo : dataColumnPairGroupDos) {
            List<ColumnGroup> columnGroups = dataColumnGroups.get(dataColumnPairGroupDo.getDataMediaPairId());
            if (columnGroups != null) {
                if (!columnGroups.contains(doToModel(dataColumnPairGroupDo))) {
                    columnGroups.add(doToModel(dataColumnPairGroupDo));
                }
            } else {
                columnGroups = new ArrayList<ColumnGroup>();
                columnGroups.add(doToModel(dataColumnPairGroupDo));
                dataColumnGroups.put(dataColumnPairGroupDo.getDataMediaPairId(), columnGroups);
            }
        }
    } catch (Exception e) {
        logger.error("ERROR ## query dataColumnPairGroup by dataMediaId:" + dataMediaPairIds + " has an exception!");
        throw new ManagerException(e);
    }
    return dataColumnGroups;
}
Also used : HashMap(java.util.HashMap) DataColumnPairGroupDO(com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject.DataColumnPairGroupDO) ArrayList(java.util.ArrayList) List(java.util.List) ColumnGroup(com.alibaba.otter.shared.common.model.config.data.ColumnGroup) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 2 with ColumnGroup

use of com.alibaba.otter.shared.common.model.config.data.ColumnGroup in project otter by alibaba.

the class DataColumnPairGroupServiceImpl method doToModel.

/*-------------------------------------------------------------*/
/**
     * 用于DO对象转化为Model对象
     */
private ColumnGroup doToModel(DataColumnPairGroupDO dataColumnPairGroupDo) {
    ColumnGroup columnGroup = new ColumnGroup();
    columnGroup.setId(dataColumnPairGroupDo.getId());
    List<ColumnPair> columnPairs = new ArrayList<ColumnPair>();
    if (StringUtils.isNotBlank(dataColumnPairGroupDo.getColumnPairContent())) {
        columnPairs = JsonUtils.unmarshalFromString(dataColumnPairGroupDo.getColumnPairContent(), new TypeReference<ArrayList<ColumnPair>>() {
        });
    }
    columnGroup.setColumnPairs(columnPairs);
    columnGroup.setDataMediaPairId(dataColumnPairGroupDo.getDataMediaPairId());
    columnGroup.setGmtCreate(dataColumnPairGroupDo.getGmtCreate());
    columnGroup.setGmtModified(dataColumnPairGroupDo.getGmtModified());
    return columnGroup;
}
Also used : ColumnPair(com.alibaba.otter.shared.common.model.config.data.ColumnPair) ArrayList(java.util.ArrayList) TypeReference(com.alibaba.fastjson.TypeReference) ColumnGroup(com.alibaba.otter.shared.common.model.config.data.ColumnGroup)

Example 3 with ColumnGroup

use of com.alibaba.otter.shared.common.model.config.data.ColumnGroup in project otter by alibaba.

the class GroupExtractor method extract.

@Override
public void extract(DbBatch dbBatch) throws ExtractException {
    Assert.notNull(dbBatch);
    Assert.notNull(dbBatch.getRowBatch());
    Pipeline pipeline = getPipeline(dbBatch.getRowBatch().getIdentity().getPipelineId());
    List<DataMediaPair> dataMediaPairs = pipeline.getPairs();
    /**
         * Key = TableId<br>
         * Value = a List of this tableId's column need to sync<br>
         */
    Map<Long, List<ColumnGroup>> groupColumns = new HashMap<Long, List<ColumnGroup>>();
    for (DataMediaPair dataMediaPair : dataMediaPairs) {
        List<ColumnGroup> columnGroups = dataMediaPair.getColumnGroups();
        if (!CollectionUtils.isEmpty(columnGroups)) {
            groupColumns.put(dataMediaPair.getSource().getId(), columnGroups);
        }
    }
    List<EventData> eventDatas = dbBatch.getRowBatch().getDatas();
    for (EventData eventData : eventDatas) {
        if (eventData.getEventType().isDdl()) {
            continue;
        }
        List<ColumnGroup> columnGroups = groupColumns.get(eventData.getTableId());
        if (!CollectionUtils.isEmpty(columnGroups)) {
            for (ColumnGroup columnGroup : columnGroups) {
                if (columnGroup != null && !CollectionUtils.isEmpty(columnGroup.getColumnPairs())) {
                    groupFilter(eventData, columnGroup);
                }
            }
        }
    }
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ColumnGroup(com.alibaba.otter.shared.common.model.config.data.ColumnGroup) EventData(com.alibaba.otter.shared.etl.model.EventData) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 4 with ColumnGroup

use of com.alibaba.otter.shared.common.model.config.data.ColumnGroup in project otter by alibaba.

the class DataMediaPairServiceImpl method doToModel.

private List<DataMediaPair> doToModel(List<DataMediaPairDO> dataMediaPairDos) {
    List<Long> dataMediaPairIds = new ArrayList<Long>();
    for (DataMediaPairDO dataMediaPairDo : dataMediaPairDos) {
        dataMediaPairIds.add(dataMediaPairDo.getId());
    }
    Map<Long, List<ColumnPair>> columnPairMap = dataColumnPairService.listByDataMediaPairIds(dataMediaPairIds.toArray(new Long[dataMediaPairIds.size()]));
    Map<Long, List<ColumnGroup>> columnPairGroupMap = dataColumnPairGroupService.listByDataMediaPairIds(dataMediaPairIds.toArray(new Long[dataMediaPairIds.size()]));
    List<DataMediaPair> dataMediaPairs = new ArrayList<DataMediaPair>();
    for (DataMediaPairDO dataMediaPairDo : dataMediaPairDos) {
        List<ColumnPair> columnPairs = columnPairMap.get(dataMediaPairDo.getId()) == null ? new ArrayList<ColumnPair>() : columnPairMap.get(dataMediaPairDo.getId());
        List<ColumnGroup> columnGroups = columnPairGroupMap.get(dataMediaPairDo.getId()) == null ? new ArrayList<ColumnGroup>() : columnPairGroupMap.get(dataMediaPairDo.getId());
        dataMediaPairs.add(doToModel(dataMediaPairDo, columnPairs, columnGroups));
    }
    return dataMediaPairs;
}
Also used : ColumnPair(com.alibaba.otter.shared.common.model.config.data.ColumnPair) DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ColumnGroup(com.alibaba.otter.shared.common.model.config.data.ColumnGroup) DataMediaPairDO(com.alibaba.otter.manager.biz.config.datamediapair.dal.dataobject.DataMediaPairDO)

Example 5 with ColumnGroup

use of com.alibaba.otter.shared.common.model.config.data.ColumnGroup in project otter by alibaba.

the class ColumnPairGroupAction method doSave.

public void doSave(@Param("dataMediaPairId") Long dataMediaPairId, @Param("submitKey") String submitKey, @Param("pipelineId") Long pipelineId, @FormGroup("columnPairGroupInfo") Group columnPairGroupInfo, @FormField(name = "formColumnPairGroupError", group = "columnPairGroupInfo") CustomErrors err, Navigator nav) throws Exception {
    String[] columnPairStrings = columnPairGroupInfo.getField("groupResult").getStringValues();
    ColumnGroup columnGroup = new ColumnGroup();
    List<ColumnPair> columnPairs = new ArrayList<ColumnPair>();
    for (String columnPairString : columnPairStrings) {
        ColumnPair columnPair = new ColumnPair();
        String[] temp = columnPairString.split(COLON);
        columnPair.setSourceColumn(new Column(temp[0]));
        columnPair.setTargetColumn(new Column(temp[1]));
        columnPair.setDataMediaPairId(dataMediaPairId);
        columnPairs.add(columnPair);
    }
    columnGroup.setColumnPairs(columnPairs);
    columnGroup.setDataMediaPairId(dataMediaPairId);
    dataColumnPairGroupService.removeByDataMediaPairId(dataMediaPairId);
    dataColumnPairGroupService.create(columnGroup);
    nav.redirectToLocation("dataMediaPairList.htm?pipelineId=" + pipelineId);
}
Also used : ColumnPair(com.alibaba.otter.shared.common.model.config.data.ColumnPair) Column(com.alibaba.otter.shared.common.model.config.data.Column) ArrayList(java.util.ArrayList) ColumnGroup(com.alibaba.otter.shared.common.model.config.data.ColumnGroup)

Aggregations

ColumnGroup (com.alibaba.otter.shared.common.model.config.data.ColumnGroup)7 ArrayList (java.util.ArrayList)6 ColumnPair (com.alibaba.otter.shared.common.model.config.data.ColumnPair)5 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)4 List (java.util.List)3 HashMap (java.util.HashMap)2 TypeReference (com.alibaba.fastjson.TypeReference)1 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)1 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)1 DataColumnPairGroupDO (com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject.DataColumnPairGroupDO)1 DataMediaPairDO (com.alibaba.otter.manager.biz.config.datamediapair.dal.dataobject.DataMediaPairDO)1 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)1 Column (com.alibaba.otter.shared.common.model.config.data.Column)1 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)1 EventData (com.alibaba.otter.shared.etl.model.EventData)1