Skip to content

Commit

Permalink
Add support for query V1 (#113)
Browse files Browse the repository at this point in the history
* Add support for V1 query

* add support query v1

* Delete client.js

* cr fix

* fix
  • Loading branch information
amshalev authored Feb 16, 2021
1 parent e53489e commit 803e4f5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion azure-kusto-data/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion azure-kusto-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-kusto-data",
"version": "2.1.3",
"version": "2.1.4",
"description": "Azure Data Explorer Query SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down
28 changes: 17 additions & 11 deletions azure-kusto-data/source/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ const CLIENT_SERVER_DELTA_IN_MILLISECS = moment.duration(0.5, "minutes").asMilli
const MGMT_PREFIX = ".";

enum ExecutionType {
Mgmt = 0,
Query = 1,
Ingest = 2
Mgmt = "mgmt",
Query = "query",
Ingest = "ingest",
QueryV1 = "queryv1",
}

export class KustoClient {
connectionString: ConnectionStringBuilder;
cluster: string;
endpoints: { mgmt: string; query: string; ingest: string; };
endpoints: { [key in ExecutionType] : string; };
aadHelper: AadHelper;
headers: { [name: string]: string };

constructor(kcsb: string | ConnectionStringBuilder) {
this.connectionString = typeof (kcsb) === "string" ? new ConnectionStringBuilder(kcsb) : kcsb;
this.cluster = (this.connectionString.dataSource as string);
this.endpoints = {
mgmt: `${this.cluster}/v1/rest/mgmt`,
query: `${this.cluster}/v2/rest/query`,
ingest: `${this.cluster}/v1/rest/ingest`,
[ExecutionType.Mgmt]: `${this.cluster}/v1/rest/mgmt`,
[ExecutionType.Query]: `${this.cluster}/v2/rest/query`,
[ExecutionType.Ingest]: `${this.cluster}/v1/rest/ingest`,
[ExecutionType.QueryV1]: `${this.cluster}/v1/rest/query`,
};
this.aadHelper = new AadHelper(this.connectionString);
this.headers = {
Expand All @@ -54,15 +56,19 @@ export class KustoClient {
}

async executeQuery(db: string, query: string, properties?: ClientRequestProperties) {
return this._execute(this.endpoints.query, ExecutionType.Query, db, query, null, properties);
return this._execute(this.endpoints[ExecutionType.Query], ExecutionType.Query, db, query, null, properties);
}

async executeQueryV1(db: string, query: string, properties?: ClientRequestProperties) {
return this._execute(this.endpoints[ExecutionType.QueryV1], ExecutionType.QueryV1, db, query, null, properties);
}

async executeMgmt(db: string, query: string, properties?: ClientRequestProperties) {
return this._execute(this.endpoints.mgmt, ExecutionType.Mgmt, db, query, null, properties);
return this._execute(this.endpoints[ExecutionType.Mgmt], ExecutionType.Mgmt, db, query, null, properties);
}

async executeStreamingIngest(db: string, table: string, stream: any, streamFormat: any, mappingName: string | null): Promise<KustoResponseDataSet> {
let endpoint = `${this.endpoints.ingest}/${db}/${table}?streamFormat=${streamFormat}`;
let endpoint = `${this.endpoints[ExecutionType.Ingest]}/${db}/${table}?streamFormat=${streamFormat}`;
if (mappingName != null) {
endpoint += `&mappingName=${mappingName}`;
}
Expand Down Expand Up @@ -174,7 +180,7 @@ export class KustoClient {
}
}

return executionType == ExecutionType.Query ? QUERY_TIMEOUT_IN_MILLISECS : COMMAND_TIMEOUT_IN_MILLISECS;
return (executionType == ExecutionType.Query || executionType == ExecutionType.QueryV1) ? QUERY_TIMEOUT_IN_MILLISECS : COMMAND_TIMEOUT_IN_MILLISECS;
}
}

Expand Down
27 changes: 21 additions & 6 deletions azure-kusto-data/test/clientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const v1Response = require("./data/response/v1");
// tslint:disable-next-line:no-var-requires variable-name
const v1_2Response = require("./data/response/v1_2");

const ExecutionType = Object.freeze({
Mgmt: 0,
Query: 1,
Ingest: 2
});
enum ExecutionType {
Mgmt = "mgmt",
Query = "query",
Ingest = "ingest",
QueryV1 = "queryv1",
}

describe("KustoClient", function () {
describe("#constructor", function () {
Expand Down Expand Up @@ -58,7 +59,7 @@ describe("KustoClient", function () {
const url = "https://cluster.kusto.windows.net";
const client = new KustoClient(url);

const response = client._parseResponse(v1_2Response, ExecutionType.Mgmt);
const response = client._parseResponse(v1_2Response, ExecutionType.QueryV1);
assert.equal((response as KustoResponseDataSetV1).version, "1.0");
});

Expand Down Expand Up @@ -181,5 +182,19 @@ describe("KustoClient", function () {

await client.execute("Database", "Table | count", clientRequestProps);
});

it("executeQueryV1", async function () {
const url = "https://cluster.kusto.windows.net";
const client = new KustoClient(url);

client.aadHelper._getAuthHeader = () => { return Promise.resolve("MockToken") };
client._doRequest = (endpoint, executionType, headers, payload, timeout, properties) => {
assert.equal(endpoint, `${url}/v1/rest/query`);
assert.equal(executionType, ExecutionType.QueryV1);
return Promise.resolve(new KustoResponseDataSetV2([]));
};

await client.executeQueryV1("Database", "Table | count");
});
});
});
2 changes: 1 addition & 1 deletion azure-kusto-ingest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion azure-kusto-ingest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-kusto-ingest",
"version": "2.1.3",
"version": "2.1.4",
"description": "Azure Data Explorer Ingestion SDK",
"main": "index.js",
"engines": {
Expand Down

0 comments on commit 803e4f5

Please sign in to comment.