Skip to content

Commit

Permalink
Parser (#22)
Browse files Browse the repository at this point in the history
* implement NMap and NSet data type for parser

* use array push instead array concat when traverse each rows

* test cases for set and map

---------

Co-authored-by: re0marb1e <[email protected]>
  • Loading branch information
re0marb1e and re0marb1e authored Apr 12, 2023
1 parent 2b04b5e commit 0f14997
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ Not implemented data type for auto parser

| Data Type | property name in nebula response |
| --------- | -------------------------------- |
| NMap | mVal |
| NSet | uVal |
| DataSet | gVal |
| Geography | ggVal |
| Duration | duVal |

## Released Versions in npmjs.com

| NodeJS Client Version | Nebula Graph Version |
| --------------------- | --------------------- |
| [2.6.2](https://www.npmjs.com/package/@nebula-contrib/nebula-nodejs/v/2.6.2) | 2.6.x |
| [3.0.1](https://www.npmjs.com/package/@nebula-contrib/nebula-nodejs/v/3.0.1) | 3.0.x 3.1.x |
| [3.0.1](https://www.npmjs.com/package/@nebula-contrib/nebula-nodejs/v/3.0.1) | 3.0.x 3.1.x |
2 changes: 1 addition & 1 deletion src/nebula/parser/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/

export default (obj: any, propName: string): any => {
return obj[propName]
return obj[propName].kvs || {}
}
2 changes: 1 addition & 1 deletion src/nebula/parser/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/

export default (obj: any, propName: string): any => {
return obj[propName]
return obj[propName].values || []
}
2 changes: 1 addition & 1 deletion src/nebula/parser/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const traverse = (obj: any): any => {

_.forEach(rows, row => {
_.forEach(columns, (c, i) => {
entity[c] = _.concat(entity[c], row.values[i])
entity[c].push(row.values[i])
})
})

Expand Down
6 changes: 2 additions & 4 deletions src/nebula/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { NebulaValue } from '../types'
import _ from 'lodash'

const NubulaValueTypeNames = [
const NebulaValueTypeNames = [
'nVal',
'bVal',
'iVal',
Expand All @@ -15,8 +15,6 @@ const NubulaValueTypeNames = [
'dVal',
'tVal',
'dtVal',
'mVal',
'uVal',
'gVal'
]

Expand All @@ -30,7 +28,7 @@ const isNebulaValue = (obj: any): boolean => {
}

const isNebulaValueTypeName = (propName: string): boolean => {
return _.includes(NubulaValueTypeNames, propName)
return _.includes(NebulaValueTypeNames, propName)
}

const isNebulaNListTypeName = (propName: string): boolean => {
Expand Down
52 changes: 49 additions & 3 deletions tests/nebula.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const commands = {
cmd1: 'get subgraph with prop 2 steps from "p001" yield vertices as nodes, edges as relationships',
cmd2: 'fetch prop on company "c001" yield properties(vertex) as node',
cmd3: 'go from "c001" over employee yield properties($^) as a, properties($$) as b, properties(edge) as p',
cmd4: 'find noloop path with prop from "p001" to "p002" over * yield path as p'
cmd4: 'find noloop path with prop from "p001" to "p002" over * yield path as p',
cmd5: 'RETURN list[1, 2, 3] AS a',
cmd6: 'UNWIND list[list[1, 2, 3], list[2, 3, 4]] as a RETURN a',
cmd7: 'RETURN set{1, 2, 3} AS a',
cmd8: 'RETURN map{a: LIST[1,2], b: SET{1,2,1}, c: "hee"} as a'
}

describe('nebula', () => {
Expand Down Expand Up @@ -66,9 +70,51 @@ describe('nebula', () => {
await client.close()
})

it('test-case-5-list', async () => {
const client = createClient(nebulaServer)

const response1 = await client.execute(commands.cmd5)

expect(response1.data?.a).deep.equal([[1, 2, 3]])

await client.close()
})

it('test-case-6-list', async () => {
const client = createClient(nebulaServer)

const response1 = await client.execute(commands.cmd6)

expect(response1.data?.a).deep.equal([[1, 2, 3], [2, 3, 4]])

await client.close()
})

it('test-case-7-set', async () => {
const client = createClient(nebulaServer)

const response1 = await client.execute(commands.cmd7)

expect(response1.data?.a?.length).to.equal(1)
expect(response1.data?.a[0]?.length).to.equal(3)

await client.close()
})

it('test-case-8-map', async () => {
const client = createClient(nebulaServer)

const response1 = await client.execute(commands.cmd8)

expect(response1.data?.a?.length).to.equal(1)
expect(response1.data?.a[0]?.a).to.deep.equal([1, 2])
expect(response1.data?.a[0]?.b?.length).to.equal(2)
expect(response1.data?.a[0]?.c).to.equal('hee')

await client.close()
})

after(async () => {
process.exit()
})
})


0 comments on commit 0f14997

Please sign in to comment.