瀏覽代碼

[phoenix] Add sql sample tables and queries

Romain Rigaux 5 年之前
父節點
當前提交
2bfd5f368e

+ 1 - 1
apps/about/src/about/templates/admin_wizard.mako

@@ -109,7 +109,7 @@ ${ layout.menubar(section='quick_start') }
 
               % if has_connectors():
                 <!-- ko foreach: connectors -->
-                  <!-- ko if: ['hive', 'impala', 'mysql', 'postgresql', 'presto'].indexOf(dialect) != -1 -->
+                  <!-- ko if: ['hive', 'impala', 'mysql', 'postgresql', 'presto', 'phoenix'].indexOf(dialect) != -1 -->
                   <li>
                     <a href="javascript:void(0)" data-bind="click: $root.installConnectorDataExample">
                       <i class="fa fa-download"></i> <span data-bind="text: name"></span>

+ 1 - 3
apps/about/src/about/views.py

@@ -16,7 +16,6 @@
 # limitations under the License.
 
 from builtins import str
-import json
 import logging
 
 from django.utils.translation import ugettext as _
@@ -24,8 +23,7 @@ from django.utils.translation import ugettext as _
 from desktop import appmanager
 from desktop.auth.backend import is_hue_admin
 from desktop.auth.decorators import admin_required
-from desktop.lib.django_util import JsonResponse, render, login_notrequired
-from desktop.log.access import access_log_level
+from desktop.lib.django_util import JsonResponse, render
 from desktop.models import Settings, hue_version
 from desktop.views import collect_usage
 

+ 20 - 0
apps/beeswax/data/queries.json

@@ -221,5 +221,25 @@
       "file_resources": [],
       "settings": []
     }
+  },
+  {
+    "name": "US City Population",
+    "desc": "Small samples of number of inhabitants in some US cities",
+    "dialects": ["phoenix"],
+    "type": "2",
+    "auto_load_only": false,
+    "data": {
+      "query": {
+        "query": "\nSELECT\n  state as \"State\",\n  count(city) as \"City Count\",\n  sum(population) as \"Population Sum\"\nFROM\n  us_population\nGROUP BY\n  state\nORDER BY\n  sum(population) DESC\n;",
+        "type": 0,
+        "email_notify": false,
+        "is_parameterized": false,
+        "database": ""
+      },
+      "functions": [],
+      "VERSION": "0.4.1",
+      "file_resources": [],
+      "settings": []
+    }
   }
 ]

+ 10 - 0
apps/beeswax/data/tables_standard.json

@@ -7,4 +7,14 @@
     "dialects": ["mysql", "postgresql", "presto"],
     "transactional": true
   }
+  ,
+  {
+    "data_file": "./tables/us_population.csv",
+    "create_sql": "CREATE TABLE IF NOT EXISTS us_population (\n  state CHAR(2) NOT NULL,\n  city VARCHAR NOT NULL,\n  population BIGINT\n  CONSTRAINT my_pk PRIMARY KEY (state, city)\n)\n",
+    "insert_sql": "UPSERT INTO us_population VALUES %(values)s",
+    "table_name": "us_population",
+    "dialects": ["phoenix"],
+    "transactional": true,
+    "is_multi_inserts": true
+  }
 ]

+ 8 - 3
apps/beeswax/src/beeswax/management/commands/beeswax_install_examples.py

@@ -68,7 +68,8 @@ class Command(BaseCommand):
       self.tables = options.get('tables')
 
     tables = 'tables_standard.json' if dialect not in ('hive', 'impala') else (
-        'tables_transactional.json' if has_concurrency_support() else 'tables.json'
+        'tables_transactional.json' if has_concurrency_support() else
+        'tables.json'
     )
     exception = None
 
@@ -128,6 +129,7 @@ class Command(BaseCommand):
     # Filter query list to HiveServer2 vs other interfaces
     app_type = HQL if dialect == 'hive' else IMPALA if dialect == 'impala' else RDBMS
     design_list = [d for d in design_list if int(d['type']) == app_type]
+
     if app_type == RDBMS:
       design_list = [d for d in design_list if dialect in d['dialects']]
     if self.queries is None:  # Manual install
@@ -168,6 +170,7 @@ class SampleTable(object):
     self.request = request
     self.columns = data_dict.get('columns')
     self.is_transactional = data_dict.get('transactional')
+    self.is_multi_inserts = data_dict.get('is_multi_inserts')
 
     # Sanity check
     self._data_dir = LOCAL_EXAMPLES_DATA_DIR.get()
@@ -357,8 +360,10 @@ class SampleTable(object):
 
     rows = [
       ', '.join(
-        col if is_number(col, i, columns) else "'%s'" % col.replace("'", "\\'") for i, col in enumerate(row)
-      ) for row in reader
+        col if is_number(col, i, columns) else "'%s'" % col.replace("'", "\\'")
+        for i, col in enumerate(row)
+      )
+      for row in reader
     ]
 
     return ', '.join('(%s)' % row for row in rows)

+ 1 - 1
desktop/core/src/desktop/lib/connectors/types.py

@@ -290,7 +290,7 @@ CONNECTOR_TYPES = [
     'dialect': 'phoenix',
     'interface': 'sqlalchemy',
     'settings': [
-      {'name': 'url', 'value': 'phoenix://sql-phoenix.com:8765/'},
+      {'name': 'url', 'value': 'phoenix://localhost:8765/'},
       {'name': 'has_ssh', 'value': False},
       {'name': 'ssh_server_host', 'value': '127.0.0.1'},
     ],