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

fix row.toString not respecting column ordering + test #5

Merged
merged 1 commit into from
Nov 28, 2018
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
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": "0.1.2",
"version": "0.1.4",
"description": "",
"main": "index.js",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion azure-kusto-data/source/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = class KustoClient {
"Content-Type": "application/json; charset=utf-8",
"Fed": "True",
"x-ms-client-version": `Kusto.Node.Client:${pkg.version}`,
"x-ms-client-request-id": `KPC.execute;${uuidv4()}`,
"x-ms-client-request-id": `KNC.execute;${uuidv4()}`,
};

const { timeout } = options || {};
Expand Down
6 changes: 3 additions & 3 deletions azure-kusto-data/source/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ValueParser = {

class KustoResultRow {
constructor(columns, row) {
this.columns = columns.sort((a, b) => a.ordianl - b.ordianl);
this.columns = columns.sort((a, b) => a.ordinal - b.ordinal);
this.raw = row;

for (let col of this.columns) {
Expand Down Expand Up @@ -56,11 +56,11 @@ class KustoResultRow {
module.exports.KustoResultRow = KustoResultRow;

class KustoResultColumn {
constructor(columnObj, ordianl) {
constructor(columnObj, ordinal) {
this.name = columnObj.ColumnName;
// TODO: should validate type? should coarse value to type?
this.type = columnObj.ColumnType || columnObj.DateType;
this.ordinal = ordianl;
this.ordinal = ordinal;
}
}

Expand Down
40 changes: 40 additions & 0 deletions azure-kusto-data/test/modelsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,46 @@ describe("KustoResultRow", function () {
assert.equal(actual.columns.length, inputColumns.length);
});

it("column ordinal affects order", function () {
const inputValues = [
"2016-06-06T15:35:00Z",
"foo",
101,
3.14,
false,
3493235670000
];

const reverseOrderColumns = rawColumns.slice().reverse();
const actual = new KustoResultRow(
reverseOrderColumns.map((c, i) => new KustoResultColumn(c, rawColumns.length - i - 1)),
inputValues
);

let asJson = actual.toJson();
let expectedValues = [
moment(inputValues[0]),
inputValues[1],
inputValues[2],
inputValues[3],
inputValues[4],
moment(inputValues[5]),
];

for (let index = 0; index < inputColumns.length; index++) {
let actual = asJson[inputColumns[index].name];
if (inputColumns[index].type === "timespan") {
assert.equal(Number(actual), expectedValues[index]);
}
else if (typeof(actual) == "object") {
assert.equal(actual.toString(), expectedValues[index].toString());
} else {
assert.equal(actual, expectedValues[index]);
}
}

});

it("mismatching data - less data than columns", function () {
const inputValues = [
"2016-06-06T15:35:00Z",
Expand Down
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": "0.1.2",
"version": "0.1.4",
"description": "",
"main": "./index.js",
"engines": {
Expand Down