Skip to content

Commit 08c1115

Browse files
authored
Merge pull request #722 from KxSystems/ee-fixes
Implement structured text for python for kdb and IE sp
2 parents ce64b30 + a7f28b8 commit 08c1115

File tree

8 files changed

+43
-39
lines changed

8 files changed

+43
-39
lines changed

CHANGELOG.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,28 @@ All notable changes to the **kdb VS Code extension** are documented in this file
66

77
### Enhancements
88

9-
- Added quick connections
10-
- Run on REPL by default
11-
- SQL Workbook
12-
- Connect and auto execute query functionality
13-
- Use own grid instead of ag-grid-community for kdb Results View
14-
- Nested objects are better supported in kdb Results View
15-
- Add support for KDB-X modules in language server
16-
- Moved documentation to its own site
17-
- Ability to execute selection in quke files
9+
- Added quick connections for faster access to kdb environments
10+
- REPL is now the default execution target
11+
- Introduced SQL Workbook support
12+
- Added ability to connect and automatically execute queries
13+
- Replaced ag-grid-community with a custom grid for the kdb Results View
14+
- Improved support for nested objects in the kdb Results View
15+
- Moved documentation to a dedicated [documentation site](code.kx.com/vscode)
16+
- Added ability to execute selection in quke files
1817

1918
### Fixes
2019

21-
- kdb output channel should support log levels
22-
- CSV export does not work properly for cells that contain lists or strings
23-
- Auto resizing of grid columns
24-
- Specific python query executions not working
20+
- kdb output channel now correctly supports log levels
21+
- Fixed CSV export issues for cells containing lists or strings
22+
- Fixed auto-resizing behavior for grid columns
23+
- Resolved issues with specific Python query executions
2524

2625
### Internal Improvements
2726

28-
- Updated telemetry data sent
29-
- Use structured text for datasources
30-
- Integrate KDB-X KX_TTY feature in REPL
27+
- Updated telemetry data collection
28+
- Implemented the use of structured text for datasources
29+
- Added use of structured text for Python
3130
- Added q CI testing
32-
- Updated query wrappers
3331

3432
# v1.16.1
3533

src/classes/insightsConnection.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,7 @@ export class InsightsConnection {
724724
};
725725

