Skip to content

Commit 7713f53

Browse files
committed
Fix how values are converted to native numbers in result summary
1 parent 9d96071 commit 7713f53

File tree

3 files changed

+79
-27
lines changed

3 files changed

+79
-27
lines changed

src/v1/internal/bolt-protocol-v3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import RequestMessage from './request-message'
2121

2222
export default class BoltProtocol extends BoltProtocolV2 {
2323
transformMetadata (metadata) {
24-
if (metadata.t_first) {
24+
if ('t_first' in metadata) {
2525
// Bolt V3 uses shorter key 't_first' to represent 'result_available_after'
2626
// adjust the key to be the same as in Bolt V1 so that ResultSummary can retrieve the value
2727
metadata.result_available_after = metadata.t_first
2828
delete metadata.t_first
2929
}
30-
if (metadata.t_last) {
30+
if ('t_last' in metadata) {
3131
// Bolt V3 uses shorter key 't_last' to represent 'result_consumed_after'
3232
// adjust the key to be the same as in Bolt V1 so that ResultSummary can retrieve the value
3333
metadata.result_consumed_after = metadata.t_last

src/v1/result-summary.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ class ProfiledPlan {
167167
this.operatorType = profile.operatorType
168168
this.identifiers = profile.identifiers
169169
this.arguments = profile.args
170-
this.dbHits = profile.args.DbHits.toInt()
171-
this.rows = profile.args.Rows.toInt()
170+
this.dbHits = intValue(profile.args.DbHits)
171+
this.rows = intValue(profile.args.Rows)
172172
this.children = profile.children
173173
? profile.children.map(child => new ProfiledPlan(child))
174174
: []
@@ -201,11 +201,9 @@ class StatementStatistics {
201201
}
202202
Object.keys(statistics).forEach(index => {
203203
// To camelCase
204-
this._stats[index.replace(/(-\w)/g, m => m[1].toUpperCase())] = isInt(
204+
this._stats[index.replace(/(-\w)/g, m => m[1].toUpperCase())] = intValue(
205205
statistics[index]
206206
)
207-
? statistics[index].toInt()
208-
: statistics[index]
209207
})
210208
}
211209

@@ -322,9 +320,9 @@ class Notification {
322320
return {}
323321
}
324322
return {
325-
offset: pos.offset.toInt(),
326-
line: pos.line.toInt(),
327-
column: pos.column.toInt()
323+
offset: intValue(pos.offset),
324+
line: intValue(pos.line),
325+
column: intValue(pos.column)
328326
}
329327
}
330328
}
@@ -347,6 +345,10 @@ class ServerInfo {
347345
}
348346
}
349347

348+
function intValue (value) {
349+
return isInt(value) ? value.toInt() : value
350+
}
351+
350352
const statementType = {
351353
READ_ONLY: 'r',
352354
READ_WRITE: 'rw',

test/v1/summary.test.js

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,71 @@ import neo4j from '../../src/v1'
2121
import sharedNeo4j from '../internal/shared-neo4j'
2222

2323
describe('result summary', () => {
24-
let driver, session
24+
describe('default driver', () => {
25+
let driver, session
2526

26-
beforeEach(done => {
27-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
28-
session = driver.session()
27+
beforeEach(done => {
28+
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
29+
session = driver.session()
2930

30-
session.run('MATCH (n) DETACH DELETE n').then(done)
31+
session.run('MATCH (n) DETACH DELETE n').then(done)
32+
})
33+
34+
afterEach(() => {
35+
driver.close()
36+
})
37+
38+
it('should get result summary', done => {
39+
verifySummary(session, done)
40+
})
41+
42+
it('should get plan from summary', done => {
43+
verifyPlan(session, done)
44+
})
45+
46+
it('should get profile from summary', done => {
47+
verifyProfile(session, done)
48+
})
49+
50+
it('should get notifications from summary', done => {
51+
verifyNotifications(session, 'EXPLAIN MATCH (n), (m) RETURN n, m', done)
52+
})
3153
})
3254

33-
afterEach(() => {
34-
driver.close()
55+
describe('driver with lossless integers disabled', () => {
56+
let driver, session
57+
58+
beforeEach(done => {
59+
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken, {
60+
disableLosslessIntegers: true
61+
})
62+
session = driver.session()
63+
64+
session.run('MATCH (n) DETACH DELETE n').then(done)
65+
})
66+
67+
afterEach(() => {
68+
driver.close()
69+
})
70+
71+
it('should get result summary', done => {
72+
verifySummary(session, done)
73+
})
74+
75+
it('should get plan from summary', done => {
76+
verifyPlan(session, done)
77+
})
78+
79+
it('should get profile from summary', done => {
80+
verifyProfile(session, done)
81+
})
82+
83+
it('should get notifications from summary', done => {
84+
verifyNotifications(session, 'EXPLAIN MATCH (n), (m) RETURN n, m', done)
85+
})
3586
})
3687

37-
it('should get result summary', done => {
38-
// When & Then
88+
function verifySummary (session, done) {
3989
session.run("CREATE (p:Person { Name: 'Test'})").then(result => {
4090
let summary = result.summary
4191

@@ -63,9 +113,9 @@ describe('result summary', () => {
63113
expect(counters.constraintsRemoved()).toBe(0)
64114
done()
65115
})
66-
})
116+
}
67117

68-
it('should get plan from summary', done => {
118+
function verifyPlan (session, done) {
69119
session.run('EXPLAIN MATCH (n) RETURN 1').then(result => {
70120
let summary = result.summary
71121
expect(summary.plan).toBeDefined()
@@ -78,9 +128,9 @@ describe('result summary', () => {
78128
expect(plan.operatorType).toBeDefined()
79129
done()
80130
})
81-
})
131+
}
82132

83-
it('should get profile from summary', done => {
133+
function verifyProfile (session, done) {
84134
session.run('PROFILE RETURN 1').then(result => {
85135
let summary = result.summary
86136
expect(summary.plan).toBeDefined()
@@ -96,10 +146,10 @@ describe('result summary', () => {
96146

97147
done()
98148
})
99-
})
149+
}
100150

101-
it('should get notifications from summary', done => {
102-
session.run('EXPLAIN MATCH (n), (m) RETURN n, m').then(result => {
151+
function verifyNotifications (session, statement, done) {
152+
session.run(statement).then(result => {
103153
let summary = result.summary
104154
expect(summary.notifications).toBeDefined()
105155
expect(summary.notifications.length).toBe(1)
@@ -113,7 +163,7 @@ describe('result summary', () => {
113163

114164
done()
115165
})
116-
})
166+
}
117167

118168
function verifyProfileAndPlanAreEqual (profile, plan) {
119169
expect(profile.arguments).toBe(plan.arguments)

0 commit comments

Comments
 (0)