Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4cce368

Browse files
committed
Add generic tests
1 parent 8eb3b3d commit 4cce368

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

jsonbc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,9 @@ jsonbc_decompress(AttributeCompression *ac, const struct varlena *data)
740740
/* replace the encoded keys with real keys */
741741
for (i = 0; i < nkeys; i++)
742742
{
743-
size_t oldoff = offset;
743+
size_t oldoff = offset;
744+
JsonbValue *v = &jbv->val.object.pairs[i].key;
744745

745-
JsonbValue *v = &jbv->val.object.pairs[i].key;
746746
v->val.string.val = &buf[offset];
747747

748748
/* move to next key in buffer */

tests/jsonbc_test.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
import random
5+
import json
6+
7+
from testgres import get_new_node
8+
9+
10+
insert_cmd = '''
11+
INSERT INTO comp.t
12+
SELECT jsonb_object(array_agg(array[repeat(letter, count), count::text]))
13+
FROM (
14+
SELECT chr(i) AS letter, b AS count
15+
FROM generate_series(ascii('a'), ascii('z')) i
16+
FULL OUTER JOIN
17+
(SELECT b FROM generate_series(10, 20) b) t2
18+
ON 1=1
19+
) t3;
20+
'''
21+
22+
def generate_dict():
23+
population = 'qwertyuiopsadfghjklzxcvbnm1234567890'
24+
res = {}
25+
26+
for i in range(300):
27+
keylen = random.randint(1, len(population))
28+
key = ''.join(random.sample(population, keylen))
29+
res[key] = keylen
30+
31+
return res
32+
33+
34+
class Tests(unittest.TestCase):
35+
def test_correctness(self):
36+
with get_new_node('node1') as node:
37+
node.init()
38+
node.append_conf("postgresql.conf", "shared_preload_libraries='jsonbc'\n")
39+
node.start()
40+
41+
node.psql('postgres', 'create extension jsonbc')
42+
node.psql('postgres', 'create compression method cm1 handler jsonbc_compression_handler')
43+
node.psql('postgres', 'create table t1(pk serial, a jsonb compressed cm1);')
44+
45+
data = []
46+
for i in range(100):
47+
d = generate_dict()
48+
data.append(d)
49+
node.psql('postgres', "begin; insert into t1 (a) values ('%s'); commit;" % json.dumps(d))
50+
51+
with node.connect('postgres') as con:
52+
res = con.execute('select pk, a from t1 order by pk')
53+
for pk, val in res:
54+
self.assertEqual(val, data[pk - 1])
55+
56+
57+
if __name__ == "__main__":
58+
unittest.main()

0 commit comments

Comments
 (0)