소스 검색

HUE-3228 [dashboard] On/off flag to allow SQL in dashboards

Romain Rigaux 8 년 전
부모
커밋
e0ce7a9742

+ 7 - 0
apps/search/src/search/conf.py

@@ -41,3 +41,10 @@ LATEST = Config(
   help=_("Use latest Solr 5.2+ features."),
   default=False,
   type=coerce_bool)
+
+ENABLE_SQL = Config(
+  key="enable_sql",
+  help=_("Offer to use SQL engines to compute the dashboards."),
+  default=False,
+  private=True,
+  type=coerce_bool)

+ 13 - 9
apps/search/src/search/models.py

@@ -34,7 +34,7 @@ from desktop.models import get_data_link
 from libsolr.api import SolrApi
 from notebook.conf import get_ordered_interpreters
 
-from search.conf import SOLR_URL, LATEST
+from search.conf import SOLR_URL, LATEST, ENABLE_SQL
 
 
 LOG = logging.getLogger(__name__)
@@ -885,7 +885,7 @@ def augment_solr_response(response, collection, query):
             counts = []
         elif collection_facet['properties'].get('isOldPivot'):
           facet_fields = [collection_facet['field']] + [f['field'] for f in collection_facet['properties'].get('facets', []) if f['aggregate']['function'] == 'count']
- 
+
           column = 'count'
           agg_keys = [key for key, value in counts[0].items() if key.lower().startswith('agg_') or key.lower().startswith('dim_')]
           agg_keys.sort(key=lambda a: a[4:])
@@ -1142,13 +1142,17 @@ def _convert_nested_to_augmented_pivot_nd(facet_fields, facet_id, counts, select
 
 
 def get_engines(user):
-  return [
-      {'name': _('index (Solr)'), 'type': 'solr'}] + [{
-        'name': _('table (%s)') % interpreter['name'],
-        'type': interpreter['type']
-      }
-      for interpreter in get_ordered_interpreters(user) if interpreter['interface'] == 'hiveserver2'
-  ]
+  engines = [{'name': _('index (Solr)'), 'type': 'solr'}]
+
+  if ENABLE_SQL.get():
+    engines += [{
+          'name': _('table (%s)') % interpreter['name'],
+          'type': interpreter['type']
+        }
+        for interpreter in get_ordered_interpreters(user) if interpreter['interface'] == 'hiveserver2'
+    ]
+
+  return engines
 
 
 def augment_solr_exception(response, collection):

+ 17 - 17
apps/search/src/search/static/search/js/search.ko.js

@@ -602,7 +602,7 @@ var Collection = function (vm, collection) {
   };
 
   self.widgetType = ko.computed(function() {
-     return self.template.isGridLayout() ? 'resultset-widget' : 'html-resultset-widget'; 
+     return self.template.isGridLayout() ? 'resultset-widget' : 'html-resultset-widget';
   });
 
   if (collection.facets.length > 0) {
@@ -669,7 +669,7 @@ var Collection = function (vm, collection) {
         vm.getFacetFromQuery(facet.id()).resultHash('');
         vm.search();
       });
-      
+
       facet.template.chartSettings.chartType.subscribe(function(newValue) {
         facet.widgetType(
             newValue == ko.HUE_CHARTS.TYPES.PIECHART ? 'pie2-widget' :
@@ -1365,7 +1365,7 @@ var NewTemplate = function (vm, initial) {
       // If new dashboard
       vm.collection.name.subscribe(function(newValue) {
         if (newValue) {
-          vm.collection.label(newValue);        
+          vm.collection.label(newValue);
           vm.collection.switchCollection();
           vm.search();
         }
@@ -1646,11 +1646,11 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
             $.each(data.normalized_facets, function (index, new_facet) {
               self._make_result_facet(new_facet);
             });
-        	return data;
+          return data;
         });
-      });  
+      });
     }
