Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to the **kdb VS Code extension** are documented in this file.

# v1.16.0

### Enhancements

- Refactored extension walkthrough for KDB-X GA
- Ability to execute SQL files on REPL
- Removed `local` connection

### Fixes

- Resolved an issue where query history was not showing copy action for some files

# v1.15.0

### Enhancements
Expand Down
13 changes: 9 additions & 4 deletions src/commands/workspaceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
notify,
Runner,
} from "../utils/notifications";
import { getPythonWrapper } from "../utils/queryUtils";
import { getPythonWrapper, getSQLWrapper } from "../utils/queryUtils";
import {
cleanAssemblyName,
cleanDapName,
Expand Down Expand Up @@ -214,13 +214,13 @@ export function getConnectionForUri(uri: Uri) {
}
}

/* c8 ignore next */
export async function pickConnection(uri: Uri) {
/* c8 ignore start */
const server = getServerForUri(uri);
const servers = getServers();

const items = ["(none)"];
if (isQ(uri) || isNotebook(uri) || isPython(uri)) {
if (isQ(uri) || isNotebook(uri) || isPython(uri) || isSql(uri)) {
items.push(ext.REPL);
}
items.push(...servers);
Expand All @@ -244,6 +244,7 @@ export async function pickConnection(uri: Uri) {
await setServerForUri(uri, picked);
}
return picked;
/* c8 ignore stop */
}

/* c8 ignore next */
Expand Down Expand Up @@ -506,7 +507,11 @@ export async function runOnRepl(editor: TextEditor, type?: ExecutionTypes) {
const repl = await ReplConnection.getOrCreateInstance(uri);
repl.show();
return repl.executeQuery(
isPython(uri) ? getPythonWrapper(text) : text,
isPython(uri)
? getPythonWrapper(text)
: isSql(uri)
? getSQLWrapper(text)
: text,
token,
);
});
Expand Down
10 changes: 6 additions & 4 deletions src/services/notebookController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
resultToBase64,
needsScratchpad,
getPythonWrapper,
getSQLWrapper,
} from "../utils/queryUtils";
import { convertToGrid, formatResult } from "../utils/resultsRenderer";

Expand Down Expand Up @@ -77,12 +78,13 @@ export class KxNotebookController {
let success = false;
try {
const kind = getCellKind(cell);
if (kind === CellKind.SQL) {
throw new Error("SQL is not supported on REPL.");
}
const text = cell.document.getText();
const result = await repl.executeQuery(
kind === CellKind.PYTHON ? getPythonWrapper(text) : text,
kind === CellKind.PYTHON
? getPythonWrapper(text)
: kind === CellKind.SQL
? getSQLWrapper(text)
: text,
execution.token,
);
this.replaceOutput(execution, {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/queryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ export function getQSQLWrapper(query: string, isPython?: boolean): string {
return isPython ? getPythonWrapper(query) : normalizeQSQLQuery(query);
}

export function getSQLWrapper(query: string): string {
return `s)${query.replace(/(?:\r\n|\n)/g, " ")}`;
}

export function generateQTypes(meta: { [key: string]: number }): any {
const newMeta: { [key: string]: string } = {};
for (const key in meta) {
Expand Down
4 changes: 2 additions & 2 deletions test/suite/services/notebook/notebookController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ describe("Controller", () => {
});

describe("sql cell", () => {
it("should not execute", async () => {
it("should execute", async () => {
await instance.execute(
[notebookTestUtils.createCell("sql")],
notebookTestUtils.createNotebook(),
createController(),
);
sinon.assert.calledOnceWithMatch(replaceOutputStub, sinon.match.any, {
text: "Error: SQL is not supported on REPL.",
text: "RESULT",
mime: "text/plain",
});
});
Expand Down