Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 3 additions & 10 deletions src/classes/insightsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { jwtDecode } from "jwt-decode";
import * as url from "url";

import { ext } from "../extensionVariables";
import { isCompressed, uncompress } from "../ipc/c";
import {
InsightsApiConfig,
InsightsConfig,
Expand Down Expand Up @@ -49,7 +48,7 @@ import { retrieveUDAtoCreateReqBody } from "../utils/uda";
const logger = "insightsConnection";

const customHeadersOctet = {
Accept: "application/octet-stream",
Accept: "application/struct-text",
"Content-Type": "application/json",
};
const customHeadersJson = {
Expand Down Expand Up @@ -483,7 +482,6 @@ export class InsightsConnection {
if (!options) {
return undefined;
}
options.responseType = "arraybuffer";

notify("REST", MessageKind.DEBUG, {
logger,
Expand All @@ -497,14 +495,9 @@ export class InsightsConnection {
MessageKind.DEBUG,
{ logger },
);
if (isCompressed(response.data)) {
response.data = uncompress(response.data);
}
return {
error: "",
arrayBuffer: response.data.buffer
? response.data.buffer
: response.data,
results: response.data.payload,
};
})
.catch((error: any) => {
Expand All @@ -514,7 +507,7 @@ export class InsightsConnection {
{ logger, params: error },
);
return {
error: { buffer: error.response.data },
error: error.response.data.header.ai,
arrayBuffer: undefined,
};
});
Expand Down
23 changes: 21 additions & 2 deletions src/commands/dataSourceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ import {
import { MessageKind, notify } from "../utils/notifications";
import {
addQueryHistory,
convertRows,
getQSQLWrapper,
handleScratchpadTableRes,
handleWSError,
handleWSResults,
} from "../utils/queryUtils";
import { updatedExtractRowData } from "../utils/resultsRenderer";
import { retrieveUDAtoCreateReqBody } from "../utils/uda";
import { validateScratchpadOutputVariableName } from "../validators/interfaceValidator";

Expand Down Expand Up @@ -200,7 +202,12 @@ export async function runDataSource(
}
if (isNotebook || ext.isResultsTabVisible) {
if (success) {
const resultCount = typeof res === "string" ? "0" : res.rows.length;
const resultCount =
typeof res === "string"
? "0"
: res.rows
? res.rows.length
: res.columns?.[0]?.values?.length || 0;
notify(`Results: ${resultCount} rows`, MessageKind.DEBUG, {
logger,
});
Expand Down Expand Up @@ -231,8 +238,12 @@ export async function runDataSource(
res = res.errorMsg ? res.errorMsg : res.error;
}

const rowData = res.columns
? convertRows(updatedExtractRowData(res))
: res;

await writeQueryResultsToConsole(
res,
rowData,
query,
connLabel,
executorName,
Expand Down Expand Up @@ -312,6 +323,8 @@ export async function runApiDataSource(

if (apiCall?.error) {
return parseError(apiCall.error);
} else if (apiCall?.results) {
return apiCall.results;
} else if (apiCall?.arrayBuffer) {
const results = handleWSResults(apiCall.arrayBuffer);
return handleScratchpadTableRes(results);
Expand Down Expand Up @@ -423,6 +436,8 @@ export async function runQsqlDataSource(

if (qsqlCall?.error) {
return parseError(qsqlCall.error);
} else if (qsqlCall?.results) {
return qsqlCall.results;
} else if (qsqlCall?.arrayBuffer) {
const results = handleWSResults(qsqlCall.arrayBuffer, isTableView);
return handleScratchpadTableRes(results);
Expand All @@ -446,6 +461,8 @@ export async function runSqlDataSource(

if (sqlCall?.error) {
return parseError(sqlCall.error);
} else if (sqlCall?.results) {
return sqlCall.results;
} else if (sqlCall?.arrayBuffer) {
const results = handleWSResults(sqlCall.arrayBuffer, isTableView);
return handleScratchpadTableRes(results);
Expand Down Expand Up @@ -484,6 +501,8 @@ export async function executeUDARequest(

if (udaCall?.error) {
return parseError(udaCall.error);
} else if (udaCall?.results) {
return udaCall.results;
} else if (udaCall?.arrayBuffer) {
const results = handleWSResults(udaCall.arrayBuffer);
return handleScratchpadTableRes(results);
Expand Down
3 changes: 3 additions & 0 deletions src/models/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* specific language governing permissions and limitations under the License.
*/

import { StructuredTextResults } from "./queryResult";

export type GetDataError = string | { buffer: ArrayBuffer };

export type GetDataObjectPayload = {
Expand All @@ -22,6 +24,7 @@ export type GetDataObjectPayload = {
columns: string[];
rows: any;
};
results?: StructuredTextResults;
arrayBuffer?: ArrayBuffer;
};

Expand Down
5 changes: 4 additions & 1 deletion src/utils/resultsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export function convertToGrid(
if (
(!isInsights && !isPython) ||
/* TODO: Workaround for Python structuredText bug */
(!isPython && connVersion && isBaseVersionGreaterOrEqual(connVersion, 1.12))
(!isPython &&
connVersion &&
isBaseVersionGreaterOrEqual(connVersion, 1.12)) ||
results.columns
) {
rowData = updatedExtractRowData(results);
columnDefs = updatedExtractColumnDefs(results);
Expand Down
Loading