Browse Source

HUE-3228 [dashboard] Better handling of number range facet

Romain Rigaux 8 years ago
parent
commit
96558032d7

+ 22 - 11
apps/impala/src/impala/dashboard_api.py

@@ -410,8 +410,7 @@ class SQLApi():
     # facet salary --> salary_range
     # facets --> Count DESC   |   salary_range ASC
     if facet['properties']['canRange']:
-      field_name = '`%(field)s_range`' % facet
-      field_name_to = '`%(field)s_range_to`' % facet
+      field_name = '%(field)s_range' % facet
       order_by = '`%(field)s_range` ASC' % facet
       if facet['properties']['isDate']:
         if facet['properties']['isBigIntDate']:
@@ -419,30 +418,40 @@ class SQLApi():
         else:
           field = '`%(field)s`' % facet
 
-        gap = facet['properties']['gap'] if 'gap' in facet['properties'] else facet['properties']['initial_gap']
+        gap = facet['properties']['gap']# if 'gap' in facet['properties'] else facet['properties']['initial_gap']
 
         slot = slot_interval = re.sub('^\+\d+', '', gap).rstrip('S')
         if slot == 'MINUTE':
           slot = 'MI'
           slot_interval = 'MINUTE'
+        # ...
 
-        select = "trunc(%(field)s, '%(slot)s') AS %(field_name)s, trunc(%(field)s, '%(slot)s') + interval 1 %(slot_interval)s AS %(field_name_to)s" % {
+        select = """
+          trunc(%(field)s, '%(slot)s') AS `%(field_name)s`,
+          trunc(%(field)s, '%(slot)s') + interval 1 %(slot_interval)s AS `%(field_name)s_to`""" % {
             'field': field,
             'slot': slot,
             'slot_interval': slot_interval,
             'field_name': field_name,
-            'field_name_to': field_name_to
+            'start': facet['properties']['start'],
+            'end': facet['properties']['end'],
         }
       else:
-        slot = max((facet['properties']['end'] - facet['properties']['start']) / facet['properties']['limit'], 1)
-        select = 'cast(`%(field)s` / %(slot)s AS int) * %(slot)s AS %(field_name)s' % {'field': facet['field'], 'slot': slot, 'field_name': field_name}
+        slot = gap
+        select = """
+        floor(floor((`%(field)s` - %(start)s) / %(slot)s) * %(slot)s) + %(start)s AS `%(field_name)s`""" % { # Beware: start might be not in sync with the UI
+          'field': facet['field'],
+          'slot': slot,
+          'field_name': field_name,
+          'start': facet['properties']['start']
+        }
     else:
-      field_name = '`%(field)s`' % facet
+      field_name = '%(field)s' % facet
       select = field_name
       order_by = 'Count DESC'
 
     return {
-      'name': field_name,
+      'name': '`%s`' % field_name,
       'select': select,
       'order_by': order_by
     }
@@ -542,6 +551,9 @@ class SQLApi():
 
     if facet['properties']['canRange']:
       if facet['properties']['isDate']:
+        
+        # Add min, max, slot into query?
+        
         props = {}#self._get_time_filter_range(collection, query)
         if props['unit'] == 'SECOND':
           dt = timedelta(seconds=1)
@@ -556,8 +568,7 @@ class SQLApi():
         #rows = augment_date_range_list(rows, facet['properties']['start'], facet['properties']['end'], timedelta(seconds=60), len(cols))
         pass
       else:
-        pass
-        #rows = augment_number_range_list(rows, facet['properties']['start'], facet['properties']['end'], facet['properties']['gap'], len(cols))
+        rows = augment_number_range_list(rows, facet['properties']['start'], facet['properties']['end'], facet['properties']['gap'], len(cols))
 
     response['fieldsAttributes'] = [{
          "sort":{

+ 0 - 1
apps/impala/src/impala/templates/dashboard.mako

@@ -366,7 +366,6 @@ ${ dashboard.layout_skeleton() }
       onStateChange: function(state){ $root.collection.getFacetById(id()).properties.stacked(state.stacked); },
       onClick: function(d){ viewModel.query.selectRangeFacet({count: d.obj.value, widget_id: $parent.id(), from: d.obj.from, to: d.obj.to, cat: d.obj.field}) },
       onComplete: function(){ viewModel.getWidgetById(id()).isLoading(false) }}" />
-
     </div>
   <!-- /ko -->
 

+ 1 - 0
apps/search/src/search/facet_builder.py

@@ -42,6 +42,7 @@ def _guess_range_facet(widget_type, solr_api, collection, facet_field, propertie
 
     _compute_range_facet(widget_type, stat_facet, properties, start, end, gap)
   except Exception, e:
+    print e
     LOG.info('Stats not supported on all the fields, like text: %s' % e)
 
 

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

@@ -496,9 +496,9 @@ var Collection = function (vm, collection) {
     vm.search();
   });
   self.timeFilter.type.subscribe(function (val) {
-	if (val == 'fixed'){
+    if (val == 'fixed'){
       self.autorefresh(false);
-	}
+    }
 	if (val == 'fixed' && self.timeFilter.from().length == 0) {
       $.ajax({
         type: "POST",