Browse Source

HUE-8408 [report] Dynamic statement retrieval

jdesjean 7 years ago
parent
commit
4c0d53d

+ 1 - 1
desktop/core/src/desktop/templates/common_notebook_ko_components.mako

@@ -374,7 +374,7 @@ except ImportError, e:
         self.checkDownloadInterval = -1;
 
         if (!self.snippet.downloadResultViewModel) {
-          self.snippet.downloadResultViewModel = ko.observable(self);
+          self.snippet.downloadResultViewModel = ko.observable({});
         }
 
         self.saveResultsModalId = '#saveResultsModal' + self.snippet.id();

+ 1 - 3
desktop/libs/dashboard/src/dashboard/api.py

@@ -430,12 +430,10 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       snippets = doc.data_dict.get('snippets', [])
       properties['result'] = {'handle': {'statement_id': 0, 'statements_count': 1, 'previous_statement_hash': hashlib.sha224(str(uuid.uuid4())).hexdigest()}}
       if snippets:
-        table_metadata = get_api(MockRequest(user, '""'), snippets[0]).autocomplete({'source': 'query', 'type': snippets[0]['type']}, doc.id)
-        template['fieldsAttributes'] = [Collection2._make_gridlayout_header_field(field) for field in table_metadata['extended_columns']]
         properties['engine'] = snippets[0]['type']
     else:
       properties['statementUuid'] = ''
-
+    properties['statement'] = ''
     properties['uuid'] = facet_field
     properties['facets'] = [{'canRange': False, 'field': 'blank', 'limit': 10, 'mincount': 0, 'sort': 'desc', 'aggregate': {'function': 'count'}, 'isDate': False, 'type': 'field'}]
     facet_type = 'statement'

+ 9 - 18
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -1746,37 +1746,28 @@ ${ dashboard.layout_skeleton(suffix='search') }
         <!-- ko if: widgetType() == 'document-widget' -->
           <!-- ko if: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.PIECHART -->
           <div data-bind="attr:{'id': 'pieChart_'+id()}, pieChart: {data: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, widget_id: $parent.id(), chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYSingle}, field: template.chartSettings.chartX, fqs: $root.query.fqs,
-                transformer: pieChartDataTransformerGrid, maxWidth: 350, parentSelector: '.chart-container',
-                onClick: function(d){ searchViewModel.query.toggleFacet({facet: {cat: template.chartSettings.chartX(), value: d.data.label}, widget_id: $parent.id()}); }}" class="chart"></div>
+                transformer: pieChartDataTransformerGrid, maxWidth: 350, parentSelector: '.chart-container'}" class="chart"></div>
           <!-- /ko -->
           <!-- ko if: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.BARCHART -->
-          <div data-bind="attr:{'id': 'barChart_'+id()}, barChart: {datum: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, widget_id: $parent.id(), chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYMulti}, field: template.chartSettings.chartX, fqs: $root.query.fqs, hideSelection: true, enableSelection: true, hideStacked: template.chartSettings.hideStacked,
-                transformer: multiSerieDataTransformerGrid, stacked: false, showLegend: true, type: template.chartSettings.chartSelectorType,
-                onClick: function(d){ searchViewModel.query.toggleFacet({facet: {cat: template.chartSettings.chartX(), value: d.x}, widget_id: $parent.id()}); },
-                onSelectRange: function(from, to){ $root.collection.selectTimelineFacet2({from: from, to: to, cat: template.chartSettings.chartX(), widget_id: $parent.id()}) }},  stacked: true, showLegend: true" class="chart"></div>
+          <div data-bind="attr:{'id': 'barChart_'+id()}, barChart: {datum: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, widget_id: $parent.id(), chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYMulti}, field: template.chartSettings.chartX, fqs: $root.query.fqs, hideSelection: true, enableSelection: false, hideStacked: template.chartSettings.hideStacked,
+                transformer: multiSerieDataTransformerGrid, stacked: false, showLegend: true, type: template.chartSettings.chartSelectorType},  stacked: true, showLegend: true" class="chart"></div>
           <!-- /ko -->
           <!-- ko if: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.LINECHART -->
