123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.hbase.HBaseConfiguration;
- import org.zillion.util.json.FastJsonReaderUtil;
- import org.zillion.util.json.FastJsonUtil;
- import org.zillion.util.log.LogUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.zillion.database.agent.ZillionAgent;
- import com.zillion.database.consistency.StrongConsistencyUtil;
- import com.zillion.util.common.ZillionConstant;
- import com.zillion.util.table.ZillionTableColumn;
- import com.zillion.util.table.ZillionTableColumnEnum;
- import com.zillion.util.table.ZillionTableSchema;
- public class AgentTest_select {
- public static void main(String[] args) throws Exception {
- System.setProperty("java.security.krb5.conf", "D:\\Test\\krb5.conf");
- System.setProperty("java.security.krb5.realm", "HADOOP.COM");
- System.setProperty("java.security.krb5.kdc", "node1");
- System.setProperty("java.security.auth.login.config", "D:\\Test\\zk-jaas.conf");
- // System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
- ZillionConstant.printCriteriaGroup = true;
- Configuration configuration = HBaseConfiguration.create();
- ZillionAgent agent = new ZillionAgent(configuration, "abc");
- // IZillionAgent agent = new ZillionAgentWebImpl("http://101.201.234.108:8555/metadata-web/");
- try {
- agent.Start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- String database_name = "db_test";
- String table_name = "table_strong_consistency_es";
- // ZillionTableSchema ss = agent.container.repositoryMap.get(database_name).GetTable(table_name);
- // List<JSONArray> ContentList = new ArrayList<JSONArray>();
- // boolean not_consistency = StrongConsistencyUtil.not_consistency(ss, agent, database_name, table_name, ContentList);
- // LogUtil.warn("not_consistency" + "\t" + not_consistency);
- // for (int i = 0; i < ContentList.size(); i++) {
- // JSONArray Content = ContentList.get(i);
- // LogUtil.warn(Content.toJSONString());
- // }
- // for (int ii = 0; ii < Integer.MAX_VALUE; ii++) {
- // Thread.sleep(1000L);
- // }
- ////////////////////////////////////////////////////////////////
- JSONArray wrapperObjects = FastJsonReaderUtil.Instance().ReadJSONArray(new File("etc/selects.json"));
- for (int i = 0; i < wrapperObjects.size(); i++) {
- JSONObject wrapperObject = (JSONObject) wrapperObjects.get(i);
- database_name = (String) wrapperObject.get("Database");
- table_name = (String) wrapperObject.get("Datatable");
- try {
- agent.NDL_AddDatabase(database_name);
- } catch (Exception e1) {
- // e1.printStackTrace();
- }
- try {
- LogUtil.warn("" + new Date());
- // LogUtil.warn("Query:\n" + FastJsonUtil.toFormatString(wrapperObject));
- JSONObject queryResult = agent.Query(wrapperObject, true);
- LogUtil.warn("Result:\n" + FastJsonUtil.toFormatString(queryResult));
- LogUtil.warn("" + new Date());
- Object contentObject = queryResult.get("Content");
- if (contentObject != null) {
- if (contentObject instanceof JSONArray) {
- JSONArray resultContent = (JSONArray) contentObject;
- ZillionTableSchema schema = agent.container.repositoryMap.get(database_name).GetTable(table_name);
- print(schema, resultContent);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- Thread.sleep(100L);
- }
- agent.Stop();
- }
- static void print(ZillionTableSchema schema, JSONArray resultContent) {
- List<String> columnList = new ArrayList<String>();
- for (String column : schema.Key) {
- columnList.add(column);
- }
- for (String column : schema.OtherColumn) {
- columnList.add(column);
- }
- for (String column : columnList) {
- System.out.printf("%20s", column);
- System.out.print("\t");
- }
- System.out.println();
- for (int i = 0; i < resultContent.size(); i++) {
- JSONObject item = (JSONObject) resultContent.get(i);
- for (String column : columnList) {
- if (item.containsKey(column)) {
- ZillionTableColumn column_schema = schema.ColumnMap.get(column);
- if (column_schema.Type == ZillionTableColumnEnum.BOOLEAN) {
- System.out.printf("%20s", ((Boolean) item.get(column)) ? "true" : "false");
- } else if (column_schema.Type == ZillionTableColumnEnum.LONG) {
- System.out.printf("%20d", (Long) item.get(column));
- } else if (column_schema.Type == ZillionTableColumnEnum.DOUBLE) {
- System.out.printf("%20.2f", (Double) item.get(column));
- } else if (column_schema.Type == ZillionTableColumnEnum.STRING) {
- System.out.printf("%20s", (String) item.get(column));
- }
- System.out.print("\t");
- }
- }
- System.out.println();
- }
- }
- }
|