Browse Source

HUE-1479 [hbase] Column range scan in search bar

Kevin Wang 12 years ago
parent
commit
480d66afcd

+ 3 - 2
apps/hbase/src/hbase/templates/app.mako

@@ -196,7 +196,7 @@ ${ commonheader(None, "hbase", user) | n,unicode }
           </div>
           </div>
           <ul id="search-typeahead" data-bind="visible: search.focused() && !search.submitted()">
           <ul id="search-typeahead" data-bind="visible: search.focused() && !search.submitted()">
             <!-- ko if: search.mode() != 'idle' -->
             <!-- ko if: search.mode() != 'idle' -->
-            <li><a><b data-bind="text: search.modes[search.mode()].hint"></b>: <span data-bind="html: search.hintText()"></span> <code class="pull-right" data-bind="text: search.modes[search.mode()].type"></code></a></li>
+            <li><a><b data-bind="text: search.modes[search.mode()].hint"></b> <code class="pull-right" data-bind="text: search.modes[search.mode()].type"></code></a></li>
             <!-- /ko -->
             <!-- /ko -->
             <!-- ko foreach: search.activeHints() -->
             <!-- ko foreach: search.activeHints() -->
             <li data-bind="event: { mousedown: function(){app.search.cur_input(app.search.cur_input() + $data.shortcut);} }, css: {active: self.activeHint}"><a><span data-bind="text: $data.hint"></span> <code class="pull-right" data-bind="text: $data.shortcut"></code></a></li>
             <li data-bind="event: { mousedown: function(){app.search.cur_input(app.search.cur_input() + $data.shortcut);} }, css: {active: self.activeHint}"><a><span data-bind="text: $data.hint"></span> <code class="pull-right" data-bind="text: $data.shortcut"></code></a></li>
@@ -396,7 +396,8 @@ var i18n_cache = {
   'Column Family: Column Name': "${_('Column Family: Column Name')}",
   'Column Family: Column Name': "${_('Column Family: Column Name')}",
   'Rows starting with': "${_('Rows starting with')}",
   'Rows starting with': "${_('Rows starting with')}",
   'String': "${_('String')}",
   'String': "${_('String')}",
-  'Integer': "${_('Integer')}"
+  'Integer': "${_('Integer')}",
+  'Column Range': "${_('Column Range')}"
 };
 };
 
 
 function i18n(text) {
 function i18n(text) {

+ 1 - 1
apps/hbase/static/css/hbase.css

@@ -378,7 +378,7 @@ ul#hbase-breadcrumbs li a {
 	border-radius: 3px;
 	border-radius: 3px;
 }
 }
 
 
-#search-tags span.prefix {
+#search-tags span.prefix, #search-tags span.range {
 	color: #fff;
 	color: #fff;
 	background: #5EB568;
 	background: #5EB568;
 }
 }

+ 44 - 19
apps/hbase/static/js/controls.js

