Skip to content

Commit bc2ffee

Browse files
committed
Use Structured Text for datasources
1 parent bbc93f6 commit bc2ffee

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/classes/insightsConnection.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { jwtDecode } from "jwt-decode";
1616
import * as url from "url";
1717

1818
import { ext } from "../extensionVariables";
19-
import { isCompressed, uncompress } from "../ipc/c";
2019
import {
2120
InsightsApiConfig,
2221
InsightsConfig,
@@ -49,7 +48,7 @@ import { retrieveUDAtoCreateReqBody } from "../utils/uda";
4948
const logger = "insightsConnection";
5049

5150
const customHeadersOctet = {
52-
Accept: "application/octet-stream",
51+
Accept: "application/struct-text",
5352
"Content-Type": "application/json",
5453
};
5554
const customHeadersJson = {
@@ -483,7 +482,6 @@ export class InsightsConnection {
483482
if (!options) {
484483
return undefined;
485484
}
486-
options.responseType = "arraybuffer";
487485

488486
notify("REST", MessageKind.DEBUG, {
489487
logger,
@@ -497,14 +495,9 @@ export class InsightsConnection {
497495
MessageKind.DEBUG,
498496
{ logger },
499497
);
500-
if (isCompressed(response.data)) {
501-
response.data = uncompress(response.data);
502-
}
503498
return {
504499
error: "",
505-
arrayBuffer: response.data.buffer
506-
? response.data.buffer
507-
: response.data,
500+
results: response.data.payload,
508501
};
509502
})
510503
.catch((error: any) => {
@@ -514,7 +507,7 @@ export class InsightsConnection {
514507
{ logger, params: error },
515508
);
516509
return {
517-
error: { buffer: error.response.data },
510+
error: error.response.data.header.ai,
518511
arrayBuffer: undefined,
519512
};
520513
});

src/commands/dataSourceCommand.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ import {
4343
import { MessageKind, notify } from "../utils/notifications";
4444
import {
4545
addQueryHistory,
46+
convertRows,
4647
getQSQLWrapper,
4748
handleScratchpadTableRes,
4849
handleWSError,
4950
handleWSResults,
5051
} from "../utils/queryUtils";
52+
import { updatedExtractRowData } from "../utils/resultsRenderer";
5153
import { retrieveUDAtoCreateReqBody } from "../utils/uda";
5254
import { validateScratchpadOutputVariableName } from "../validators/interfaceValidator";
5355

@@ -200,7 +202,12 @@ export async function runDataSource(
200202
}
201203
if (isNotebook || ext.isResultsTabVisible) {
202204
if (success) {
203-
const resultCount = typeof res === "string" ? "0" : res.rows.length;
205+
const resultCount =
206+
typeof res === "string"
207+
? "0"
208+
: res.rows
209+
? res.rows.length
210+
: res.columns?.[0]?.values?.length || 0;
204211
notify(`Results: ${resultCount} rows`, MessageKind.DEBUG, {
205212
logger,
206213
});
@@ -231,8 +238,12 @@ export async function runDataSource(
231238
res = res.errorMsg ? res.errorMsg : res.error;
232239
}
233240

241+
const rowData = res.columns
242+
? convertRows(updatedExtractRowData(res))
243+
: res;
244+
234245
await writeQueryResultsToConsole(
235-
res,
246+
rowData,
236247
query,
237248
connLabel,
238249
executorName,
@@ -312,6 +323,8 @@ export async function runApiDataSource(
312323

313324
if (apiCall?.error) {
314325
return parseError(apiCall.error);
326+
} else if (apiCall?.results) {
327+
return apiCall.results;
315328
} else if (apiCall?.arrayBuffer) {
316329
const results = handleWSResults(apiCall.arrayBuffer);
317330
return handleScratchpadTableRes(results);
@@ -423,6 +436,8 @@ export async function runQsqlDataSource(
423436

424437
if (qsqlCall?.error) {
425438
return parseError(qsqlCall.error);
439+
} else if (qsqlCall?.results) {
440+
return qsqlCall.results;
426441
} else if (qsqlCall?.arrayBuffer) {
427442
const results = handleWSResults(qsqlCall.arrayBuffer, isTableView);
428443
return handleScratchpadTableRes(results);
@@ -446,6 +461,8 @@ export async function runSqlDataSource(
446461

447462
if (sqlCall?.error) {
448463
return parseError(sqlCall.error);
464+
} else if (sqlCall?.results) {
465+
return sqlCall.results;
449466
} else if (sqlCall?.arrayBuffer) {
450467
const results = handleWSResults(sqlCall.arrayBuffer, isTableView);
451468
return handleScratchpadTableRes(results);
@@ -484,6 +501,8 @@ export async function executeUDARequest(
484501

485502
if (udaCall?.error) {
486503
return parseError(udaCall.error);
504+
} else if (udaCall?.results) {
505+
return udaCall.results;
487506
} else if (udaCall?.arrayBuffer) {
488507
const results = handleWSResults(udaCall.arrayBuffer);
489508
return handleScratchpadTableRes(results);

src/models/data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* specific language governing permissions and limitations under the License.
1212
*/
1313

14+
import { StructuredTextResults } from "./queryResult";
15+
1416
export type GetDataError = string | { buffer: ArrayBuffer };
1517

1618
export type GetDataObjectPayload = {
@@ -22,6 +24,7 @@ export type GetDataObjectPayload = {
2224
columns: string[];
2325
rows: any;
2426
};
27+
results?: StructuredTextResults;
2528
arrayBuffer?: ArrayBuffer;
2629
};
2730

src/utils/resultsRenderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export function convertToGrid(
2828
if (
2929
(!isInsights && !isPython) ||
3030
/* TODO: Workaround for Python structuredText bug */
31-
(!isPython && connVersion && isBaseVersionGreaterOrEqual(connVersion, 1.12))
31+
(!isPython &&
32+
connVersion &&
33+
isBaseVersionGreaterOrEqual(connVersion, 1.12)) ||
34+
results.columns
3235
) {
3336
rowData = updatedExtractRowData(results);
3437
columnDefs = updatedExtractColumnDefs(results);

0 commit comments

Comments
 (0)