Skip to content

Bolt 6.0 and Vector Type #1293

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

Draft
wants to merge 13 commits into
base: 6.x
Choose a base branch
from
Draft
513 changes: 18 additions & 495 deletions README.md

Large diffs are not rendered by default.

505 changes: 505 additions & 0 deletions original_README.md

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions packages/bolt-connection/src/bolt/bolt-protocol-v6x0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import BoltProtocolV5x8 from './bolt-protocol-v5x8'

import transformersFactories from './bolt-protocol-v6x0.transformer'
import Transformer from './transformer'

import { internal } from 'neo4j-driver-core'

const {
constants: { BOLT_PROTOCOL_V6_0 }
} = internal

export default class BoltProtocol extends BoltProtocolV5x8 {
get version () {
return BOLT_PROTOCOL_V6_0
}

get transformer () {
if (this._transformer === undefined) {
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
}
return this._transformer
}
}
130 changes: 130 additions & 0 deletions packages/bolt-connection/src/bolt/bolt-protocol-v6x0.transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import v5x8 from './bolt-protocol-v5x8.transformer'
import { TypeTransformer } from './transformer'
import { structure } from '../packstream'
import { Vector, newError } from 'neo4j-driver-core'
const VECTOR = 0x56
const FLOAT_32 = 0xc6
const FLOAT_64 = 0xc1
const INT_8 = 0xc8
const INT_16 = 0xc9
const INT_32 = 0xca
const INT_64 = 0xcb

function createVectorTransformer () {
return new TypeTransformer({
signature: VECTOR,
isTypeInstance: object => object instanceof Vector,
toStructure: vector => {
const dataview = new DataView(new ArrayBuffer(vector.typedArray.byteLength))
let set
let typeMarker
switch (vector.type) {
case 'INT8':
typeMarker = Uint8Array.from([INT_8])
set = dataview.setUint8.bind(dataview)
break
case 'INT16':
typeMarker = Uint8Array.from([INT_16])
set = dataview.setUint16.bind(dataview)
break
case 'INT32':
typeMarker = Uint8Array.from([INT_32])
set = dataview.setUint32.bind(dataview)
break
case 'INT64':
typeMarker = Uint8Array.from([INT_64])
set = dataview.setBigInt64.bind(dataview)
break
case 'FLOAT32':
typeMarker = Uint8Array.from([FLOAT_32])
set = dataview.setFloat32.bind(dataview)
break
case 'FLOAT64':
typeMarker = Uint8Array.from([FLOAT_64])
set = dataview.setFloat64.bind(dataview)
break
default:
throw newError(`Vector is of unsupported type ${vector.type}`)
}
for (let i = 0; i < vector.typedArray.length; i++) {
set(i * vector.typedArray.BYTES_PER_ELEMENT, vector.typedArray[i])
}
const struct = new structure.Structure(VECTOR, [typeMarker, new Int8Array(dataview.buffer)])
return struct
},
fromStructure: structure => {
const isLittleEndian = checkLittleEndian()
const typeMarker = structure.fields[0][0]
const arrayBuffer = structure.fields[1]
const setview = new DataView(new ArrayBuffer(arrayBuffer.byteLength))
const getview = new DataView(arrayBuffer.buffer)
let get
let set
let resultArray
switch (typeMarker) {
case INT_8:
return new Vector(Int8Array.from(arrayBuffer))
case INT_16:
resultArray = new Int16Array(setview.buffer)
get = getview.getInt16.bind(getview)
set = setview.setInt16.bind(setview)
break
case INT_32:
resultArray = new Int32Array(setview.buffer)
get = getview.getInt32.bind(getview)
set = setview.setInt32.bind(setview)
break
case INT_64:
resultArray = new BigInt64Array(setview.buffer)
get = getview.getBigInt64.bind(getview)
set = setview.setBigInt64.bind(setview)
break
case FLOAT_32:
resultArray = new Float32Array(setview.buffer)
get = getview.getFloat32.bind(getview)
set = setview.setFloat32.bind(setview)
break
case FLOAT_64:
resultArray = new Float64Array(setview.buffer)
get = getview.getFloat64.bind(getview)
set = setview.setFloat64.bind(setview)
break
default:
throw newError(`Recieved Vector of unknown type ${typeMarker}`)
}
for (let i = 0; i < arrayBuffer.length; i += resultArray.BYTES_PER_ELEMENT) {
set(i, get(i), isLittleEndian)
}
return new Vector(resultArray)
}
})
}

function checkLittleEndian () {
const dataview = new DataView(new ArrayBuffer(2))
dataview.setInt16(0, 1000, true)
const typeArray = new Int16Array(dataview.buffer)
return typeArray[0] === 1000
}

export default {
...v5x8,
createVectorTransformer
}
9 changes: 9 additions & 0 deletions packages/bolt-connection/src/bolt/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import BoltProtocolV5x5 from './bolt-protocol-v5x5'
import BoltProtocolV5x6 from './bolt-protocol-v5x6'
import BoltProtocolV5x7 from './bolt-protocol-v5x7'
import BoltProtocolV5x8 from './bolt-protocol-v5x8'
import BoltProtocolV6x0 from './bolt-protocol-v6x0'
// eslint-disable-next-line no-unused-vars
import { Chunker, Dechunker } from '../channel'
import ResponseHandler from './response-handler'
Expand Down Expand Up @@ -266,6 +267,14 @@ function createProtocol (
log,
onProtocolError,
serversideRouting)
case 6.0:
return new BoltProtocolV6x0(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
default:
throw newError('Unknown Bolt protocol version: ' + version)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bolt-connection/src/bolt/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { alloc } from '../channel'
import { newError } from 'neo4j-driver-core'

const BOLT_MAGIC_PREAMBLE = 0x6060b017
const AVAILABLE_BOLT_PROTOCOLS = ['5.8', '5.7', '5.6', '5.4', '5.3', '5.2', '5.1', '5.0', '4.4', '4.3', '4.2', '3.0'] // bolt protocols the client will accept, ordered by preference
const AVAILABLE_BOLT_PROTOCOLS = ['6.0', '5.8', '5.7', '5.6', '5.4', '5.3', '5.2', '5.1', '5.0', '4.4', '4.3', '4.2', '3.0'] // bolt protocols the client will accept, ordered by preference
const DESIRED_CAPABILITES = 0

function version (major, minor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:"b"})"`;

exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`;

exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:"c"}]->(f)"`;

exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:"c"}]->"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 5"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 5"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 9"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 3"`;

exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 5"`;
Loading