Skip to content

Commit

Permalink
fix row.toString not respecting column ordering + test (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Dubovski authored Nov 28, 2018
1 parent 6310617 commit ba13777
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 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": "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

0 comments on commit ba13777

Please sign in to comment.