Skip to content

Commit

Permalink
Merge pull request #58 from lenchv/fix/#51-reading-values-on-undefined
Browse files Browse the repository at this point in the history
fix reading values on undefined
  • Loading branch information
lenchv authored Sep 25, 2023
2 parents fd86564 + 740e5e4 commit ae056fe
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 17 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

[0.2.0](https://github.com/lenchv/hive-driver/releases/tag/v0.3.0) 2023-09-25

- Upgraded kerberos library

- Added parameter "orientation" to fetch method in order to force using FETCH_NEXT as first operation after initialization schema

- Fixed issue when on pending state the error was thrown

- Fixed issue when in some cases colum was undefined when parsing JsonResult

[0.2.0](https://github.com/lenchv/hive-driver/releases/tag/v0.2.0) 2022-08-20

- Fixed an issue with zero-based column start (Spark Thrift Server, Kyuubi, for example)
Expand Down
4 changes: 2 additions & 2 deletions dist/result/JsonResult.js

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

2 changes: 1 addition & 1 deletion dist/result/JsonResult.js.map

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

4 changes: 2 additions & 2 deletions lib/result/JsonResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export default class JsonResult implements IOperationResult {
}

private getRows(columns: Array<Column>, descriptors: Array<ColumnDesc>): Array<any> {
const columnStartPosition = Math.min(...descriptors.map(d => d.position));
const columnStartPosition = Math.max(Math.min(...descriptors.map(d => d.position)), 0);
return descriptors.reduce((rows, descriptor) => {
return this.getSchemaValues(
descriptor,
columns[descriptor.position - columnStartPosition]
columns[descriptor.position - columnStartPosition] || {}
).reduce((result, value, i) => {
if (!result[i]) {
result[i] = {};
Expand Down
20 changes: 9 additions & 11 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hive-driver",
"version": "0.2.0",
"version": "0.3.0",
"description": "Driver for connection to Apache Hive via Thrift API.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/result/JsonResult.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,57 @@ describe('JsonResult', () => {
"month_interval": null,
}]);
});

it('should check column that starts from 0', () => {
const schema = {
columns: [
getColumnSchema('table.str_0', TCLIService_types.TTypeId.STRING_TYPE, 0),
getColumnSchema('table.str', TCLIService_types.TTypeId.STRING_TYPE, 1),
]
};
const data = [
{
columns: [{
stringVal: { values: ['a0', 'b0'] }
}, {
stringVal: { values: ['a', 'b'] }
}]
}
];

const result = new JsonResult(TCLIService_types);
result.setOperation({
getSchema: () => schema,
getData: () => data,
});

expect(result.getValue()).to.be.deep.eq([{
"str":"a",
"str_0":"a0",
}, {
"str":"b",
"str_0":"b0",
}]);
});

it('should not fail if there is no column by descriptor', () => {
const schema = {
columns: [
getColumnSchema('table.str', TCLIService_types.TTypeId.STRING_TYPE, 0),
]
};
const data = [
{
columns: []
}
];

const result = new JsonResult(TCLIService_types);
result.setOperation({
getSchema: () => schema,
getData: () => data,
});

expect(result.getValue()).to.be.deep.eq([]);
});
});

0 comments on commit ae056fe

Please sign in to comment.