726726
if (this.insightsVersion) {
727-
/* TODO: Workaround for Python structuredText bug */
728-
if (
729-
!isPython &&
730-
isBaseVersionGreaterOrEqual(this.insightsVersion, 1.12)
731-
) {
727+
if (isBaseVersionGreaterOrEqual(this.insightsVersion, 1.12)) {
732728
body.returnFormat = isTableView ? "structuredText" : "text";
733729
} else {
734730
body.isTableView = isTableView;
@@ -768,8 +764,6 @@ export class InsightsConnection {
768764
if (!response.data.error) {
769765
if (isTableView) {
770766
if (
771-
/* TODO: Workaround for Python structuredText bug */
772-
!isPython &&
773767
this.insightsVersion &&
774768
isBaseVersionGreaterOrEqual(this.insightsVersion, 1.12)
775769
) {

src/classes/localConnection.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { commands } from "vscode";
1919
import { ext } from "../extensionVariables";
2020
import { QueryResult, QueryResultType } from "../models/queryResult";
2121
import { ServerObject } from "../models/serverObject";
22-
import { convertStringToArray, handleQueryResults } from "../utils/execution";
22+
import { handleQueryResults } from "../utils/execution";
2323
import { MessageKind, notify } from "../utils/notifications";
2424
import { queryWrapper } from "../utils/queryUtils";
2525

@@ -128,7 +128,12 @@ export class LocalConnection {
128128
const args: any[] = [];
129129
const wrapper = queryWrapper(!!isPython);
130130
if (isPython) {
131-
args.push(stringify ? "text" : "serialized", command, "first", 10000);
131+
args.push(
132+
stringify ? "text" : "structuredText",
133+
command,
134+
"first",
135+
10000,
136+
);
132137
} else {
133138
args.push(
134139
context ?? ".",
@@ -148,12 +153,10 @@ export class LocalConnection {
148153
);
149154
} else {
150155
const result = res.result === null ? "" : res.result;
151-
if (!stringify && !isPython) {
152-
resolve(JSON.parse(result));
153-
} else if (ext.isResultsTabVisible && stringify) {
154-
resolve(convertStringToArray(result ? result : ""));
155-
} else {
156+
if (stringify) {
156157
resolve(result);
158+
} else {
159+
resolve(JSON.parse(result));
157160
}
158161
}
159162
this.updateGlobal();

src/commands/dataSourceCommand.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,10 @@ export function getPartialDatasourceFile(
557557
: <DataSourceFiles>{
558558
dataSource: {
559559
selectedType: "QSQL",
560-
qsql: { query: getQSQLWrapper(query, isPython), selectedTarget },
560+
qsql: {
561+
query: getQSQLWrapper(query, "serialized", isPython),
562+
selectedTarget,
563+
},
561564
source: query,
562565
},
563566
};

src/commands/workspaceCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ export async function runOnRepl(editor: TextEditor, type?: ExecutionTypes) {
574574
repl.show();
575575
return repl.executeQuery(
576576
isPython(uri)
577-
? getPythonWrapper(text)
577+
? getPythonWrapper(text, "serialized")
578578
: isSql(uri)
579579
? getSQLWrapper(text)
580580
: text,

src/services/notebookController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class KxNotebookController {
8787
const text = cell.document.getText();
8888
const result = await repl.executeQuery(
8989
kind === CellKind.PYTHON
90-
? getPythonWrapper(text)
90+
? getPythonWrapper(text, "serialized")
9191
: kind === CellKind.SQL
9292
? getSQLWrapper(text)
9393
: text,

src/utils/queryUtils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export function normalizePyQuery(query: string): string {
281281

282282
export function getPythonWrapper(
283283
query: string,
284-
returnFormat: "serialized" | "text" | "structuredText" = "serialized",
284+
returnFormat: "serialized" | "text" | "structuredText",
285285
): string {
286286
const wrapper = normalizeQSQLQuery(queryWrapper(true));
287287
const args = {
@@ -293,8 +293,14 @@ export function getPythonWrapper(
293293
return `{[returnFormat;code;sample_fn;sample_size] res:${wrapper}[returnFormat;code;sample_fn;sample_size];$[res\`errored;res\`error;res\`result]}["${args.returnFormat}";"${args.code}";"${args.sample_fn}";${args.sample_size}]`;
294294
}
295295

296-
export function getQSQLWrapper(query: string, isPython?: boolean): string {
297-
return isPython ? getPythonWrapper(query) : normalizeQSQLQuery(query);
296+
export function getQSQLWrapper(
297+
query: string,
298+
returnFormat: "serialized" | "text" | "structuredText",
299+
isPython?: boolean,
300+
): string {
301+
return isPython
302+
? getPythonWrapper(query, returnFormat)
303+
: normalizeQSQLQuery(query);
298304
}
299305

300306
export function getSQLWrapper(query: string): string {

test/suite/utils/queryUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,13 @@ describe("queryUtils", () => {
615615
let queryWrappeStub: sinon.SinonStub;
616616

617617
it("should not add extra semicolon", () => {
618-
const res = queryUtils.getQSQLWrapper("a:1;\na");
618+
const res = queryUtils.getQSQLWrapper("a:1;\na", "serialized");
619619
assert.strictEqual(res, "a:1;\na");
620620
});
621621

622622
it("should normalize python code using wrapper", () => {
623623
assert.throws(() => {
624-
queryUtils.getQSQLWrapper(``, true);
624+
queryUtils.getQSQLWrapper(``, "serialized", true);
625625
sinon.assert.calledOnce(queryWrappeStub);
626626
});
627627
});

0 commit comments

Comments
 (0)