-    
+
     $.each(self.fieldAnalyses(), function (index, analyse) { // Invalidate stats analysis
       analyse.stats.data.removeAll();
     });
@@ -1707,16 +1707,16 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
       .done(function () {
         if (arguments[0] instanceof Array) {
           if (self.collection.engine() != 'impala') { // If multi queries
-	          var histograms = self.collection.getHistogramFacets();
-	          for (var h = 0; h < histograms.length; h++) { // Do not use $.each here
-	            var histoFacetId = histograms[h].id();
-	            var histoFacet = self.getFacetFromQuery(histoFacetId);
-	            var _series = [];
-	            for (var i = 1; i < arguments.length; i++) {
-	              _series.push(arguments[i][0]['series']);
-	            }
-	            histoFacet.extraSeries(_series);
-	          }
+            var histograms = self.collection.getHistogramFacets();
+            for (var h = 0; h < histograms.length; h++) { // Do not use $.each here
+              var histoFacetId = histograms[h].id();
+              var histoFacet = self.getFacetFromQuery(histoFacetId);
+              var _series = [];
+              for (var i = 1; i < arguments.length; i++) {
+                _series.push(arguments[i][0]['series']);
+              }
+              histoFacet.extraSeries(_series);
+            }
           }
           self.response.valueHasMutated();
         }
@@ -1763,7 +1763,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
         facet.has_data(true);
       }
   }
-  
+
   self._make_result_doc = function(item, _mustacheTmpl, template) {
       var row = [];
       var leafletmap = {};

+ 10 - 5
apps/search/src/search/templates/common_search.mako

@@ -84,10 +84,15 @@ from desktop.views import commonheader, commonfooter, _ko
 
   <form data-bind="visible: $root.isEditing() && columns().length == 0">
     ${ _('Select one') }
-    <select class="input-medium" data-bind="options: $root.initial.engines, value: $root.collection.engine, optionsText: 'name',  optionsValue: 'type', disable: isSyncingCollections"></select>
+    <!-- ko if: $root.initial.engines().length > 1 -->
+      <select class="input-medium" data-bind="options: $root.initial.engines, value: $root.collection.engine, optionsText: 'name',  optionsValue: 'type', disable: isSyncingCollections"></select>
+    <!-- /ko -->
+    <!-- ko ifnot: $root.initial.engines().length > 1 -->
+      ${_('index')}
+    <!-- /ko -->
 
     <!-- ko if: $root.collection.engine() == 'solr' -->
-      <!-- ko if: columns().length == 0 -->      
+      <!-- ko if: columns().length == 0 -->
       <select data-bind="options: $root.initial.collections, value: $root.collection.name, disable: isSyncingCollections"></select>
 
         <label class="checkbox" style="display:inline-block; margin-left: 10px">
@@ -99,12 +104,12 @@ from desktop.views import commonheader, commonfooter, _ko
       <select data-bind="options: $root.availableDateFields, value: collection.timeFilter.field, optionsValue: 'name', visible: $root.isEditing() && $root.availableDateFields().length > 0" class="input-medium" style="margin-left: 4px"></select>
       <span class="time-filter" data-bind="template: {name: 'time-filter'}, visible: collection.timeFilter.type() == 'rolling'"></span>
       <span class="time-fixed-filter" data-bind="template: {name: 'time-fixed-filter'}, visible: collection.timeFilter.type() == 'fixed'"></span>
-  
+
       <span data-bind="template: {name: 'nested-document-filter'}"></span>
     <!-- /ko -->
-    
+
     <!-- ko if: $root.collection.engine() != 'solr' -->
-      <!-- ko if: columns().length == 0 -->      
+      <!-- ko if: columns().length == 0 -->
         <input type="text" class="no-margin" data-bind="value: $root.collection.name, hivechooser: $root.collection.name, skipColumns: true" placeholder="${ _('Table name or <database>.<table>') }">
       <!-- /ko -->
     <!-- /ko -->