從HIVE中中查詢

2021-07-27 22:49:49 字數 4174 閱讀 9903

/**

* 從hive資料庫查詢文件 by ymd

// 拼接sql語句

string sql = "select * from doc_file where contains(name ,\"wildcard '"

+ "*" + "'\" ) ";

// 拼接名稱查詢語句

if (stringutils.isnoneempty(unstructuredbean.getname()))

// 拼接操作人語句

if (stringutils.isnoneempty(unstructuredbean.getoptioner()))

// 拼接全文檢索語句

if (stringutils.isnoneempty(unstructuredbean.getsearch()))

// 拼接詳細描述語句

if (stringutils.isnoneempty(unstructuredbean.getdescribes()))

// 拼接開始時間、結束時間語句

if (unstructuredbean.getbegintime() != null

&& unstructuredbean.getendtime() != null)

// 呼叫ws介面 返回jsonarray

jsonarray resarray = toolws.getunstructuredws(sql, unstructuredbean

.getpage().getpageno());

// 所有列名

system.out.println("resarray:" + resarray);

listcolumnnamelist = getcolumnnamelist(resarray);

listbean = toolws.getlistbean(resarray);

sqlbean sqlbean = new sqlbean();

sqlbean.setsql_sentence(sql);

// 總數

long totalnum = toolws.unstructuredtotalnum(sqlbean);

system.out.println("總數:" + totalnum);

// 分頁

pagepage = toolws.getpageinte***ce(sqlbean.getpage()

.getpagesize(), sqlbean.getpage().getpageno(), listbean,

totalnum);

model.addattribute("page", page);

model.addattribute("columnnamelist", columnnamelist);

model.addattribute("unstructuredbean", unstructuredbean);

return "/modules/bankunstructured/unstructured_list";

}

/**

* 根據sql 呼叫hive介面  返回  jsonarray

* @param sql

* @return jsonarray

*/public jsonarray getunstructuredws(string sql,int num)

else

jsonobject jsonobject = new jsonobject();

jsonobject.addproperty("sql", sql);

jsonobject.addproperty("recordnum", "5");      // key:recordnum 分頁(每頁條數)

jsonobject.addproperty("datasource", "hive");      // key:datasource "hive"

jsonobject.addproperty("actiontype", "fullindex");

//獲取頁面第一項序號

jsonobject.addproperty("startlimit", numstr);      // key:startlimit

idispatcherwebserviceservice dispatcherwebserviceservice = new idispatcherwebserviceservice();

idispatcherwebservice service = dispatcherwebserviceservice

.getidispatcherwebserviceport();

gson gson = new gson();

string handle = service.handle(gson.tojson(jsonobject));

infobean infobean = gson.fromjson(handle, infobean.class);

string message = infobean.getmessage();

jsonobject jsonobject = gson.fromjson(message, jsonobject.class);

jsonarray resarray = (jsonarray) jsonobject.get("res");

return resarray;

}

/**

* 將jsonarray 轉換為list返回 list*/

public listgetlistbean(jsonarray jsonarray)

//去掉前後括號並去空格

jsonstr = jsonstr.substring(1,jsonstr.length()-1).replaceall(" ", "");

//擷取逗號

string str1 = jsonstr.split(",");

for (string str : str1)

}sql.setmap(newmap);

list.add(sql);

} return list;

}

/**

* 查詢非結構化資料檢索總條數

* @param sqlbean

* @return

*/public long unstructuredtotalnum(sqlbean sqlbean)

if(jsonarray != null)

//將字串分割成陣列

string strtocolon = strstobracket.split(":");

string column = strtocolon[1].split("\"");

totalnum = long.parselong(column[1]);

} return totalnum;

}

/*** 返回分頁* @param sql* @param listbean* @param totalnum* @return*/ public pagegetpageinte***ce(int pagesize,int pageno, listlistbean,long totalnum)

hive查詢中的排序總結

四個排序總結 order by 全域性排序 reduce啟動個數為乙個 sort by 區內排序和distrbute by 結合使用 reduce個數為多個 distribute by 同上reduce個數為多個 cluster by 當distribute by 和 sort by相同時 使用。r...

如何從SAP中查詢BADI

1 badi物件的資訊儲存在sxs inter,sxc exit,sxc class 和sxc attr這四個表中 參見sece包 2 sap程式都會呼叫cl exithandler get instance來判斷物件是否存在,並返回例項 其實get instance就是對上述幾個表和他們的檢視 v...

Hive的in中不能子查詢,in中的多字段子查詢

error semanticexception error 10249 line 1 146 unsupported subquery expression userid correlating expression cannot contain unqualified column referen...