Browse Source

HUE-5125 [editor] Skeleton for HDFS details in context popover

Johan Ahlen 9 years ago
parent
commit
98cc47b

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/aceSqlWorker.js

@@ -14,8 +14,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-importScripts('/static/desktop/js/autocomplete/sql.js?version=3');
-importScripts('/static/desktop/js/sqlFunctions.js?version=3');
+importScripts('/static/desktop/js/autocomplete/sql.js?version=4');
+importScripts('/static/desktop/js/sqlFunctions.js?version=4');
 
 (function () {
 

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql.jisonlex

@@ -394,7 +394,7 @@
 <hdfs>'\u2020'                             { parser.yy.cursorFound = true; return 'CURSOR'; }
 <hdfs>'\u2021'                             { parser.yy.cursorFound = true; return 'PARTIAL_CURSOR'; }
 <hdfs>\s+[']                               { return 'HDFS_START_QUOTE'; }
-<hdfs>[^'\u2020\u2021]+                    { return 'HDFS_PATH'; }
+<hdfs>[^'\u2020\u2021]+                    { addHdfsLocation(yylloc, yytext); return 'HDFS_PATH'; }
 <hdfs>[']                                  { this.popState(); return 'HDFS_END_QUOTE'; }
 <hdfs><<EOF>>                              { return 'EOF'; }
 

+ 18 - 10
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js

@@ -5022,6 +5022,14 @@ var addFunctionLocation = function (location, functionName) {
   });
 };
 
+var addHdfsLocation = function (location, path) {
+  parser.yy.locations.push({
+    type: 'hdfs',
+    location: adjustLocationForCursor(location),
+    path: path
+  });
+};
+
 var addDatabaseLocation = function (location, identifierChain) {
   parser.yy.locations.push({
     type: 'database',
@@ -6245,23 +6253,23 @@ case 335: addFunctionLocation(yy_.yylloc, 'variance_pop'); return 325;
 break;
 case 336: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 326; 
 break;
-case 337: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 337: addFunctionLocation(yy_.yylloc, 'dense_rank'); return 327; 
 break;
-case 338: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 338: addFunctionLocation(yy_.yylloc, 'first_value'); return 327; 
 break;
-case 339: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 339: addFunctionLocation(yy_.yylloc, 'lag'); return 327; 
 break;
-case 340: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 340: addFunctionLocation(yy_.yylloc, 'last_value'); return 327; 
 break;
-case 341: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 341: addFunctionLocation(yy_.yylloc, 'lead'); return 327; 
 break;
-case 342: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 342: addFunctionLocation(yy_.yylloc, 'rank'); return 327; 
 break;
-case 343: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 343: addFunctionLocation(yy_.yylloc, 'row_number'); return 327; 
 break;
-case 344: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 344: addFunctionLocation(yy_.yylloc, 'cume_dist'); return 327; 
 break;
-case 345: addFunctionLocation(yy_.yylloc, 'variance_samp'); return 327; 
+case 345: addFunctionLocation(yy_.yylloc, 'percent_rank'); return 327; 
 break;
 case 346: return 328; 
 break;
@@ -6277,7 +6285,7 @@ case 351: parser.yy.cursorFound = true; return 379;
 break;
 case 352: return 330; 
 break;
-case 353: return 839; 
+case 353: addHdfsLocation(yy_.yylloc, yy_.yytext); return 839; 
 break;
 case 354: this.popState(); return 840; 
 break;

+ 8 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql_support.js

@@ -1024,6 +1024,14 @@ var addFunctionLocation = function (location, functionName) {
   });
 };
 
+var addHdfsLocation = function (location, path) {
+  parser.yy.locations.push({
+    type: 'hdfs',
+    location: adjustLocationForCursor(location),
+    path: path
+  });
+};
+
 var addDatabaseLocation = function (location, identifierChain) {
   parser.yy.locations.push({
     type: 'database',

+ 24 - 1
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecLocations.js

@@ -153,6 +153,29 @@
       });
     });
 
+    describe('HDFS paths', function () {
+      fit('should report locations for "LOAD DATA LOCAL INPATH \'/some/path/file.ble\' OVERWRITE INTO TABLE bla; |"', function () {
+        assertLocations({
+          dialect: 'hive',
+          beforeCursor: 'LOAD DATA LOCAL INPATH \'/some/path/file.ble\' OVERWRITE INTO TABLE bla;',
+          expectedLocations: [
+            { type: 'hdfs', location: {first_line: 1, last_line: 1, first_column: 25, last_column: 44}, path: '/some/path/file.ble' },
+            { type: 'table', location: {first_line: 1, last_line: 1, first_column: 67, last_column: 70}, identifierChain: [{name: 'bla'}] }
+          ]
+        });
+      });
+
+      fit('should report locations for "CREATE TABLE bla (id INT) LOCATION \'/bla/bla/\'; |"', function () {
+        assertLocations({
+          dialect: 'impala',
+          beforeCursor: 'CREATE TABLE bla (id INT) LOCATION \'/bla/bla/\';',
+          expectedLocations: [
+            { type: 'hdfs', location: {first_line: 1, last_line: 1, first_column: 37, last_column: 46}, path: '/bla/bla/' }
+          ]
+        });
+      });
+    });
+
     describe('Hive specific', function () {
       it('should report locations for "SELECT * FROM testTable t1 ORDER BY t1.a ASC, t1.b, t1.c DESC, t1.d;\nSELECT t1.bla FROM testTable2 t1;\\nSELECT * FROM testTable3 t3, testTable4 t4; |"', function () {
         assertLocations({
@@ -331,7 +354,7 @@
         });
       });
     });
-//SELECT tmp.bc, ROUND(tmp.r, 2) AS r FROM ( SELECT tstDb1.b1.cat AS bc, SUM(tstDb1.b1.price * tran.qua) AS r FROM tstDb1.b1 JOIN [SHUFFLE] tran ON ( tran.b_id = tstDb1.b1.id AND YEAR(tran.tran_d) BETWEEN 2008 AND 2010) GROUP BY tstDb1.b1.cat) tmp ORDER BY r DESC LIMIT 60;',
+
     describe('Impala specific', function () {
       it('should report locations for "SELECT tmp.bc, ROUND(tmp.r, 2) AS r FROM ( SELECT tstDb1.b1.cat AS bc, SUM(tstDb1.b1.price * tran.qua) AS r FROM tstDb1.b1 JOIN [SHUFFLE] tran ON ( tran.b_id = tstDb1.b1.id AND YEAR(tran.tran_d) BETWEEN 2008 AND 2010) GROUP BY tstDb1.b1.cat) tmp ORDER BY r DESC LIMIT 60; |"', function () {
         assertLocations({

+ 35 - 0
desktop/core/src/desktop/templates/sql_context_popover.mako

@@ -278,6 +278,7 @@ from metadata.conf import has_navigator
       <div class="sql-context-link-row">
         <a class="inactive-action pointer" data-bind="visible: isTable || isColumn, click: function() { huePubSub.publish('sql.context.popover.show.in.assist') }"><i style="font-size: 11px;" title="${ _("Show in Assist...") }" class="fa fa-search"></i> ${ _("Assist") }</a>
         <a class="inactive-action pointer" data-bind="visible: isTable, click: function() { huePubSub.publish('sql.context.popover.open.in.metastore') }"><i style="font-size: 11px;" title="${ _("Open in Metastore...") }" class="fa fa-external-link"></i> ${ _("Metastore") }</a>
+        <a class="inactive-action pointer" data-bind="visible: isHdfs, click: function() { huePubSub.publish('sql.context.popover.open.in.file.browser') }"><i style="font-size: 11px;" title="${ _("Open in File Browser...") }" class="fa fa-external-link"></i> ${ _("File Browser") }</a>
       </div>
     </div>
   </script>
@@ -382,6 +383,14 @@ from metadata.conf import has_navigator
     </div>
   </script>
 
+  <script type="text/html" id="sql-context-hdfs-details">
+    <div class="sql-context-flex-fill" data-bind="with: details, niceScroll">
+      <div style="padding: 8px">
+        <div style="margin: 10px 10px 18px 10px;"><pre data-bind="text: ko.mapping.toJSON($data)"></pre></div>
+      </div>
+    </div>
+  </script>
+
   <script type="text/html" id="sql-context-function-details">
     <div class="sql-context-flex-fill" data-bind="with: details, niceScroll">
       <div style="padding: 8px">
@@ -811,6 +820,27 @@ from metadata.conf import has_navigator
         self.activeTab = ko.observable('tags');
       }
 
+      function HdfsContextTabs(data) {
+        var self = this;
+
+        // TODO: Update Ace token with selected path
+        self.data = ko.observable({
+          details: data,
+          loading: ko.observable(false),
+          hasErrors: ko.observable(false)
+        });
+
+        pubSubs.push(huePubSub.subscribe('sql.context.popover.open.in.file.browser', function () {
+          window.open((data.path.indexOf('/') === 0 ? '/filebrowser/#' : '/filebrowser/#/') + data.path, '_blank');
+        }));
+
+
+        self.tabs = [
+          { id: 'details', label: '${ _("Details") }', template: 'sql-context-hdfs-details', templateData: self.data }
+        ];
+        self.activeTab = ko.observable('details');
+      }
+
       function FunctionContextTabs(data, sourceType) {
         var self = this;
         self.func = ko.observable({
@@ -1061,6 +1091,7 @@ from metadata.conf import has_navigator
         self.isTable = params.data.type === 'table';
         self.isColumn = params.data.type === 'column';
         self.isFunction = params.data.type === 'function';
+        self.isHdfs = params.data.type === 'hdfs';
 
         if (self.isDatabase) {
           self.contents = new DatabaseContextTabs(self.data, self.sourceType);
@@ -1078,6 +1109,10 @@ from metadata.conf import has_navigator
           self.contents = new FunctionContextTabs(self.data, self.sourceType);
           self.title = self.data.function;
           self.iconClass = 'fa-superscript'
+        } else if (self.isHdfs) {
+          self.contents = new HdfsContextTabs(self.data);
+          self.title = self.data.path;
+          self.iconClass = 'fa-folder-o'
         } else {
           self.title = '';
           self.iconClass = 'fa-info'