Ver Fonte

HUE-9187 [editor] Switch to connector instead of sourceType in the executor

Johan Ahlen há 5 anos atrás
pai
commit
0fdc985c59

+ 1 - 1
desktop/core/src/desktop/js/api/apiHelper.js

@@ -2115,7 +2115,7 @@ class ApiHelper {
    */
   async executeStatement(options) {
     const executable = options.executable;
-    const url = EXECUTE_API_PREFIX + executable.executor.sourceType();
+    const url = EXECUTE_API_PREFIX + executable.executor.connector().type;
 
     const promise = new Promise(async (resolve, reject) => {
       let data = {};

+ 11 - 5
desktop/core/src/desktop/js/apps/notebook2/execution/executable.js

@@ -167,7 +167,10 @@ export default class Executable {
     this.setProgress(0);
 
     try {
-      hueAnalytics.log('notebook', 'execute/' + this.executor.sourceType());
+      hueAnalytics.log(
+        'notebook',
+        'execute/' + (this.executor.connector() ? this.executor.connector().type : '')
+      );
       try {
         const response = await this.internalExecute();
         this.handle = response.handle;
@@ -309,7 +312,10 @@ export default class Executable {
 
   async cancel() {
     if (this.cancellables.length && this.status === EXECUTION_STATUS.running) {
-      hueAnalytics.log('notebook', 'cancel/' + this.executor.sourceType());
+      hueAnalytics.log(
+        'notebook',
+        'cancel/' + (this.executor.connector() ? this.executor.connector().type : '')
+      );
       this.setStatus(EXECUTION_STATUS.canceling);
       while (this.cancellables.length) {
         await this.cancellables.pop().cancel();
@@ -379,10 +385,10 @@ export default class Executable {
       };
     }
 
-    const session = await sessionManager.getSession({ type: this.executor.sourceType() });
+    const session = await sessionManager.getSession({ type: this.executor.connector().type });
     const statement = this.getStatement();
     const snippet = {
-      type: this.executor.sourceType(),
+      type: this.executor.connector().type,
       result: {
         handle: this.handle
       },
@@ -399,7 +405,7 @@ export default class Executable {
     };
 
     const notebook = {
-      type: this.executor.sourceType(),
+      type: this.executor.connector().type,
       snippets: [snippet],
       id: this.notebookId,
       uuid: hueUtils.UUID(),

+ 2 - 2
desktop/core/src/desktop/js/apps/notebook2/execution/executor.js

@@ -24,7 +24,7 @@ class Executor {
   /**
    * @param options
    * @param {boolean} [options.isSqlEngine] (default false)
-   * @param {observable<string>} options.sourceType
+   * @param {observable<Connector>} options.connector
    * @param {observable<ContextCompute>} options.compute
    * @param {observable<ContextNamespace>} options.namespace
    * @param {string} [options.database]
@@ -32,7 +32,7 @@ class Executor {
    * @param {boolean} [options.isOptimizerEnabled] - Default false
    */
   constructor(options) {
-    this.sourceType = options.sourceType;
+    this.connector = options.connector;
     this.compute = options.compute;
     this.namespace = options.namespace;
     this.database = options.database;

+ 1 - 1
desktop/core/src/desktop/js/apps/notebook2/execution/executor.test.js

@@ -30,7 +30,7 @@ describe('executor.js', () => {
       compute: { id: 'compute' },
       namespace: { id: 'namespace' },
       database: 'default',
-      sourceType: 'impala',
+      connector: () => ({ type: 'impala' }),
       statement: statement,
       isSqlEngine: true
     });

+ 2 - 1
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -193,6 +193,7 @@ export default class Snippet {
     this.connector = ko.observable();
 
     this.dialect = ko.pureComputed(() => this.connector() && this.connector().dialect);
+    this.connectorType = ko.pureComputed(() => this.connector() && this.connector().type);
 
     this.isSqlDialect = ko.pureComputed(() => this.connector() && this.connector().is_sql);
     this.defaultLimit = ko.observable(snippetRaw.defaultLimit);
@@ -1006,7 +1007,7 @@ export default class Snippet {
     this.executor = new Executor({
       compute: this.compute,
       database: this.database,
-      sourceType: this.dialect,
+      connector: this.connector,
       namespace: this.namespace,
       defaultLimit: this.defaultLimit,
       isOptimizerEnabled: this.parentVm.isOptimizerEnabled(),