Browse Source

HUE-4866 [editor] Submit query from a source file

Romain Rigaux 9 years ago
parent
commit
799bf622f7

+ 8 - 5
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -103,8 +103,7 @@ class HiveConfiguration(object):
 
   APP_NAME = 'hive'
 
-  PROPERTIES = [
-    {
+  PROPERTIES = [{
       "multiple": True,
       "defaultValue": [],
       "value": [],
@@ -137,8 +136,7 @@ class ImpalaConfiguration(object):
 
   APP_NAME = 'impala'
 
-  PROPERTIES = [
-    {
+  PROPERTIES = [{
       "multiple": True,
       "defaultValue": [],
       "value": [],
@@ -224,7 +222,12 @@ class HS2Api(Api):
 
     statement = self._get_current_statement(db, snippet)
     session = self._get_session(notebook, snippet['type'])
-    query = self._prepare_hql_query(snippet, statement['statement'], session)
+    if snippet.get('statementType') == 'file':
+      query_s = ''
+    else:
+      query_s = statement['statement']
+
+    query = self._prepare_hql_query(snippet, query_s, session)
 
     try:
       if statement.get('statement_id') == 0:

+ 3 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -416,6 +416,9 @@ var EditorViewModel = (function() {
       huePubSub.publish("assist.get.database", self.type());
     }
 
+    self.statementType = ko.observable(typeof snippet.statementType != "undefined" && snippet.statementType != null ? snippet.statementType : 'text');
+    self.statementTypes = ko.observableArray(['text', 'file']); // Maybe computed later for spark
+    self.statementPath = ko.observable(typeof snippet.statementPath != "undefined" && snippet.statementPath != null ? snippet.statementPath : '');
     self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
     self.selectedStatement = ko.observable('');
     self.aceSize = ko.observable(typeof snippet.aceSize != "undefined" && snippet.aceSize != null ? snippet.aceSize : 100);

+ 29 - 9
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1408,6 +1408,11 @@ ${ hueIcons.symbols() }
     <!-- ko if: availableDatabases().length > 0 && isSqlDialect() -->
     <div data-bind="component: { name: 'snippet-db-selection', params: { selectedDatabase: database, availableDatabases: availableDatabases } }" style="display: inline-block"></div>
     <!-- /ko -->
+    
+    <!-- ko if: isSqlDialect() -->
+      <select class="input-medium" data-bind="options: statementTypes, value: statementType"></select>
+    <!-- /ko -->
+
     <a class="inactive-action margin-left-10" href="javascript:void(0)" data-bind="visible: status() != 'ready' && status() != 'loading', click: function() { hideFixedHeaders(); $data.showLogs(!$data.showLogs());}, css: {'blue': $data.showLogs}" title="${ _('Show Logs') }"><i class="fa fa-file-text-o"></i></a>
     <a class="inactive-action margin-left-10" href="javascript:void(0)" data-bind="toggle: settingsVisible, visible: hasProperties, css: { 'blue' : settingsVisible }" title="${ _('Settings and properties') }"><i class="fa fa-cog"></i></a>
     <a class="inactive-action margin-left-10 pointer" title="${ _('Show editor shortcuts') }" data-toggle="modal" data-target="#helpModal"><i class="fa fa-question"></i></a>
@@ -1539,8 +1544,23 @@ ${ hueIcons.symbols() }
     </div>
   </div>
   <div class="row-fluid" style="margin-bottom: 5px">
+
     <div class="editor span12" data-bind="css: {'single-snippet-editor ace-container-resizable' : $root.editorMode() }, clickForAceFocus: ace">
-      <div class="ace-editor" data-bind="css: {'single-snippet-editor ace-editor-resizable' : $root.editorMode(), 'active-editor': inFocus }, attr: { id: id() }, delayedOverflow, aceEditor: {
+      <!-- ko if: statementType() != 'text' -->
+        <div class="control-group">
+          <label class="control-label">${_('Path')}</label>
+          <div class="controls">
+            <input type="text" class="input-xxlarge filechooser-input" data-bind="value: statementPath, valueUpdate: 'afterkeydown', filechooser: statementPath" placeholder="${ _('Path to query, e.g. /user/hue/sample.sql, s3a:///hue/sample.sql') }"/>
+            <!-- ko if: statementPath() -->
+              <a data-bind="attr: {href: '/filebrowser/view=' + statementPath() }" target="_blank" title="${ _('Open in new tab') }">
+                <i class="fa fa-external-link-square"></i>
+              </a>
+            <!-- /ko -->
+          </div>
+      </div>
+      <!-- /ko -->
+
+      <div class="ace-editor" data-bind="visible: statementType() == 'text', css: {'single-snippet-editor ace-editor-resizable' : $root.editorMode(), 'active-editor': inFocus }, attr: { id: id() }, delayedOverflow, aceEditor: {
         snippet: $data,
         contextTooltip: '${ _ko("Right-click for details") }',
         expandStar: '${ _ko("Shift + Click to replace with all columns") }',
@@ -1563,18 +1583,18 @@ ${ hueIcons.symbols() }
         <li class="editor-drop-drop"><a href="javascript:void(0);">DROP TABLE <span class="editor-drop-identifier"></span>...</a></li>
       </ul>
     </div>
+
     <div class="clearfix"></div>
     <ul data-bind="foreach: variables" class="unstyled inline">
-        <li>
-          <div class="input-prepend margin-top-10">
-            <span class="muted add-on" data-bind="text: name"></span>
-            <input class="input-medium" type="text" placeholder="${ _("Variable value") }" data-bind="value: value, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, event: { 'keypress': function (context, e){ if (e.ctrlKey && e.which === 13) { $parent.ace().commands.commands['execute'].exec(); } return true; } }">
-          </div>
-        </li>
-      </ul>
+      <li>
+        <div class="input-prepend margin-top-10">
+          <span class="muted add-on" data-bind="text: name"></span>
+          <input class="input-medium" type="text" placeholder="${ _("Variable value") }" data-bind="value: value, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, event: { 'keypress': function (context, e){ if (e.ctrlKey && e.which === 13) { $parent.ace().commands.commands['execute'].exec(); } return true; } }">
+        </div>
+      </li>
+    </ul>
   </div>
   <div class="clearfix"></div>
-
 </script>
 
 <script type="text/html" id="snippet-chart-settings">