Skip to content

Commit a73a1b1

Browse files
committed
Add Map technique comparisons
1 parent 69d4262 commit a73a1b1

File tree

9 files changed

+448
-8
lines changed

9 files changed

+448
-8
lines changed

hana/lib/deep-queries.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ async function onDeep(req, next) {
3131
}
3232

3333
const hasDeep = (q, target) => {
34-
if(q.INSERT && !q.INSERT.entries) return false
35-
if(q.UPSERT && !q.UPSERT.entries) return false
36-
for(const _ in target.compositions) return true
34+
if (q.INSERT && !q.INSERT.entries) return false
35+
if (q.UPSERT && !q.UPSERT.entries) return false
36+
for (const _ in target.compositions) return true
3737
return false
3838
}
3939

@@ -50,12 +50,15 @@ const getDeepQueries = async function (query, target) {
5050
const getEntries = (query) => {
5151
const cqn2sql = new this.class.CQN2SQL(this)
5252
cqn2sql.cqn = query
53+
const entries = query.INSERT
54+
? query.INSERT.entries
55+
: query.UPSERT.entries
56+
if (entries[0] instanceof Readable) {
57+
entries[0].type = 'json'
58+
return entries[0]
59+
}
5360
return Readable.from(
54-
cqn2sql.INSERT_entries_stream(
55-
query.INSERT
56-
? query.INSERT.entries
57-
: query.UPSERT.entries
58-
),
61+
cqn2sql.INSERT_entries_stream(entries),
5962
{ ObjectMode: false },
6063
)
6164
}

test/scenarios/maps/clob.cds

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using {cuid} from '@sap/cds/common';
2+
3+
entity Map : cuid {
4+
map : cds.Map;
5+
}

test/scenarios/maps/clob.test.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const cds = require('../../cds.js')
2+
const { Readable } = require('stream')
3+
4+
const { gen, rows } = require('./data.js')
5+
const { run } = require('./perf.js')
6+
7+
describe('Map - CLOB', () => {
8+
const { expect } = cds.test(__dirname, __dirname + '/clob.cds')
9+
10+
test('perf', async () => {
11+
const { Map } = cds.entities
12+
13+
console.log('Starting Insert...')
14+
const s = performance.now()
15+
await INSERT(Readable.from(gen(), { objectMode: false })).into(Map)
16+
const dur = performance.now() - s
17+
console.log('Finished Insert:', dur, '(', (rows / dur), 'rows/ms)')
18+
19+
const [{ count: rowCount }] = await cds.ql`SELECT count() from ${Map}`
20+
expect(rowCount).eq(rows)
21+
console.log('Validated Insert.')
22+
23+
/* HANA
24+
Starting Insert...
25+
Finished Insert: 10261.39113 ( 3.19332920701172 rows/ms)
26+
Validated Insert.
27+
$top=30 avg: 3 ms cold: 30 ms
28+
ID='1' avg: 3 ms cold: 34 ms
29+
*/
30+
31+
/* postgres
32+
Starting Insert...
33+
Finished Insert: 13024.595653 ( 2.51585545325182 rows/ms)
34+
Validated Insert.
35+
$top=30 avg: 6 ms cold: 9 ms
36+
ID='1' avg: 0 ms cold: 4 ms
37+
*/
38+
39+
/* sqlite
40+
Starting Insert...
41+
Finished Insert: 2072.096841 ( 15.813932704123069 rows/ms)
42+
Validated Insert.
43+
$top=30 avg: 1 ms cold: 2 ms
44+
ID='1' avg: 0 ms cold: 1 ms
45+
*/
46+
47+
await run('$top=30', cds.ql`SELECT ID, map FROM ${Map} LIMIT ${30}`)
48+
await run(`ID='1'`, cds.ql`SELECT ID, map FROM ${Map} WHERE ID=${'1'} LIMIT ${1}`)
49+
})
50+
51+
})

test/scenarios/maps/comp.cds

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using {cuid} from '@sap/cds/common';
2+
3+
entity Map : cuid {
4+
map : Composition of many {
5+
key ![key] : String(255);
6+
value : String(5000);
7+
}
8+
}

test/scenarios/maps/comp.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const cds = require('../../cds.js')
2+
const { Readable } = require('stream')
3+
4+
const { gen, rows, maps } = require('./data.js')
5+
const { run } = require('./perf.js')
6+
7+
describe('Map - Composition', () => {
8+
const { expect } = cds.test(__dirname, __dirname + '/comp.cds')
9+
10+
test('perf', async () => {
11+
const { Map } = cds.entities
12+
let s, dur
13+
14+
console.log('Starting Insert...')
15+
s = performance.now()
16+
await INSERT(Readable.from(gen(), { objectMode: false })).into(Map)
17+
dur = performance.now() - s
18+
console.log('Finished Insert:', dur, '(', (rows / dur), 'rows/ms)')
19+
20+
const [{ count: rowCount }] = await cds.ql`SELECT count() FROM ${Map}`
21+
const [{ count: mapCount }] = await cds.ql`SELECT count() FROM ${Map}.map`
22+
expect(rowCount).eq(rows)
23+
expect(mapCount).eq(maps * rows)
24+
console.log('Validated Insert.')
25+
26+
/*
27+
Starting Insert...
28+
Finished Insert: 28935.987634 ( 1.1324306747179196 rows/ms)
29+
Validated Insert.
30+
$top=30 avg: 18 ms cold: 165 ms
31+
ID='1' avg: 4 ms cold: 83 ms
32+
*/
33+
34+
await run('$top=30', cds.ql`SELECT ID, map {*} FROM ${Map} LIMIT ${30}`)
35+
await run(`ID='1'`, cds.ql`SELECT ID, map {*} FROM ${Map} WHERE ID=${'1'} LIMIT ${1}`)
36+
})
37+
38+
})

test/scenarios/maps/data.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const rows = 1 << 15
2+
const maps = 1e2
3+
const gen = function* () {
4+
yield '['
5+
let sep = ''
6+
for (let ID = 0; ID < rows; ID++) {
7+
let row = `${sep}{"ID":${ID},"map":[`
8+
let rowSep = ''
9+
for (let key = 0; key < maps; key++) {
10+
if (rowSep) row += rowSep
11+
else rowSep = ','
12+
row += `{"up__ID":"${ID}","key":"${key}","value":"a value for \\"${key}\\""}`
13+
}
14+
row += ']}'
15+
yield row
16+
sep = ','
17+
}
18+
yield ']'
19+
}
20+
21+
module.exports = { rows, maps, gen }

test/scenarios/maps/docs.cds

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using {cuid} from '@sap/cds/common';
2+
3+
entity Map : cuid {
4+
map : Composition of many {
5+
key ![key] : String(255);
6+
value : String(5000);
7+
}
8+
}

0 commit comments

Comments
 (0)