配置:
dataSourceKey: defaultDS
destination: test
groupId: g1
esMapping:
_index: test_left
_id: _id
upsert: true
sql: "select a.id as _id,a.id as id,a.username as an,b.username as bn from test a left join tt b on a.id = b.id"
commitBatch: 2
现有test表和tt表两张表做left join,当查询两张表字段名称相同时(a.username as an, b.username as bn),修改主表a.username的数据,会导致ES中an(a.username)和bn(b.username)的数据同时被修改为a.username的数据
1条答案
按热度按时间8zzbczxx1#
参照 #2023
getESDataFromDmlData()方法添加参数Dml dml
public Object getESDataFromDmlData(ESMapping mapping, Map<String, Object> dmlData, Map<String, Object> dmlOld,
Map<String, Object> esFieldData, Dml dml) {
SchemaItem schemaItem = mapping.getSchemaItem();
Map<String, SchemaItem.TableItem> tableAliasMap = schemaItem.getAliasTableItems(); //表名 别名 映射
String tableName = dml.getTable(); //获取表名
tableAliasMap.get(tableName);
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);
}
// FIX BUG 主表 从表 存在同名字段。导致解析结果混乱
String owner = fieldItem.getColumnItems().iterator().next().getOwner();//表别名
SchemaItem.TableItem tableItem = tableAliasMap.get(owner); // 转换实际表名
String colunmTable = tableItem.getTableName();
if (!colunmTable.equals(tableName)) { //field不属于dml中的table 忽略
continue;
}
if (dmlOld.get(columnName) != null && !mapping.getSkips().contains(fieldItem.getFieldName())) {
esFieldData.put(fieldItem.getFieldName(),
getValFromData(mapping, dmlData, fieldItem.getFieldName(), columnName));
}
}
return resultIdVal;
}