-          <div data-bind="attr:{'id': 'lineChart_'+id()}, lineChart: {datum: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, widget_id: $parent.id(), chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYMulti}, field: template.chartSettings.chartX, fqs: $root.query.fqs, hideSelection: true, enableSelection: true,
-                transformer: multiSerieDataTransformerGrid, showControls: false,
-                onClick: function(d){ searchViewModel.query.toggleFacet({facet: {cat: template.chartSettings.chartX(), value: d.x}, widget_id: $parent.id()}); },
-                onSelectRange: function(from, to){ $root.collection.selectTimelineFacet2({from: from, to: to, cat: template.chartSettings.chartX(), widget_id: $parent.id()}) }}" class="chart"></div>
+          <div data-bind="attr:{'id': 'lineChart_'+id()}, lineChart: {datum: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, widget_id: $parent.id(), chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYMulti}, field: template.chartSettings.chartX, fqs: $root.query.fqs, hideSelection: true, enableSelection: false,
+                transformer: multiSerieDataTransformerGrid, showControls: false}" class="chart"></div>
           <!-- /ko -->
           <!-- ko if: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.MAP -->
           <div data-bind="attr: {'id': 'leafletMapChart_'+id()}, leafletMapChart: {datum: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYSingle, chartZ: template.chartSettings.chartMapLabel},
                 transformer: leafletMapChartDataTransformerGrid, showControls: false, height: 380, forceRedraw: true,
-                showMoveCheckbox: true, moveCheckboxLabel: '${ _ko('Search as I move the map') }',
-                onRegionChange: function(bounds){ $root.query.selectMapRegionFacet({widget_id: $parent.id(), 'bounds': ko.toJS(bounds, null, 2), lat: template.chartSettings.chartX(), lon: template.chartSettings.chartYSingle()}); }}" class="chart"></div>
+                showMoveCheckbox: false, moveCheckboxLabel: '${ _ko('Search as I move the map') }'}" class="chart"></div>
           <!-- /ko -->
           <!-- ko if: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.TIMELINECHART -->
-          <div data-bind="attr:{'id': 'timelineChart_'+id()}, timelineChart: {datum: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYMulti, widget_id: $parent.id()}, field: template.chartSettings.chartX, fqs: $root.query.fqs, hideSelection: true, enableSelection: true, hideStacked: template.chartSettings.hideStacked,
-                transformer: multiSerieDataTransformerGrid, showControls: false,
-                onClick: function(d){ searchViewModel.query.toggleFacet({facet: {cat: template.chartSettings.chartX(), value: d.x}, widget_id: $parent.id()}); },
-                onSelectRange: function(from, to){ $root.collection.selectTimelineFacet2({from: from, to: to, cat: template.chartSettings.chartX(), widget_id: $parent.id()}) }}" class="chart"></div>
+          <div data-bind="attr:{'id': 'timelineChart_'+id()}, timelineChart: {datum: {counts: $parent.results(), sorting: template.chartSettings.chartSorting(), snippet: $data, chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYMulti, widget_id: $parent.id()}, field: template.chartSettings.chartX, fqs: $root.query.fqs, hideSelection: true, enableSelection: false, hideStacked: template.chartSettings.hideStacked,
+                transformer: multiSerieDataTransformerGrid, showControls: false}" class="chart"></div>
           <!-- /ko -->
           <!-- ko if: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.GRADIENTMAP -->
           <div data-bind="attr:{'id': 'gradientMapChart_'+id()}, mapChart: {data: {counts: $parent.results(), scope: template.chartSettings.chartScope(), snippet: $data, widget_id: $parent.id(), chartX: template.chartSettings.chartX, chartY: template.chartSettings.chartYSingle},
-              transformer: gradientMapChartDataTransformerGrid, maxWidth: 750, isScale: true,
-              onClick: function(d){ searchViewModel.query.toggleFacet({facet: {cat: template.chartSettings.chartX(), value: d.fields[0]}, widget_id: $parent.id()}); }}" />
+              transformer: gradientMapChartDataTransformerGrid, maxWidth: 750, isScale: true}" />
           <!-- /ko -->
           <div class="clearfix"></div>
         <!-- /ko -->

+ 2 - 13
desktop/libs/notebook/src/notebook/dashboard_api.py

@@ -152,20 +152,9 @@ class SQLDashboardApi(DashboardApi):
             'filters': self._convert_filters_to_where(filters),
         }
       elif facet['type'] == 'statement':
-        doc = Document2.objects.get_by_uuid(user=self.user, uuid=facet['statementUuid'], perm_type='read')
+        doc = Document2.objects.get_by_uuid(user=self.user, uuid=facet['properties']['statementUuid'], perm_type='read')
         snippets = doc.data_dict.get('snippets', [])
-        statement = snippets[0]['statement_raw']
-
-        if filters:
-          sql = '''SELECT *
-          FROM
-          (%(statement)s) as sub
-          %(filters)s''' % {
-            'statement': statement,
-            'filters': self._convert_filters_to_where(filters, alias='sub')
-          }
-        else:
-          sql = statement
+        sql = snippets[0].get('statement', '')
         result_properties = facet['properties']['result']
     else:
       fields = Collection2.get_field_list(dashboard)