Search in sources :

Example 6 with RowData

use of com.alibaba.otter.canal.protocol.CanalEntry.RowData in project otter by alibaba.

the class MessageParser method internParse.

private List<EventData> internParse(Pipeline pipeline, Entry entry) {
    RowChange rowChange = null;
    try {
        rowChange = RowChange.parseFrom(entry.getStoreValue());
    } catch (Exception e) {
        throw new SelectException("parser of canal-event has an error , data:" + entry.toString(), e);
    }
    if (rowChange == null) {
        return null;
    }
    String schemaName = entry.getHeader().getSchemaName();
    String tableName = entry.getHeader().getTableName();
    EventType eventType = EventType.valueOf(rowChange.getEventType().name());
    // 处理下DDL操作
    if (eventType.isQuery()) {
        // 直接忽略query事件
        return null;
    }
    // 首先判断是否为系统表
    if (StringUtils.equalsIgnoreCase(pipeline.getParameters().getSystemSchema(), schemaName)) {
        // do noting
        if (eventType.isDdl()) {
            return null;
        }
        if (StringUtils.equalsIgnoreCase(pipeline.getParameters().getSystemDualTable(), tableName)) {
            // 心跳表数据直接忽略
            return null;
        }
    } else {
        if (eventType.isDdl()) {
            boolean notExistReturnNull = false;
            if (eventType.isRename()) {
                notExistReturnNull = true;
            }
            DataMedia dataMedia = ConfigHelper.findSourceDataMedia(pipeline, schemaName, tableName, notExistReturnNull);
            // DataMediaInfo;并且把CREATE/ALTER类型的事件丢弃掉.
            if (dataMedia != null && (eventType.isCreate() || eventType.isAlter() || eventType.isRename())) {
                DbDialect dbDialect = dbDialectFactory.getDbDialect(pipeline.getId(), (DbMediaSource) dataMedia.getSource());
                // 更新下meta信息
                dbDialect.reloadTable(schemaName, tableName);
            }
            boolean ddlSync = pipeline.getParameters().getDdlSync();
            if (ddlSync) {
                // 处理下ddl操作
                EventData eventData = new EventData();
                eventData.setSchemaName(schemaName);
                eventData.setTableName(tableName);
                eventData.setEventType(eventType);
                eventData.setExecuteTime(entry.getHeader().getExecuteTime());
                eventData.setSql(rowChange.getSql());
                eventData.setDdlSchemaName(rowChange.getDdlSchemaName());
                eventData.setTableId(dataMedia.getId());
                return Arrays.asList(eventData);
            } else {
                return null;
            }
        }
    }
    List<EventData> eventDatas = new ArrayList<EventData>();
    for (RowData rowData : rowChange.getRowDatasList()) {
        EventData eventData = internParse(pipeline, entry, rowChange, rowData);
        if (eventData != null) {
            eventDatas.add(eventData);
        }
    }
    return eventDatas;
}
Also used : RowData(com.alibaba.otter.canal.protocol.CanalEntry.RowData) RowChange(com.alibaba.otter.canal.protocol.CanalEntry.RowChange) EventType(com.alibaba.otter.shared.etl.model.EventType) DbDialect(com.alibaba.otter.node.etl.common.db.dialect.DbDialect) SelectException(com.alibaba.otter.node.etl.select.exceptions.SelectException) ArrayList(java.util.ArrayList) SelectException(com.alibaba.otter.node.etl.select.exceptions.SelectException) TransformException(com.alibaba.otter.node.etl.transform.exception.TransformException) DataMedia(com.alibaba.otter.shared.common.model.config.data.DataMedia) EventData(com.alibaba.otter.shared.etl.model.EventData)

Aggregations

RowChange (com.alibaba.otter.canal.protocol.CanalEntry.RowChange)6 RowData (com.alibaba.otter.canal.protocol.CanalEntry.RowData)6 Entry (com.alibaba.otter.canal.protocol.CanalEntry.Entry)5 EventType (com.alibaba.otter.canal.protocol.CanalEntry.EventType)5 CanalParseException (com.alibaba.otter.canal.parse.exception.CanalParseException)3 AbstractLogPositionManager (com.alibaba.otter.canal.parse.index.AbstractLogPositionManager)3 AbstractCanalEventSinkTest (com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest)3 AuthenticationInfo (com.alibaba.otter.canal.parse.support.AuthenticationInfo)3 LogPosition (com.alibaba.otter.canal.protocol.position.LogPosition)3 CanalSinkException (com.alibaba.otter.canal.sink.exception.CanalSinkException)3 InetSocketAddress (java.net.InetSocketAddress)3 List (java.util.List)3 Test (org.junit.Test)3 TransactionBegin (com.alibaba.otter.canal.protocol.CanalEntry.TransactionBegin)2 TransactionEnd (com.alibaba.otter.canal.protocol.CanalEntry.TransactionEnd)2 EntryPosition (com.alibaba.otter.canal.protocol.position.EntryPosition)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 Date (java.util.Date)2 AviaterRegexFilter (com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter)1 RdsLocalBinlogEventParser (com.alibaba.otter.canal.parse.inbound.mysql.rds.RdsLocalBinlogEventParser)1