Browse Source

HUE-8155 [metastore] Show view SQL for views in the Table Browser

Johan Ahlen 7 years ago
parent
commit
9055de8a3d

+ 24 - 2
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -365,6 +365,7 @@ var MetastoreTable = (function () {
 
 
     // TODO: Check if enough or if we need to fetch additional details
     // TODO: Check if enough or if we need to fetch additional details
     self.isView = ko.observable(self.catalogEntry.isView());
     self.isView = ko.observable(self.catalogEntry.isView());
+    self.viewSql = ko.observable();
 
 
     self.optimizerStats = ko.observable();
     self.optimizerStats = ko.observable();
     self.optimizerDetails = ko.observable();
     self.optimizerDetails = ko.observable();
@@ -377,6 +378,7 @@ var MetastoreTable = (function () {
     self.loadingColumns = ko.observable(false);
     self.loadingColumns = ko.observable(false);
     self.loadingQueries = ko.observable(false);
     self.loadingQueries = ko.observable(false);
     self.loadingComment = ko.observable(false);
     self.loadingComment = ko.observable(false);
+    self.loadingViewSql = ko.observable(false);
 
 
     self.columns = ko.observableArray();
     self.columns = ko.observableArray();
 
 
@@ -394,7 +396,7 @@ var MetastoreTable = (function () {
 
 
     self.refreshing = ko.pureComputed(function () {
     self.refreshing = ko.pureComputed(function () {
       return self.loadingDetails() || self.loadingColumns() || self.loadingQueries() || self.loadingComment() ||
       return self.loadingDetails() || self.loadingColumns() || self.loadingQueries() || self.loadingComment() ||
-        self.samples.loading() || self.partitions.loading();
+        self.samples.loading() || self.partitions.loading() || self.loadingViewSql();
     });
     });
 
 
     self.partitionsCountLabel = ko.pureComputed(function () {
     self.partitionsCountLabel = ko.pureComputed(function () {
@@ -479,7 +481,6 @@ var MetastoreTable = (function () {
     };
     };
 
 
     self.fetchDetails = function () {
     self.fetchDetails = function () {
-
       self.loadingComment(true);
       self.loadingComment(true);
       self.database.catalogEntry.loadNavigatorMetaForChildren().done(function () {
       self.database.catalogEntry.loadNavigatorMetaForChildren().done(function () {
         self.catalogEntry.getComment().done(self.comment);
         self.catalogEntry.getComment().done(self.comment);
@@ -487,6 +488,10 @@ var MetastoreTable = (function () {
         self.loadingComment(false);
         self.loadingComment(false);
       });
       });
 
 
+      if (self.catalogEntry.isView()) {
+        self.loadingViewSql(true);
+      }
+
       self.loadingDetails(true);
       self.loadingDetails(true);
       self.catalogEntry.getAnalysis().done(function (analysis) {
       self.catalogEntry.getAnalysis().done(function (analysis) {
         self.tableDetails(analysis);
         self.tableDetails(analysis);
@@ -499,9 +504,26 @@ var MetastoreTable = (function () {
           self.partitions.loading(false);
           self.partitions.loading(false);
           self.partitions.loaded(true);
           self.partitions.loaded(true);
         }
         }
+
+        var found = analysis.properties && analysis.properties.some(function (property) {
+          if (property.col_name.toLowerCase() === 'view original text:') {
+            ApiHelper.getInstance().formatSql({ statements: property.data_type }).done(function (formatResponse) {
+              self.viewSql(formatResponse.status === 0 ? formatResponse.formatted_statements : property.data_type)
+            }).fail(function () {
+              self.viewSql(property.data_type)
+            }).always(function () {
+              self.loadingViewSql(false);
+            })
+            return true;
+          }
+        });
+        if (!found) {
+          self.loadingViewSql(false);
+        }
       }).fail(function () {
       }).fail(function () {
         self.partitions.loading(false);
         self.partitions.loading(false);
         self.partitions.loaded(true);
         self.partitions.loaded(true);
+        self.loadingViewSql(false);
       }).always(function () {
       }).always(function () {
         self.refreshingTableStats(false);
         self.refreshingTableStats(false);
         self.loadingDetails(false)
         self.loadingDetails(false)

+ 25 - 9
apps/metastore/src/metastore/templates/metastore.mako

@@ -815,6 +815,15 @@ ${ components.menubar(is_embeddable) }
   </div>
   </div>
 </script>
 </script>
 
 
+<script type="text/html" id="metastore-view-sql-tab">
+  <div style="padding: 5px 15px">
+    <!-- ko hueSpinner: { spin: loadingViewSql, inline: true } --><!-- /ko -->
+    <!-- ko ifnot: loadingViewSql -->
+    <div data-bind="highlight: { value: viewSql, formatted: true, dialect: catalogEntry.getSourceType() }"></div>
+    <!-- /ko -->
+  </div>
+</script>
+
 <script type="text/html" id="metastore-details-tab">
 <script type="text/html" id="metastore-details-tab">
   <!-- ko with: tableDetails -->
   <!-- ko with: tableDetails -->
   <table class="properties-table">
   <table class="properties-table">
@@ -934,15 +943,18 @@ ${ components.menubar(is_embeddable) }
       <li data-bind="css: { 'active': $root.currentTab() === 'partitions' }"><a href="javascript: void(0);" data-bind="click: function() { $root.currentTab('partitions'); }">${_('Partitions')} (<span data-bind="text: partitionsCountLabel"></span>)</a></li>
       <li data-bind="css: { 'active': $root.currentTab() === 'partitions' }"><a href="javascript: void(0);" data-bind="click: function() { $root.currentTab('partitions'); }">${_('Partitions')} (<span data-bind="text: partitionsCountLabel"></span>)</a></li>
     <!-- /ko -->
     <!-- /ko -->
     <li data-bind="css: { 'active': $root.currentTab() === 'sample' }"><a href="javascript: void(0);" data-bind="click: function() { $root.currentTab('sample'); }">${_('Sample')} (<span data-bind="text: samples.rows().length"></span>)</a></li>
     <li data-bind="css: { 'active': $root.currentTab() === 'sample' }"><a href="javascript: void(0);" data-bind="click: function() { $root.currentTab('sample'); }">${_('Sample')} (<span data-bind="text: samples.rows().length"></span>)</a></li>
-    <!-- ko if: $root.optimizerEnabled() -->
-      <!-- ko if: $root.database().table().optimizerDetails() -->
-      ##<li data-bind="css: { 'active': $root.currentTab() === 'permissions' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('permissions'); }">${_('Permissions')}</a></li>
-      ##<li data-bind="css: { 'active': $root.currentTab() === 'queries' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('queries'); }">${_('Queries')} (<span data-bind="text: $root.database().table().optimizerDetails().queryCount"></span>)</a></li>
-      ##<li data-bind="css: { 'active': $root.currentTab() === 'joins' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('joins'); }">${_('Joins')} (<span data-bind="text: $root.database().table().optimizerDetails().joinCount"></span>)</a></li>
-      <!-- /ko -->
-      ##<!-- ko if: $root.database().table().relationshipsDetails() -->
-      ##<li data-bind="css: { 'active': $root.currentTab() === 'relationships' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('relationships'); }">${_('Relationships')} (<span data-bind="text: $root.database().table().relationshipsDetails().inputs().length + $root.database().table().relationshipsDetails().targets().length"></span>)</a></li>
-      ##<!-- /ko -->
+##     <!-- ko if: $root.optimizerEnabled() -->
+##       <!-- ko if: $root.database().table().optimizerDetails() -->
+##       <li data-bind="css: { 'active': $root.currentTab() === 'permissions' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('permissions'); }">${_('Permissions')}</a></li>
+##       <li data-bind="css: { 'active': $root.currentTab() === 'queries' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('queries'); }">${_('Queries')} (<span data-bind="text: $root.database().table().optimizerDetails().queryCount"></span>)</a></li>
+##       <li data-bind="css: { 'active': $root.currentTab() === 'joins' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('joins'); }">${_('Joins')} (<span data-bind="text: $root.database().table().optimizerDetails().joinCount"></span>)</a></li>
+##       <!-- /ko -->
+##       <!-- ko if: $root.database().table().relationshipsDetails() -->
+##       <li data-bind="css: { 'active': $root.currentTab() === 'relationships' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('relationships'); }">${_('Relationships')} (<span data-bind="text: $root.database().table().relationshipsDetails().inputs().length + $root.database().table().relationshipsDetails().targets().length"></span>)</a></li>
+##       <!-- /ko -->
+##     <!-- /ko -->
+    <!-- ko if: catalogEntry.isView() -->
+    <li data-bind="css: { 'active' : $root.currentTab() === 'viewSql' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('viewSql'); }">${ _('View SQL') }</a></li>
     <!-- /ko -->
     <!-- /ko -->
     <li data-bind="css: { 'active' : $root.currentTab() === 'details' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('details'); }">${ _('Details') }</a></li>
     <li data-bind="css: { 'active' : $root.currentTab() === 'details' }"><a href="javascript: void(0);" data-bind="click: function(){ $root.currentTab('details'); }">${ _('Details') }</a></li>
   </ul>
   </ul>
@@ -977,6 +989,10 @@ ${ components.menubar(is_embeddable) }
         <!-- ko template: { name: 'metastore-relationships-tab', data: $root.database().table().relationshipsDetails() } --><!-- /ko -->
         <!-- ko template: { name: 'metastore-relationships-tab', data: $root.database().table().relationshipsDetails() } --><!-- /ko -->
       <!-- /ko -->
       <!-- /ko -->
 
 
+      <!-- ko if: $root.currentTab() === 'viewSql' -->
+        <!-- ko template: 'metastore-view-sql-tab' --><!-- /ko -->
+      <!-- /ko -->
+
       <!-- ko if: $root.currentTab() === 'details' -->
       <!-- ko if: $root.currentTab() === 'details' -->
         <!-- ko template: 'metastore-details-tab' --><!-- /ko -->
         <!-- ko template: 'metastore-details-tab' --><!-- /ko -->
       <!-- /ko -->
       <!-- /ko -->