Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KXI-52581 add limit to DS run #431

Merged
merged 18 commits into from
Oct 1, 2024
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
9 changes: 9 additions & 0 deletions src/commands/dataSourceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ export function getApiBody(
if (optional.temporal) {
apiBody.temporality = api.temporality;
}
if (optional.rowLimit && api.rowCountLimit) {
if (api.isRowLimitLast) {
apiBody.limit = -parseInt(api.rowCountLimit);
} else {
apiBody.limit = parseInt(api.rowCountLimit);
}
}

const labels = optional.labels.filter((label) => label.active);

Expand All @@ -291,6 +298,8 @@ export function getApiBody(
{},
...labels.map((label) => ({ [label.key]: label.value })),
);
} else {
apiBody.labels = {};
}

const filters = optional.filters
Expand Down
1 change: 1 addition & 0 deletions src/models/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export type getDataBodyPayload = {
temporality?: string;
slice?: string[];
sortCols?: string[];
limit?: number;
};
6 changes: 6 additions & 0 deletions src/models/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum DataSourceTypes {
SQL = "SQL",
}

//TODO: make the optional params required in 1.10 or superior
export interface DataSourceFiles {
name?: string;
originalName?: string;
Expand All @@ -30,6 +31,8 @@ export interface DataSourceFiles {
endTS: string;
fill: string;
temporality: string;
rowCountLimit?: string;
isRowLimitLast?: boolean;
filter: string[];
groupBy: string[];
agg: string[];
Expand All @@ -44,6 +47,7 @@ export interface DataSourceFiles {
sorts: Sort[];
aggs: Agg[];
groups: Group[];
rowLimit?: boolean;
};
};
qsql: {
Expand All @@ -68,6 +72,8 @@ export function createDefaultDataSourceFile(): DataSourceFiles {
endTS: "",
fill: "zero",
temporality: "snapshot",
rowCountLimit: "100000",
isRowLimitLast: true,
filter: [],
groupBy: [],
agg: [],
Expand Down
1 change: 1 addition & 0 deletions src/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DataSourceMessage2 {
command: DataSourceCommand;
servers: string[];
selectedServer: string;
selectedServerVersion: number;
isInsights: boolean;
insightsMeta: MetaObjectPayload;
dataSourceFile: DataSourceFiles;
Expand Down
8 changes: 8 additions & 0 deletions src/services/connectionManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ export class ConnectionManagementService {
}
}

public async retrieveInsightsConnVersion(connLabel: string): Promise<number> {
const connection = this.retrieveConnectedConnection(connLabel);
if (!connection || !(connection instanceof InsightsConnection)) {
return 0;
}
return connection.insightsVersion ? connection.insightsVersion : 0;
}

public exportConnection(connLabel?: string, includeAuth?: boolean): string {
const exportedContent: ExportedConnections = {
connections: {
Expand Down
5 changes: 4 additions & 1 deletion src/services/dataSourceEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,19 @@ export class DataSourceEditorProvider implements CustomTextEditorProvider {
webview.options = { enableScripts: true };
webview.html = this.getWebviewContent(webview);
let changing = 0;
const connMngService = new ConnectionManagementService();

const updateWebview = async () => {
if (changing === 0) {
const selectedServer = getServerForUri(document.uri) || "";
const selectedServerVersion =
await connMngService.retrieveInsightsConnVersion(selectedServer);
await getConnectionForServer(selectedServer);
webview.postMessage(<DataSourceMessage2>{
command: DataSourceCommand.Update,
selectedServer,
servers: getInsightsServers(),
selectedServerVersion,
dataSourceFile: this.getDocumentAsJson(document),
insightsMeta: await this.getMeta(selectedServer),
isInsights: true,
Expand Down Expand Up @@ -173,7 +177,6 @@ export class DataSourceEditorProvider implements CustomTextEditorProvider {
);
break;
case DataSourceCommand.Refresh:
const connMngService = new ConnectionManagementService();
const selectedServer = getServerForUri(document.uri) || "";
if (!connMngService.isConnected(selectedServer)) {
offerConnectAction(selectedServer);
Expand Down
21 changes: 19 additions & 2 deletions src/services/queryHistoryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,25 @@ export class QueryHistoryTreeItem extends TreeItem {
"- File: " + this.details.executorName + " \n",
);
}
tooltipMd.appendMarkdown("- Query: \n");
tooltipMd.appendCodeblock(this.details.query, codeType);
tooltipMd.appendMarkdown("- Query: ");
let queryText = this.details.query;

if (typeof queryText === "string") {
const lines = queryText.split("\n");
if (lines.length > 1) {
queryText =
lines[0].slice(0, 77) +
(lines[0].length > 77 ? "... " : "") +
"\n" +
lines[1].slice(0, 77) +
(lines[1].length > 77 ? "... " : "");
} else {
queryText =
lines[0].slice(0, 77) + (lines[0].length > 77 ? "... " : "");
}
}

tooltipMd.appendCodeblock(queryText, codeType);
} else {
tooltipMd.appendMarkdown(
"- Data Source: **" + this.details.executorName + "** \n",
Expand Down
94 changes: 92 additions & 2 deletions src/webview/components/kdbDataSourceView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class KdbDataSourceView extends LitElement {
selectedApi = "";
selectedTable = "";
startTS = "";
rowLimitCount = "100000";
isRowLimitLast = true;
rowLimit = false;
selectedServerVersion = 0;
endTS = "";
fill = "";
filled = false;
Expand Down Expand Up @@ -97,6 +101,9 @@ export class KdbDataSourceView extends LitElement {
if (msg.command === DataSourceCommand.Update) {
this.servers = msg.servers;
this.selectedServer = msg.selectedServer;
this.selectedServerVersion = msg.selectedServerVersion
? msg.selectedServerVersion
: 0;
this.isInsights = msg.isInsights;
this.isMetaLoaded = !!msg.insightsMeta.dap;
this.insightsMeta = msg.insightsMeta;
Expand All @@ -107,6 +114,12 @@ export class KdbDataSourceView extends LitElement {
this.startTS = ds.dataSource.api.startTS;
this.endTS = ds.dataSource.api.endTS;
this.fill = ds.dataSource.api.fill;
this.rowLimitCount = ds.dataSource.api.rowCountLimit
? ds.dataSource.api.rowCountLimit
: "100000";
this.isRowLimitLast = ds.dataSource.api.isRowLimitLast
? ds.dataSource.api.isRowLimitLast
: true;
this.temporality = ds.dataSource.api.temporality;
this.qsqlTarget = ds.dataSource.qsql.selectedTarget;
this.qsql = ds.dataSource.qsql.query;
Expand All @@ -120,6 +133,7 @@ export class KdbDataSourceView extends LitElement {
this.sorts = optional.sorts;
this.aggs = optional.aggs;
this.groups = optional.groups;
this.rowLimit = optional.rowLimit ? optional.rowLimit : false;
}
this.requestUpdate();
}
Expand All @@ -137,6 +151,8 @@ export class KdbDataSourceView extends LitElement {
startTS: this.startTS,
endTS: this.endTS,
fill: this.fill,
rowCountLimit: this.rowLimitCount,
isRowLimitLast: this.isRowLimitLast,
temporality: this.temporality,
filter: [],
groupBy: [],
Expand All @@ -152,6 +168,7 @@ export class KdbDataSourceView extends LitElement {
sorts: this.sorts,
aggs: this.aggs,
groups: this.groups,
rowLimit: this.rowLimit,
},
},
qsql: {
Expand Down Expand Up @@ -222,6 +239,78 @@ export class KdbDataSourceView extends LitElement {
});
}

renderRowCountOptions() {
const compareVersions = (v1: string, v2: string) =>
v1
.split(".")
.map(Number)
.reduce((acc, num, i) => acc || num - Number(v2.split(".")[i] || 0), 0);

if (compareVersions(this.selectedServerVersion.toString(), "1.11") >= 0) {
return html`
<div class="row align-bottom">
<vscode-checkbox
.checked="${this.rowLimit}"
@change="${(event: Event) => {
/* istanbul ignore next */
this.rowLimit = (event.target as HTMLInputElement).checked;
this.requestChange();
}}"></vscode-checkbox>
<div class="dropdown-container">
<label for="row-count">Row Limit</label>
<vscode-text-field
type="number"
class="text-field input-number"
.value="${live(this.rowLimitCount)}"
@input="${(event: Event) => {
/* istanbul ignore next */
this.rowLimitCount = (event.target as HTMLInputElement).value;
this.requestChange();
}}">
</vscode-text-field>
</div>

<vscode-radio-group>
<div class="dropdown-container">
<vscode-radio
name="row-count"
value="first"
.checked="${!this.isRowLimitLast}"
@change="${(event: Event) => {
/* istanbul ignore next */
if ((event.target as HTMLInputElement).checked) {
this.isRowLimitLast = false;
this.requestChange();
}
}}"
>First</vscode-radio
>
</div>
<div class="dropdown-container">
<vscode-radio
name="row-count"
value="last"
.checked="${this.isRowLimitLast}"
@change="${(event: Event) => {
/* istanbul ignore next */
if ((event.target as HTMLInputElement).checked) {
this.isRowLimitLast = true;
this.requestChange();
}
}}"
>Last</vscode-radio
>
</div>
</vscode-radio-group>
</div>
`;
} else {
this.rowLimit = false;
this.rowLimitCount = "100000";
this.isRowLimitLast = true;
}
}

renderApiOptions() {
if (this.isInsights && this.isMetaLoaded) {
return this.insightsMeta.api
Expand Down Expand Up @@ -781,7 +870,8 @@ export class KdbDataSourceView extends LitElement {
).value;
this.requestChange();
}}"
>Start Time</vscode-text-field
>Start Time
${this.selectedServerVersion}</vscode-text-field
>

<vscode-text-field
Expand All @@ -795,7 +885,7 @@ export class KdbDataSourceView extends LitElement {
>End Time</vscode-text-field
>
</div>

${this.renderRowCountOptions()}
<div class="row align-bottom">
<vscode-checkbox
.checked="${this.filled}"
Expand Down
11 changes: 11 additions & 0 deletions test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ describe("dataSourceCommand2", () => {
api.startTS = "2022-01-01T00:00:00Z";
api.endTS = "2022-01-02T00:00:00Z";
api.fill = "zero";
api.rowCountLimit = "20";
api.isRowLimitLast = true;
api.temporality = "snapshot";
api.filter = ["col1=val1;col2=val2", "col3=val3"];
api.groupBy = ["col1", "col2"];
Expand All @@ -228,6 +230,7 @@ describe("dataSourceCommand2", () => {
api.optional = {
filled: true,
temporal: true,
rowLimit: true,
filters: [],
sorts: [],
groups: [],
Expand All @@ -241,6 +244,8 @@ describe("dataSourceCommand2", () => {
startTS: "2022-01-01T00:00:00.000000000",
endTS: "2022-01-02T00:00:00.000000000",
fill: "zero",
limit: -20,
labels: {},
temporality: "snapshot",
});
});
Expand All @@ -251,6 +256,8 @@ describe("dataSourceCommand2", () => {
api.startTS = "2022-01-01T00:00:00Z";
api.endTS = "2022-01-02T00:00:00Z";
api.fill = "zero";
api.rowCountLimit = "20";
api.isRowLimitLast = false;
api.temporality = "slice";
api.filter = [];
api.groupBy = [];
Expand All @@ -260,6 +267,7 @@ describe("dataSourceCommand2", () => {
api.labels = [];
api.table = "myTable";
api.optional = {
rowLimit: true,
filled: false,
temporal: true,
filters: [],
Expand All @@ -279,6 +287,8 @@ describe("dataSourceCommand2", () => {
api.endTS = "2022-01-02T00:00:00Z";
api.fill = "zero";
api.temporality = "snapshot";
api.rowCountLimit = "20";
api.isRowLimitLast = false;
api.filter = [];
api.groupBy = [];
api.agg = [];
Expand All @@ -287,6 +297,7 @@ describe("dataSourceCommand2", () => {
api.labels = [];
api.table = "myTable";
api.optional = {
rowLimit: false,
filled: true,
temporal: true,
filters: [
Expand Down
Loading