فهرست منبع

HUE-5683 [editor] Show details for popular aggregate functions in the autocomplete dropdown

Johan Ahlen 8 سال پیش
والد
کامیت
eb81662709

+ 13 - 4
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js

@@ -1156,7 +1156,7 @@ var SqlAutocompleter3 = (function () {
                 })
               } else if (table.identifierChain.length === 1) {
                 substitutions.push({
-                  replace: new RegExp(database + '\.' + table.identifierChain[0].name + '\.', 'gi'),
+                  replace: new RegExp(self.activeDatabase + '\.' + table.identifierChain[0].name + '\.', 'gi'),
                   with: replaceWith
                 });
                 substitutions.push({
@@ -1166,22 +1166,31 @@ var SqlAutocompleter3 = (function () {
               }
             });
 
+            var totalCount = 0;
             data.values.forEach(function (value) {
               var clean = value.aggregateClause;
               substitutions.forEach(function (substitution) {
                 clean = clean.replace(substitution.replace, substitution.with);
               });
+              totalCount += value.totalQueryCount;
+              value.function = SqlFunctions.findFunction(self.snippet.type(), value.aggregateFunction);
               aggregateFunctionsSuggestions.push({
                 value: clean,
-                meta: AutocompleterGlobals.i18n.meta.aggregateFunction,
+                meta: value.function.returnTypes.join('|'),
                 category: CATEGORIES.POPULAR_AGGREGATE,
                 popular: true,
                 weightAdjust: Math.min(value.totalQueryCount, 99),
                 details: value
               });
-            })
+            });
+
+            aggregateFunctionsSuggestions.forEach(function (suggestion) {
+              suggestion.details.relativePopularity = totalCount === 0 ? suggestion.details.totalQueryCount : Math.round(100 * suggestion.details.totalQueryCount / totalCount);
+              suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
+            });
+
+            self.entries(self.entries().concat(aggregateFunctionsSuggestions));
           }
-          self.entries(self.entries().concat(aggregateFunctionsSuggestions));
           aggregateFunctionsDeferred.resolve();
           self.loadingAggregateFunctions(false);
         },

+ 10 - 1
desktop/libs/notebook/src/notebook/templates/hue_ace_autocompleter.mako

@@ -336,7 +336,16 @@ from desktop.views import _ko
 
   <script type="text/html" id="autocomplete-details-agg-udf">
     <div class="autocompleter-details">
-      <pre data-bind="text: ko.mapping.toJSON(details)"></pre>
+      <div class="autocompleter-header"><i class="fa fa-fw fa-superscript"></i> ${ _('Popular aggregate')} - <span data-bind="text: details.aggregateFunction"></span></div>
+      <div class="autocompleter-details-contents">
+        <div class="details-code" data-bind="text: value"></div>
+        <div class="details-popularity margin-top-10" data-bind="tooltip: { title: '${ _ko('Popularity') } ' + details.relativePopularity + '%', placement: 'bottom' }"><i class="fa fa-fw fa-star-o popular-icon"></i>
+          <div class="progress">
+            <div class="bar" data-bind="style: { 'width': details.relativePopularity + '%' }"></div>
+          </div>
+        </div>
+        <div class="details-comment" data-bind="text: details.function.description"></div>
+      </div>
     </div>
   </script>