فهرست منبع

[notebook] Add sql dialect flag for snippets in the snippet view settings

Each snippet has an autocompleter and the sql dialect flag is used to control whether it should fetch completion for or not.
Johan Ahlen 10 سال پیش
والد
کامیت
42ab1ed

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete.js

@@ -34,6 +34,9 @@ function Autocompleter(options) {
 // ACE Format for autocompleter
 Autocompleter.prototype.getCompletions = function (editor, session, pos, prefix, callback) {
   var self = this;
+  if (! self.snippet.isSqlDialect()) {
+    return;
+  }
 
   var before = editor.getTextBeforeCursor(";");
   var after = editor.getTextAfterCursor(";");

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

@@ -145,6 +145,10 @@ var Snippet = function (vm, notebook, snippet) {
   self.ace = ko.observable(null);
   self.errors = ko.observableArray([]);
 
+  self.isSqlDialect = function () {
+    return vm.getSnippetViewSettings(self.type()).sqlDialect;
+  };
+
   self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
   self.codemirrorSize = ko.observable(typeof snippet.codemirrorSize != "undefined" && snippet.codemirrorSize != null ? snippet.codemirrorSize : 100);
   // self.statement_raw.extend({ rateLimit: 150 }); // Should prevent lag from typing but currently send the old query when using the key shortcut

+ 6 - 3
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -949,7 +949,8 @@ from desktop.views import _ko
     default: {
       placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
       aceMode: 'ace/mode/sql',
-      snippetIcon: 'fa-database'
+      snippetIcon: 'fa-database',
+      sqlDialect: true
     },
     code: {
       placeHolder: '${ _("Example: 1 + 1, or press CTRL + space") }',
@@ -958,12 +959,14 @@ from desktop.views import _ko
     hive: {
       placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
       aceMode: 'ace/mode/hive',
-      snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }'
+      snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
+      sqlDialect: true
     },
     impala: {
       placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
       aceMode: 'ace/mode/impala',
-      snippetImage: '${ static("impala/art/icon_impala_48.png") }'
+      snippetImage: '${ static("impala/art/icon_impala_48.png") }',
+      sqlDialect: true
     },
     jar : {
       snippetIcon: 'fa-file-archive-o '