Search in sources :

Example 11 with SchemaItem

use of com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem in project canal by alibaba.

the class ES6xTemplate method getESDataFromDmlData.

@Override
public Object getESDataFromDmlData(ESSyncConfig.ESMapping mapping, Map<String, Object> dmlData, Map<String, Object> dmlOld, Map<String, Object> esFieldData) {
    SchemaItem schemaItem = mapping.getSchemaItem();
    String idFieldName = mapping.get_id() == null ? mapping.getPk() : mapping.get_id();
    Object resultIdVal = null;
    for (FieldItem fieldItem : schemaItem.getSelectFields().values()) {
        String columnName = fieldItem.getColumnItems().iterator().next().getColumnName();
        if (fieldItem.getFieldName().equals(idFieldName)) {
            resultIdVal = getValFromData(mapping, dmlData, fieldItem.getFieldName(), columnName);
        }
        if (dmlOld.containsKey(columnName) && !mapping.getSkips().contains(fieldItem.getFieldName())) {
            esFieldData.put(Util.cleanColumn(fieldItem.getFieldName()), getValFromData(mapping, dmlData, fieldItem.getFieldName(), columnName));
        }
    }
    // 添加父子文档关联信息
    putRelationData(mapping, schemaItem, dmlOld, esFieldData);
    return resultIdVal;
}
Also used : SchemaItem(com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem) FieldItem(com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem)

Example 12 with SchemaItem

use of com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem in project canal by alibaba.

the class ES7xTemplate method getESDataFromDmlData.

@Override
public Object getESDataFromDmlData(ESMapping mapping, Map<String, Object> dmlData, Map<String, Object> dmlOld, Map<String, Object> esFieldData) {
    SchemaItem schemaItem = mapping.getSchemaItem();
    String idFieldName = mapping.get_id() == null ? mapping.getPk() : mapping.get_id();
    Object resultIdVal = null;
    for (FieldItem fieldItem : schemaItem.getSelectFields().values()) {
        String columnName = fieldItem.getColumnItems().iterator().next().getColumnName();
        if (fieldItem.getFieldName().equals(idFieldName)) {
            resultIdVal = getValFromData(mapping, dmlData, fieldItem.getFieldName(), columnName);
        }
        if (dmlOld.containsKey(columnName) && !mapping.getSkips().contains(fieldItem.getFieldName())) {
            esFieldData.put(Util.cleanColumn(fieldItem.getFieldName()), getValFromData(mapping, dmlData, fieldItem.getFieldName(), columnName));
        }
    }
    // 添加父子文档关联信息
    putRelationData(mapping, schemaItem, dmlOld, esFieldData);
    return resultIdVal;
}
Also used : SchemaItem(com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem) FieldItem(com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem)

Aggregations

SchemaItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem)12 FieldItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem)10 TableItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.TableItem)5 ColumnItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.ColumnItem)4 Map (java.util.Map)4 LinkedHashMap (java.util.LinkedHashMap)3 ESMapping (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig.ESMapping)2 List (java.util.List)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 OuterAdapter (com.alibaba.otter.canal.client.adapter.OuterAdapter)1 ESSyncConfig (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig)1 ESSyncConfigLoader (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfigLoader)1 SqlParser (com.alibaba.otter.canal.client.adapter.es.core.config.SqlParser)1 ESConfigMonitor (com.alibaba.otter.canal.client.adapter.es.core.monitor.ESConfigMonitor)1 ESSyncService (com.alibaba.otter.canal.client.adapter.es.core.service.ESSyncService)1 ESTemplate (com.alibaba.otter.canal.client.adapter.es.core.support.ESTemplate)1 DatasourceConfig (com.alibaba.otter.canal.client.adapter.support.DatasourceConfig)1 Dml (com.alibaba.otter.canal.client.adapter.support.Dml)1 EtlResult (com.alibaba.otter.canal.client.adapter.support.EtlResult)1 OuterAdapterConfig (com.alibaba.otter.canal.client.adapter.support.OuterAdapterConfig)1