@@ -19,8 +19,17 @@ var searchRenderers = {
      select: /[^\,\{\[]+(([\{\[][^\}\]]+[\}\]])+|)([^\,]+|)/g, //select the substring to process, useful as JS has no lookbehinds old: ([^,]+\[([^,]+(,|)+)+\]|[^,]+)
      select: /[^\,\{\[]+(([\{\[][^\}\]]+[\}\]])+|)([^\,]+|)/g, //select the substring to process, useful as JS has no lookbehinds old: ([^,]+\[([^,]+(,|)+)+\]|[^,]+)
      tag: /.+/g, //select the matches to wrap with tags
      tag: /.+/g, //select the matches to wrap with tags
      nested: {
      nested: {
-        'scan': { select: /(([^\\]|\b)\+[0-9]+)/g, tag: /\+[0-9]+/g},
-        'columns': { select: /\[.+\]/g, tag: /[^:,\[\]]+:([^,\[\]]+|)/g}, //forced to do this select due to lack of lookbehinds /[\[\]]/g
+        'scan': { select: /(([^\\]|\b)\+[0-9]+)/g, tag: /\+[0-9]+/g },
+        'columns': {
+          select: /\[.+\]/g,
+          tag: /[^,\[\]]+/g, //forced to do this select due to lack of lookbehinds /[\[\]]/g
+          nested: {
+            'range': {
+              select: /\sto\s/g,
+              tag: /.+/g
+            }
+          }
+        },
         'prefix': { select: /[^\*\\]+\*/g, tag: /\*/g},
         'prefix': { select: /[^\*\\]+\*/g, tag: /\*/g},
         'filter': {
         'filter': {
           select: /\{[^\{\}]+\}/,
           select: /\{[^\{\}]+\}/,
@@ -177,6 +186,14 @@ var SmartViewModel = function(options) {
     if(inputs) {
     if(inputs) {
       for(var i=0; i<inputs.length; i++) {
       for(var i=0; i<inputs.length; i++) {
         if(inputs[i].trim() != "" && inputs[i].trim() != ',') {
         if(inputs[i].trim() != "" && inputs[i].trim() != ',') {
+          //pull out filters
+          var filter = inputs[i].match(searchRenderers['rowkey']['nested']['filter']['select']) || "";
+          filter = filter != null && filter.length > 0 ? escape(filter[0].trim().slice(1, -1)) : "";
+
+          function filterPostfix(postfix) {
+            return (filter != null && filter.length > 0 ? ' AND ' : ' ' ) + postfix;
+          }
+
           //pull out columns
           //pull out columns
           var extract = inputs[i].match(searchRenderers['rowkey']['nested']['columns']['select']);
           var extract = inputs[i].match(searchRenderers['rowkey']['nested']['columns']['select']);
           var columns = extract != null ? extract[0].match(searchRenderers['rowkey']['nested']['columns']['tag']) : [];
           var columns = extract != null ? extract[0].match(searchRenderers['rowkey']['nested']['columns']['tag']) : [];
@@ -188,29 +205,32 @@ var SmartViewModel = function(options) {
           p = p.split('+');
           p = p.split('+');
           var scan = p.length > 1 ? parseInt(p[1].trim()) : 0;
           var scan = p.length > 1 ? parseInt(p[1].trim()) : 0;
 
 
-          //pull out filters
-          var filter = inputs[i].match(searchRenderers['rowkey']['nested']['filter']['select']) || "";
-          filter = filter != null && filter.length > 0 ? escape(filter[0].trim().slice(1, -1)) : "";
-
           //pull out column filters
           //pull out column filters
-          function filterPostfix(postfix) {
-            return (filter != null && filter.length > 0 ? ' AND ' : ' ' ) + postfix;
-          }
-
+          var toRemove = [];
           var cfs = [];
           var cfs = [];
           $(columns).each(function(i, o) {
           $(columns).each(function(i, o) {
-            var colscan = pullFromRenderer(o, searchRenderers['rowkey']['nested']['scan']);
-            if(colscan) {
-              colscan = parseInt(colscan.split('+')[1]) + 1;
-              filter += filterPostfix("ColumnPaginationFilter(" + colscan + ", 0)");
-            }
-            var fc = o.replace(pullFromRenderer(o, searchRenderers['rowkey']['nested']['prefix']), '');
-            if(fc != o) {
-              filter += filterPostfix("ColumnPrefixFilter('" + fc.slice(fc.indexOf(':') + 1).match(/[0-9]+/g)[0] + "')");
-              columns[i] = fc.slice(0, fc.indexOf(':'));
+            if(columns[i].match(searchRenderers['rowkey']['nested']['columns']['nested']['range']['select'])) {
+              var partitions = columns[i].split(searchRenderers['rowkey']['nested']['columns']['nested']['range']['select']);
+              filter += filterPostfix("ColumnRangeFilter('" + partitions[0] + "', false, '" + partitions[1] + "', true)");
+              toRemove.push(i);
+            } else {
+              var colscan = pullFromRenderer(o, searchRenderers['rowkey']['nested']['scan']);
+              if(colscan) {
+                colscan = parseInt(colscan.split('+')[1]) + 1;
+                filter += filterPostfix("ColumnPaginationFilter(" + colscan + ", 0)");
+              }
+              var fc = o.replace(pullFromRenderer(o, searchRenderers['rowkey']['nested']['prefix']), '');
+              if(fc != o) {
+                filter += filterPostfix("ColumnPrefixFilter('" + fc.slice(fc.indexOf(':') + 1).match(/[0-9]+/g)[0] + "')");
+                columns[i] = fc.slice(0, fc.indexOf(':'));
+              }
             }
             }
           });
           });
 
 
+          $(toRemove).each(function(i) {
+            columns.splice(toRemove[i], 1);
+          });
+
           self.querySet.push(new QuerySetPiece({
           self.querySet.push(new QuerySetPiece({
             'row_key': inputs[i].replace(/\\(\+|\*|\,)/g, '$1').replace(/[\[\{].+[\]\}]|\*/g,'').trim(), //clean up with column regex selectors instead
             'row_key': inputs[i].replace(/\\(\+|\*|\,)/g, '$1').replace(/[\[\{].+[\]\}]|\*/g,'').trim(), //clean up with column regex selectors instead
             'scan_length': scan ? scan + 1 : 1,
             'scan_length': scan ? scan + 1 : 1,
@@ -655,6 +675,11 @@ var tagsearch = function() {
       shortcut: ']',
       shortcut: ']',
       mode: ['columns'],
       mode: ['columns'],
       selected: false
       selected: false
+    }, {
+      hint: i18n('Column Range'),
+      shortcut: ' to ',
+      mode: ['columns'],
+      selected: false
     },
     },
     {
     {
       hint: i18n('Start FilterString'),
       hint: i18n('Start FilterString'),