Search in sources :

Example 6 with NoSqlFieldsModel

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;
}
Also used : NoSqlFieldsModel(org.sagacity.sqltoy.config.model.NoSqlFieldsModel)

Aggregations

NoSqlFieldsModel (org.sagacity.sqltoy.config.model.NoSqlFieldsModel)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 DataSetResult (org.sagacity.sqltoy.model.inner.DataSetResult)5 JSONArray (com.alibaba.fastjson.JSONArray)4 JSONObject (com.alibaba.fastjson.JSONObject)4 ElasticEndpoint (org.sagacity.sqltoy.config.model.ElasticEndpoint)2 HashMap (java.util.HashMap)1 Document (org.bson.Document)1 NoSqlConfigModel (org.sagacity.sqltoy.config.model.NoSqlConfigModel)1