AgentTest_select.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import java.io.File;
  2. import java.util.ArrayList;
  3. import java.util.Date;
  4. import java.util.List;
  5. import org.apache.hadoop.conf.Configuration;
  6. import org.apache.hadoop.hbase.HBaseConfiguration;
  7. import org.zillion.util.json.FastJsonReaderUtil;
  8. import org.zillion.util.json.FastJsonUtil;
  9. import org.zillion.util.log.LogUtil;
  10. import com.alibaba.fastjson.JSONArray;
  11. import com.alibaba.fastjson.JSONObject;
  12. import com.zillion.database.agent.ZillionAgent;
  13. import com.zillion.database.consistency.StrongConsistencyUtil;
  14. import com.zillion.util.common.ZillionConstant;
  15. import com.zillion.util.table.ZillionTableColumn;
  16. import com.zillion.util.table.ZillionTableColumnEnum;
  17. import com.zillion.util.table.ZillionTableSchema;
  18. public class AgentTest_select {
  19. public static void main(String[] args) throws Exception {
  20. System.setProperty("java.security.krb5.conf", "D:\\Test\\krb5.conf");
  21. System.setProperty("java.security.krb5.realm", "HADOOP.COM");
  22. System.setProperty("java.security.krb5.kdc", "node1");
  23. System.setProperty("java.security.auth.login.config", "D:\\Test\\zk-jaas.conf");
  24. // System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
  25. ZillionConstant.printCriteriaGroup = true;
  26. Configuration configuration = HBaseConfiguration.create();
  27. ZillionAgent agent = new ZillionAgent(configuration, "abc");
  28. // IZillionAgent agent = new ZillionAgentWebImpl("http://101.201.234.108:8555/metadata-web/");
  29. try {
  30. agent.Start();
  31. } catch (Exception e) {
  32. e.printStackTrace();
  33. }
  34. String database_name = "db_test";
  35. String table_name = "table_strong_consistency_es";
  36. // ZillionTableSchema ss = agent.container.repositoryMap.get(database_name).GetTable(table_name);
  37. // List<JSONArray> ContentList = new ArrayList<JSONArray>();
  38. // boolean not_consistency = StrongConsistencyUtil.not_consistency(ss, agent, database_name, table_name, ContentList);
  39. // LogUtil.warn("not_consistency" + "\t" + not_consistency);
  40. // for (int i = 0; i < ContentList.size(); i++) {
  41. // JSONArray Content = ContentList.get(i);
  42. // LogUtil.warn(Content.toJSONString());
  43. // }
  44. // for (int ii = 0; ii < Integer.MAX_VALUE; ii++) {
  45. // Thread.sleep(1000L);
  46. // }
  47. ////////////////////////////////////////////////////////////////
  48. JSONArray wrapperObjects = FastJsonReaderUtil.Instance().ReadJSONArray(new File("etc/selects.json"));
  49. for (int i = 0; i < wrapperObjects.size(); i++) {
  50. JSONObject wrapperObject = (JSONObject) wrapperObjects.get(i);
  51. database_name = (String) wrapperObject.get("Database");
  52. table_name = (String) wrapperObject.get("Datatable");
  53. try {
  54. agent.NDL_AddDatabase(database_name);
  55. } catch (Exception e1) {
  56. // e1.printStackTrace();
  57. }
  58. try {
  59. LogUtil.warn("" + new Date());
  60. // LogUtil.warn("Query:\n" + FastJsonUtil.toFormatString(wrapperObject));
  61. JSONObject queryResult = agent.Query(wrapperObject, true);
  62. LogUtil.warn("Result:\n" + FastJsonUtil.toFormatString(queryResult));
  63. LogUtil.warn("" + new Date());
  64. Object contentObject = queryResult.get("Content");
  65. if (contentObject != null) {
  66. if (contentObject instanceof JSONArray) {
  67. JSONArray resultContent = (JSONArray) contentObject;
  68. ZillionTableSchema schema = agent.container.repositoryMap.get(database_name).GetTable(table_name);
  69. print(schema, resultContent);
  70. }
  71. }
  72. } catch (Exception e) {
  73. e.printStackTrace();
  74. }
  75. Thread.sleep(100L);
  76. }
  77. agent.Stop();
  78. }
  79. static void print(ZillionTableSchema schema, JSONArray resultContent) {
  80. List<String> columnList = new ArrayList<String>();
  81. for (String column : schema.Key) {
  82. columnList.add(column);
  83. }
  84. for (String column : schema.OtherColumn) {
  85. columnList.add(column);
  86. }
  87. for (String column : columnList) {
  88. System.out.printf("%20s", column);
  89. System.out.print("\t");
  90. }
  91. System.out.println();
  92. for (int i = 0; i < resultContent.size(); i++) {
  93. JSONObject item = (JSONObject) resultContent.get(i);
  94. for (String column : columnList) {
  95. if (item.containsKey(column)) {
  96. ZillionTableColumn column_schema = schema.ColumnMap.get(column);
  97. if (column_schema.Type == ZillionTableColumnEnum.BOOLEAN) {
  98. System.out.printf("%20s", ((Boolean) item.get(column)) ? "true" : "false");
  99. } else if (column_schema.Type == ZillionTableColumnEnum.LONG) {
  100. System.out.printf("%20d", (Long) item.get(column));
  101. } else if (column_schema.Type == ZillionTableColumnEnum.DOUBLE) {
  102. System.out.printf("%20.2f", (Double) item.get(column));
  103. } else if (column_schema.Type == ZillionTableColumnEnum.STRING) {
  104. System.out.printf("%20s", (String) item.get(column));
  105. }
  106. System.out.print("\t");
  107. }
  108. }
  109. System.out.println();
  110. }
  111. }
  112. }