Search in sources :

Example 21 with FieldItem

use of com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem 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

FieldItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem)21 LinkedHashMap (java.util.LinkedHashMap)12 SchemaItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem)10 ESMapping (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig.ESMapping)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ColumnItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.ColumnItem)5 TableItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.TableItem)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 ESBulkRequest (com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest)2 ESBulkResponse (com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESBulkResponse)2 ESIndexRequest (com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESIndexRequest)2 ESUpdateRequest (com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESUpdateRequest)2 DataSource (javax.sql.DataSource)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 SearchHit (org.elasticsearch.search.SearchHit)2