dummy_client.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env python
  2. # -- coding: utf-8 --
  3. # Licensed to Cloudera, Inc. under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. Cloudera, Inc. licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. import logging
  19. from django.utils.translation import ugettext as _
  20. from desktop.lib.exceptions_renderable import PopupException
  21. from metadata.optimizer.base import Api
  22. LOG = logging.getLogger(__name__)
  23. class DummyClient(Api):
  24. def __init__(self, user, api_url=None, auth_key=None, auth_key_secret=None, tenant_id=None):
  25. self.user = user
  26. def get_tenant(self, cluster_id='default'):
  27. pass
  28. def upload(self, data, data_type='queries', source_platform='generic', workload_id=None):
  29. pass
  30. def upload_status(self, workload_id):
  31. pass
  32. def top_tables(self, workfloadId=None, database_name='default', page_size=1000, startingToken=None, connector=None):
  33. data = {
  34. 'results': [{
  35. "database": "default",
  36. "name": "sample_07",
  37. "workloadPercent": 42,
  38. "columnCount": 4,
  39. "total": 6
  40. }, {
  41. "database": "default",
  42. "name": "sample_08",
  43. "workloadPercent": 21,
  44. "columnCount": 4,
  45. "total": 3
  46. }, {
  47. "database": "default",
  48. "name": "web_logs",
  49. "workloadPercent": 21,
  50. "columnCount": 1,
  51. "total": 3
  52. }, {
  53. "database": "default",
  54. "name": "customers",
  55. "workloadPercent": 7,
  56. "columnCount": 44,
  57. "total": 1
  58. }
  59. ]
  60. }
  61. return data
  62. def table_details(self, database_name, table_name, page_size=100, startingToken=None):
  63. return {}
  64. def query_compatibility(self, source_platform, target_platform, query, page_size=100, startingToken=None):
  65. return {}
  66. def query_risk(self, query, source_platform, db_name, page_size=100, startingToken=None):
  67. hints = []
  68. response = {}
  69. return {
  70. 'hints': hints,
  71. 'noStats': response.get('noStats', []),
  72. 'noDDL': response.get('noDDL', []),
  73. }
  74. def similar_queries(self, source_platform, query, page_size=100, startingToken=None):
  75. raise PopupException(_('Call not supported'))
  76. def top_filters(self, db_tables=None, page_size=100, startingToken=None):
  77. results = {'results': []}
  78. return results
  79. def top_aggs(self, db_tables=None, page_size=100, startingToken=None):
  80. results = {'results': []}
  81. return results
  82. def top_columns(self, db_tables=None, page_size=100, startingToken=None, connector=None):
  83. results = {
  84. 'selectColumns': [{
  85. "dbName": 'default',
  86. "tableName": 'sample_07',
  87. "columnName": 'description',
  88. "columnCount": 2,
  89. "groupbyCol": 0,
  90. "selectCol": 2,
  91. "filterCol": 0,
  92. "joinCol": 0,
  93. "orderbyCol": 0,
  94. "workloadPercent": 100,
  95. }
  96. ]}
  97. return results
  98. def top_joins(self, db_tables=None, page_size=100, startingToken=None, connector=None):
  99. results = {'results': []}
  100. return results
  101. def top_databases(self, page_size=100, startingToken=None):
  102. results = {'results': []}
  103. return results