ZillionUtil.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from MyUtils.MetadataWebUtil import MetadataWebUtil
  2. class ZillionUtil():
  3. def __init__(self, url):
  4. self.metadata = MetadataWebUtil(url)
  5. ##列出所有数据库
  6. def database_list(self):
  7. param = {
  8. "QueryType": "database_list"
  9. }
  10. databases = self.metadata.get_hbase(param)
  11. return databases["Content"]
  12. # TODO 其他zillion语句
  13. ##列出所有数据库下的表(不包含分表)
  14. def table_list_strict(self,table):
  15. param = {
  16. "QueryType":"table_list_strict",
  17. "Database":table
  18. }
  19. databases = self.metadata.get_hbase(param)
  20. return databases["Content"]
  21. ##列出所有数据库
  22. # def query(self, database, table, Criteria):
  23. # param = {
  24. # "QueryType": "select",
  25. # "Database": database,
  26. # "Datatable": table,
  27. # "Criteria": Criteria
  28. # }
  29. # print(param)
  30. # databases = self.metadata.get_hbase(param)
  31. # return databases["Content"]
  32. def select(self, database, table, Criteria):
  33. param = {
  34. "QueryType": "select",
  35. "Database": database,
  36. "Datatable": table,
  37. "Criteria": Criteria
  38. }
  39. databases = self.metadata.get_hbase(param)
  40. return databases["Content"]
  41. def table_key(self, database, table):
  42. param = {
  43. "QueryType": "table_detail",
  44. "Database": database,
  45. "Datatable": table
  46. }
  47. databases = self.metadata.get_hbase(param)
  48. key = databases["Content"]["Key"]
  49. return key
  50. def select_count(self, database, table, Criteria):
  51. param = {
  52. "QueryType": "select_count",
  53. "Database": database,
  54. "Datatable": table,
  55. "Criteria": Criteria
  56. }
  57. databases = self.metadata.get_hbase(param)
  58. return databases["Count"]
  59. def query_data(self, sql):
  60. databases = self.metadata.get_hbase(sql)
  61. return databases["Content"]
  62. def insert(self,database,table,InsertObject):
  63. param = {
  64. "QueryType": "batch_insert",
  65. "Database": database,
  66. "Datatable": table,
  67. "InsertObjects": InsertObject
  68. }
  69. databases = self.metadata.get_hbase(param)
  70. return databases["Count"]
  71. def remove(self,database,table,key):
  72. param = {
  73. "QueryType": "remove",
  74. "Database": database,
  75. "Datatable": table,
  76. "Key": key
  77. }
  78. databases = self.metadata.get_hbase(param)
  79. return databases["Count"]
  80. def put(self,database,table,InsertObject):
  81. param = {
  82. "QueryType": "batch_put",
  83. "Database": database,
  84. "Datatable": table,
  85. "InsertObjects": InsertObject
  86. }
  87. databases = self.metadata.get_hbase(param)
  88. return databases["Result"]