SQL Kernel Improvements/Removing Spark Code from Core/Attach to Changes (#3790)

* Scenarios work besides loading saved kernel

* Fix compilation issue

* Save and load functional

* Fix loading kernesl issue when sql kernel is not enabled

* Fix language mapping to not be hardcoded any longer

* Remove unnecessary comment

* PR Comments vol. 1

* Code cleanup, use ConnectionProfile instead of IConnectionProfile when accessing serverName

* PR changes vol. 2

* One final comment for PR

* Fix linting issue
This commit is contained in:
Chris LaFreniere
2019-01-25 18:54:04 -08:00
committed by GitHub
parent ea67859de7
commit 43be88a37c
29 changed files with 768 additions and 627 deletions

View File

@@ -14,8 +14,9 @@ import Severity from 'vs/base/common/severity';
import * as Utils from 'sql/platform/connection/common/utils';
import { Deferred } from 'sql/base/common/promise';
import { Disposable } from 'vs/base/common/lifecycle';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
export const sqlKernel: string = localize('sqlKernel', 'SQL');
export const sqlKernelError: string = localize("sqlKernelError", "SQL kernel error");
@@ -63,6 +64,7 @@ export class SqlSessionManager implements nb.SessionManager {
export class SqlSession implements nb.ISession {
private _kernel: SqlKernel;
private _defaultKernelLoaded = false;
private _currentConnection: IConnectionProfile;
public set defaultKernelLoaded(value) {
this._defaultKernelLoaded = value;
@@ -107,12 +109,25 @@ export class SqlSession implements nb.ISession {
changeKernel(kernelInfo: nb.IKernelSpec): Thenable<nb.IKernel> {
return Promise.resolve(this.kernel);
}
configureKernel(kernelInfo: nb.IKernelSpec): Thenable<void> {
return Promise.resolve();
}
configureConnection(connection: ConnectionProfile): Thenable<void> {
if (this._kernel) {
this._kernel.connection = connection;
}
return Promise.resolve();
}
}
class SqlKernel extends Disposable implements nb.IKernel {
private _queryRunner: QueryRunner;
private _columns: IDbColumn[];
private _rows: DbCellValue[][];
private _currentConnection: IConnectionProfile;
static kernelId: number = 0;
constructor( @IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IInstantiationService private _instantiationService: IInstantiationService,
@@ -121,7 +136,7 @@ class SqlKernel extends Disposable implements nb.IKernel {
}
public get id(): string {
return '-1';
return (SqlKernel.kernelId++).toString();
}
public get name(): string {
@@ -159,6 +174,12 @@ class SqlKernel extends Disposable implements nb.IKernel {
return info;
}
public set connection(conn: IConnectionProfile) {
this._currentConnection = conn;
this._queryRunner = undefined;
}
getSpec(): Thenable<nb.IKernelSpec> {
return Promise.resolve(sqlKernelSpec);
}
@@ -167,11 +188,10 @@ class SqlKernel extends Disposable implements nb.IKernel {
if (this._queryRunner) {
this._queryRunner.runQuery(content.code);
} else {
let connections = this._connectionManagementService.getActiveConnections();
let connectionProfile = connections.find(connection => connection.providerName === mssqlProviderName);
let connectionUri = Utils.generateUri(connectionProfile, 'notebook');
let connectionUri = Utils.generateUri(this._currentConnection, 'notebook');
this._queryRunner = this._instantiationService.createInstance(QueryRunner, connectionUri, undefined);
this._connectionManagementService.connect(connectionProfile, connectionUri).then((result) => {
this._connectionManagementService.connect(this._currentConnection, connectionUri).then((result) =>
{
this.addQueryEventListeners(this._queryRunner);
this._queryRunner.runQuery(content.code);
});
@@ -186,7 +206,9 @@ class SqlKernel extends Disposable implements nb.IKernel {
}
interrupt(): Thenable<void> {
return Promise.resolve(undefined);
// TODO: figure out what to do with the QueryCancelResult
return this._queryRunner.cancelQuery().then((cancelResult) => {
});
}
private addQueryEventListeners(queryRunner: QueryRunner): void {
@@ -234,7 +256,11 @@ export class SQLFuture extends Disposable implements FutureInternal {
get inProgress(): boolean {
return !this._queryRunner.hasCompleted;
}
set inProgress(val: boolean) {
if (this._queryRunner && !val) {
this._queryRunner.cancelQuery();
}
}
get msg(): nb.IMessage {
return this._msg;
}