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 ContentList = new ArrayList(); // 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 columnList = new ArrayList(); 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(); } } }