use of org.sagacity.sqltoy.config.model.NoSqlFieldsModel in project sagacity-sqltoy by chenrenfei.
the class MongoElasticUtils method processFields.
/**
* @TODO 统一解析elastic或mongodb 的fields 信息,分解成fieldName 和 aliasName
* @param fields
* @param fieldMap
* @return
*/
public static NoSqlFieldsModel processFields(String[] fields, HashMap<String, String[]> fieldMap) {
NoSqlFieldsModel result = new NoSqlFieldsModel();
String[] realFields = new String[fields.length];
String[] aliasFields = new String[fields.length];
int aliasIndex = 0;
for (int i = 0; i < fields.length; i++) {
realFields[i] = fields[i];
aliasFields[i] = fields[i];
aliasIndex = fields[i].indexOf(":");
if (aliasIndex != -1) {
realFields[i] = fields[i].substring(0, aliasIndex).trim();
aliasFields[i] = fields[i].substring(aliasIndex + 1).trim();
} else {
aliasIndex = fields[i].lastIndexOf(".");
if (aliasIndex != -1) {
aliasFields[i] = fields[i].substring(aliasIndex + 1).trim();
}
}
// 放入缓存为了提升效率
if (fieldMap != null && realFields[i].contains(".")) {
fieldMap.put(realFields[i], realFields[i].split("\\."));
}
}
result.setFields(realFields);
result.setAliasLabels(aliasFields);
return result;
}
Aggregations