Skip to content

Commit cc2cb62

Browse files
[PECO-446] Use original column names when parsing fetch response (#88)
Signed-off-by: Levko Kravets <levko.ne@gmail.com> Signed-off-by: Levko Kravets <levko.ne@gmail.com>
1 parent 37c04de commit cc2cb62

File tree

3 files changed

+70
-66
lines changed

3 files changed

+70
-66
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Release History
22

3-
## 1.0.0 (Unreleased)
3+
## 1.x (Unreleased)
4+
5+
- Fix(databricks/databricks-sql-nodejs#84): now library will not attempt to parse column names and
6+
will use ones provided by server
7+
8+
## 1.0.0
49

510
- `DBSQLClient.openSession` now takes a limited set of options (`OpenSessionRequest` instead of Thrift's `TOpenSessionReq`)
611
- `DBSQLClient.openSession` now uses the latest protocol version by default

lib/result/JsonResult.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export default class JsonResult implements IOperationResult {
5050
result[i] = {};
5151
}
5252

53-
const name = this.getColumnName(descriptor);
53+
const { columnName } = descriptor;
5454

55-
result[i][name] = value;
55+
result[i][columnName] = value;
5656

5757
return result;
5858
}, rows),
@@ -76,12 +76,6 @@ export default class JsonResult implements IOperationResult {
7676
});
7777
}
7878

79-
private getColumnName(column: TColumnDesc): string {
80-
const name = column.columnName || '';
81-
82-
return name.split('.').pop() || '';
83-
}
84-
8579
private convertData(typeDescriptor: TPrimitiveTypeEntry | undefined, value: ColumnType): any {
8680
if (!typeDescriptor) {
8781
return value;

tests/unit/result/JsonResult.test.js

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -105,40 +105,40 @@ describe('JsonResult', () => {
105105

106106
expect(result.getValue()).to.be.deep.eq([
107107
{
108-
str: 'a',
109-
int64: 282578800148737,
110-
bin: Buffer.from([1]),
111-
bool: true,
112-
char: 'c',
113-
dbl: 1.2,
114-
flt: 2.2,
115-
int: 1,
116-
small_int: 3,
117-
tiny_int: 5,
118-
varch: 'e',
119-
dec: 2.1,
120-
ts: '2020-01-17 00:17:13.0',
121-
date: '2020-01-17',
122-
day_interval: '1 00:00:00.000000000',
123-
month_interval: '0-1',
108+
'table.str': 'a',
109+
'table.int64': 282578800148737,
110+
'table.bin': Buffer.from([1]),
111+
'table.bool': true,
112+
'table.char': 'c',
113+
'table.dbl': 1.2,
114+
'table.flt': 2.2,
115+
'table.int': 1,
116+
'table.small_int': 3,
117+
'table.tiny_int': 5,
118+
'table.varch': 'e',
119+
'table.dec': 2.1,
120+
'table.ts': '2020-01-17 00:17:13.0',
121+
'table.date': '2020-01-17',
122+
'table.day_interval': '1 00:00:00.000000000',
123+
'table.month_interval': '0-1',
124124
},
125125
{
126-
str: 'b',
127-
int64: 565157600297474,
128-
bin: Buffer.from([2]),
129-
bool: false,
130-
char: 'd',
131-
dbl: 1.3,
132-
flt: 2.3,
133-
int: 2,
134-
small_int: 4,
135-
tiny_int: 6,
136-
varch: 'f',
137-
dec: 2.2,
138-
ts: '2020-01-17 00:17:13.0',
139-
date: '2020-01-17',
140-
day_interval: '1 00:00:00.000000000',
141-
month_interval: '0-1',
126+
'table.str': 'b',
127+
'table.int64': 565157600297474,
128+
'table.bin': Buffer.from([2]),
129+
'table.bool': false,
130+
'table.char': 'd',
131+
'table.dbl': 1.3,
132+
'table.flt': 2.3,
133+
'table.int': 2,
134+
'table.small_int': 4,
135+
'table.tiny_int': 6,
136+
'table.varch': 'f',
137+
'table.dec': 2.2,
138+
'table.ts': '2020-01-17 00:17:13.0',
139+
'table.date': '2020-01-17',
140+
'table.day_interval': '1 00:00:00.000000000',
141+
'table.month_interval': '0-1',
142142
},
143143
]);
144144
});
@@ -175,16 +175,16 @@ describe('JsonResult', () => {
175175

176176
expect(result.getValue()).to.be.deep.eq([
177177
{
178-
array: ['a', 'b'],
179-
map: { key: 12 },
180-
struct: { name: 'Jon', surname: 'Doe' },
181-
union: '{0:12}',
178+
'table.array': ['a', 'b'],
179+
'table.map': { key: 12 },
180+
'table.struct': { name: 'Jon', surname: 'Doe' },
181+
'table.union': '{0:12}',
182182
},
183183
{
184-
array: ['c', 'd'],
185-
map: { key: 13 },
186-
struct: { name: 'Jane', surname: 'Doe' },
187-
union: '{1:"foo"}',
184+
'table.array': ['c', 'd'],
185+
'table.map': { key: 13 },
186+
'table.struct': { name: 'Jane', surname: 'Doe' },
187+
'table.union': '{1:"foo"}',
188188
},
189189
]);
190190
});
@@ -212,7 +212,12 @@ describe('JsonResult', () => {
212212

213213
const result = new JsonResult(schema, data);
214214

215-
expect(result.getValue()).to.be.deep.eq([{ id: '0' }, { id: '1' }, { id: '2' }, { id: '3' }]);
215+
expect(result.getValue()).to.be.deep.eq([
216+
{ 'table.id': '0' },
217+
{ 'table.id': '1' },
218+
{ 'table.id': '2' },
219+
{ 'table.id': '3' },
220+
]);
216221
});
217222

218223
it('should detect nulls', () => {
@@ -332,22 +337,22 @@ describe('JsonResult', () => {
332337

333338
expect(result.getValue()).to.be.deep.eq([
334339
{
335-
str: null,
336-
int64: null,
337-
bin: null,
338-
bool: null,
339-
char: null,
340-
dbl: null,
341-
flt: null,
342-
int: null,
343-
small_int: null,
344-
tiny_int: null,
345-
varch: null,
346-
dec: null,
347-
ts: null,
348-
date: null,
349-
day_interval: null,
350-
month_interval: null,
340+
'table.str': null,
341+
'table.int64': null,
342+
'table.bin': null,
343+
'table.bool': null,
344+
'table.char': null,
345+
'table.dbl': null,
346+
'table.flt': null,
347+
'table.int': null,
348+
'table.small_int': null,
349+
'table.tiny_int': null,
350+
'table.varch': null,
351+
'table.dec': null,
352+
'table.ts': null,
353+
'table.date': null,
354+
'table.day_interval': null,
355+
'table.month_interval': null,
351356
},
352357
]);
353358
});

0 commit comments

Comments
 (0)