/*** SQL 联想搜索返回随机的16个* &#64;param sql* &#64;return*/&#64;Overridepublic String sqlLenovo(String sql, String db) {List> result &#61; new ArrayList<>();MySQLUtil mySQLUtil &#61; new MySQLUtil(configUtil.readConfig("hive.meta.url"),configUtil.readConfig("hive.meta.username"),configUtil.readConfig("hive.meta.password"));if (sql.endsWith(" ")) {return returnResultModel.generateResult(Integer.parseInt(configUtil.readConfig("return.success")),configUtil.readConfig("return.msg.success"),result);}if (sql.trim().equals("") || sql.trim().equals(".")) {return returnResultModel.generateResult(Integer.parseInt(configUtil.readConfig("return.success")),configUtil.readConfig("return.msg.success"),result);}String key &#61; sql.trim().split(" ")[sql.trim().split(" ").length - 1];List keyList &#61; new ArrayList<>(Arrays.asList(key.split("\\.")));if (key.contains(".") && keyList.size() > 1) {key &#61; key.split("\\.")[1];LOG.info(key);} else if (key.contains(".") && keyList.size() &#61;&#61; 1){key &#61; key.split("\\.")[0];LOG.info(key);}if (!key.isEmpty()) {if (configUtil.readConfig("data.engine.hive").equals(db)) {// 匹配关键字List keyWordTemp &#61; new ArrayList<>(Arrays.asList(configUtil.readConfig("hive.keywords").split(",")));if (!keyWordTemp.isEmpty()) {int i &#61; 0;for (String keyTemp : keyWordTemp) {if (i &#61;&#61; 4) break;if (keyTemp.startsWith(key.toUpperCase())) {Map mapKeyWord &#61; Maps.newHashMap();mapKeyWord.put("key", i);mapKeyWord.put("name", keyTemp);mapKeyWord.put("type", "KeyWord");result.add(mapKeyWord);i &#43;&#61; 1;}}}// 匹配表名String mysqlTable &#61; "select TBL_NAME from TBLS where TBL_NAME like \&#39;" &#43; key.toLowerCase() &#43; "%\&#39; limit 4";List> tableData &#61; mySQLUtil.executeQuery(mysqlTable);if (!tableData.isEmpty()) {int j &#61; 5;for (List dataTemp : tableData) {for (String dat : dataTemp) {Map mapTable &#61; Maps.newHashMap();mapTable.put("name", dat);mapTable.put("key", j);mapTable.put("type", "Table");result.add(mapTable);j &#43;&#61; 1;}}}// 字段String mysqlCol &#61; "select COLUMN_NAME from COLUMNS_V2 where COLUMN_NAME like \&#39;" &#43; key.toLowerCase() &#43; "%\&#39; limit 4";List> colData &#61; mySQLUtil.executeQuery(mysqlCol);if (!colData.isEmpty()) {int count &#61; 10;for (List dataTemp : colData) {for (String dat : dataTemp) {Map mapColumn &#61; Maps.newHashMap();mapColumn.put("name", dat);mapColumn.put("key", count);mapColumn.put("type", "Column");result.add(mapColumn);count &#43;&#61; 1;}}}// 匹配聚合函数List funcTemp &#61; new ArrayList<>(Arrays.asList(configUtil.readConfig("hive.func").split(",")));if (!funcTemp.isEmpty()) {int k &#61; 15;for (String funcT : funcTemp) {if (k &#61;&#61; 19) break;if (funcT.startsWith(key.toUpperCase())) {Map mapFunc &#61; Maps.newHashMap();mapFunc.put("key", k);mapFunc.put("name", funcT);mapFunc.put("type", "Func");result.add(mapFunc);k &#43;&#61; 1;}}}}}