sop4py 2.0.7__tar.gz → 2.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sop4py might be problematic. Click here for more details.
- {sop4py-2.0.7/sop4py.egg-info → sop4py-2.0.8}/PKG-INFO +119 -3
- {sop4py-2.0.7 → sop4py-2.0.8}/README.md +118 -2
- {sop4py-2.0.7 → sop4py-2.0.8}/pyproject.toml +1 -1
- {sop4py-2.0.7 → sop4py-2.0.8/sop4py.egg-info}/PKG-INFO +119 -3
- {sop4py-2.0.7 → sop4py-2.0.8}/MANIFEST.in +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/setup.cfg +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/__init__.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/btree.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/call_go.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/context.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_amd64darwin.dylib +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_amd64darwin.h +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_amd64linux.h +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_amd64linux.so +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_amd64windows.dll +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_amd64windows.h +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_arm64darwin.dylib +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_arm64darwin.h +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_arm64linux.h +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/libjsondb_arm64linux.so +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/redis.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/test_btree.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/test_btree_idx.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop/transaction.py +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop4py.egg-info/SOURCES.txt +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop4py.egg-info/dependency_links.txt +0 -0
- {sop4py-2.0.7 → sop4py-2.0.8}/sop4py.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sop4py
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.8
|
|
4
4
|
Summary: Scalable Objects Persistence for Python. Release Candidate 1 (RC1) Release
|
|
5
5
|
Author-email: Gerardo Recinto <gerardorecinto@yahoo.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -47,7 +47,7 @@ Following steps outlines how to use the Scalable Objects Persistence code librar
|
|
|
47
47
|
* Open the global Redis connection
|
|
48
48
|
* Create a transaction
|
|
49
49
|
* Begin a transaction
|
|
50
|
-
* Create
|
|
50
|
+
* Create new B-tree(s), or Open existing B-tree(s)
|
|
51
51
|
* Manage data, do some CRUD operations
|
|
52
52
|
* Commit the transaction
|
|
53
53
|
|
|
@@ -59,7 +59,9 @@ from sop import btree
|
|
|
59
59
|
from sop import context
|
|
60
60
|
from sop import redis
|
|
61
61
|
|
|
62
|
+
# Store info & Registry home base folders. Array of strings of two elements, one for Active & another, for passive folder.
|
|
62
63
|
stores_folders = ("/disk1", "/disk2")
|
|
64
|
+
|
|
63
65
|
ec = {
|
|
64
66
|
# Erasure Config default entry(key="") will allow different B-tree (data store) to share same EC structure.
|
|
65
67
|
# You can also specify a different one exclusive to a B-tree with the given name.
|
|
@@ -128,8 +130,122 @@ t.commit(ctx)
|
|
|
128
130
|
print("ended.")
|
|
129
131
|
```
|
|
130
132
|
|
|
133
|
+
# Index Specification
|
|
134
|
+
You can specify a Key structure that can be complex like a class and cherry pick the fields you want to affect the indexing and data organization in the B-tree. Like pick two fields from the Key class as comprised your index. And optionally specify the sort order, like 1st field is descending order and the 2nd field ascending.
|
|
135
|
+
|
|
136
|
+
Here is a good example to illustrate this use-case.
|
|
137
|
+
```
|
|
138
|
+
from . import transaction
|
|
139
|
+
from . import btree
|
|
140
|
+
from . import context
|
|
141
|
+
|
|
142
|
+
from .redis import *
|
|
143
|
+
from .test_btree import to
|
|
144
|
+
|
|
145
|
+
from dataclasses import dataclass
|
|
146
|
+
|
|
147
|
+
# Define your Key data class with two fields.
|
|
148
|
+
@dataclass
|
|
149
|
+
class Key:
|
|
150
|
+
address1: str
|
|
151
|
+
address2: str
|
|
152
|
+
|
|
153
|
+
# Define your Value data class.
|
|
154
|
+
@dataclass
|
|
155
|
+
class Person:
|
|
156
|
+
first_name: str
|
|
157
|
+
last_name: str
|
|
158
|
+
|
|
159
|
+
# Create a context for use in Transaction & B-tree API calls.
|
|
160
|
+
ctx = context.Context()
|
|
161
|
+
|
|
162
|
+
class TestBtreeIndexSpecs(unittest.TestCase):
|
|
163
|
+
def setUpClass():
|
|
164
|
+
ro = RedisOptions()
|
|
165
|
+
Redis.open_connection(ro)
|
|
166
|
+
|
|
167
|
+
t = transaction.Transaction(ctx, to)
|
|
168
|
+
t.begin()
|
|
169
|
+
|
|
170
|
+
cache = btree.CacheConfig()
|
|
171
|
+
bo = btree.BtreeOptions("personidx", True, cache_config=cache)
|
|
172
|
+
|
|
173
|
+
# Specify Small size, meaning, both Key & Value object values will be stored in the B-tree node segment.
|
|
174
|
+
# This is very efficient/appropriate for small data structure sizes (of Key & Value pairs).
|
|
175
|
+
bo.set_value_data_size(btree.ValueDataSize.Small)
|
|
176
|
+
|
|
177
|
+
# Specify that the B-tree will host non-primitive Key data type, i.e. - it is a dataclass.
|
|
178
|
+
bo.is_primitive_key = False
|
|
179
|
+
|
|
180
|
+
btree.Btree.new(
|
|
181
|
+
ctx,
|
|
182
|
+
bo,
|
|
183
|
+
t,
|
|
184
|
+
# Specify the Index fields of the Key class. You control how many fields get included
|
|
185
|
+
# and each field's sort order (asc or desc).
|
|
186
|
+
btree.IndexSpecification(
|
|
187
|
+
index_fields=(
|
|
188
|
+
# 1st field is "address1" in descending order.
|
|
189
|
+
btree.IndexFieldSpecification(
|
|
190
|
+
"address1", ascending_sort_order=False
|
|
191
|
+
),
|
|
192
|
+
# 2nd field is "address2" in ascending order (default).
|
|
193
|
+
btree.IndexFieldSpecification("address2"),
|
|
194
|
+
)
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
# Commit the transaction to finalize it.
|
|
199
|
+
t.commit(ctx)
|
|
200
|
+
|
|
201
|
+
def test_add(self):
|
|
202
|
+
t = transaction.Transaction(ctx, to)
|
|
203
|
+
t.begin()
|
|
204
|
+
|
|
205
|
+
b3 = btree.Btree.open(ctx, "personidx", t)
|
|
206
|
+
|
|
207
|
+
pk = Key(address1="123 main st", address2="Fremont, CA")
|
|
208
|
+
l = [btree.Item(pk, Person(first_name="joe", last_name="petit"))]
|
|
209
|
+
|
|
210
|
+
# Populate with some sample Key & Value pairs of data set.
|
|
211
|
+
for i in range(20):
|
|
212
|
+
pk = Key(address1=f"{i}123 main st", address2="Fremont, CA")
|
|
213
|
+
l.append(btree.Item(pk, Person(first_name=f"joe{i}", last_name="petit")))
|
|
214
|
+
|
|
215
|
+
# Submit the entire generated batch to be added to B-tree in one call.
|
|
216
|
+
b3.add_if_not_exists(ctx, l)
|
|
217
|
+
|
|
218
|
+
# Commit the changes.
|
|
219
|
+
t.commit(ctx)
|
|
220
|
+
|
|
221
|
+
def test_get_items_batch(self):
|
|
222
|
+
t = transaction.Transaction(ctx, to)
|
|
223
|
+
t.begin()
|
|
224
|
+
|
|
225
|
+
b3 = btree.Btree.open(ctx, "personidx", t)
|
|
226
|
+
|
|
227
|
+
# Fetch the data starting with 1st record up to 10th.
|
|
228
|
+
# Paging info is:
|
|
229
|
+
# 0 page offset means the current record where the cursor is located, 0 skipped items, 10 items to fetch.
|
|
230
|
+
# In forward direction.
|
|
231
|
+
items = b3.get_items(
|
|
232
|
+
ctx,
|
|
233
|
+
btree.PagingInfo(0, 0, 10, direction=btree.PagingDirection.Forward.value),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
print(f"read items from indexed keyed b-tree {items}")
|
|
237
|
+
|
|
238
|
+
# End the transaction by calling commit. Commit in this case will also double check that the fetched items
|
|
239
|
+
# did not change while in the transaction. If there is then it will return an error to denote this and
|
|
240
|
+
# thus, your code can treat it as failure if it needs to, like in a financial transaction.
|
|
241
|
+
t.commit(ctx)
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
** Above is the same code of "sop/test_btree_idx.py" unit test file.
|
|
246
|
+
|
|
131
247
|
# SOP in Github
|
|
132
248
|
SOP open source project (MIT license) is in github. You can checkout the "...sop/jsondb/" package which contains the Go code enabling general purpose JSON data management & the Python wrapper, coding guideline of which, was described above.
|
|
133
249
|
|
|
134
250
|
Please feel free to join the SOP project if you have the bandwidth and participate/co-own/lead! the project engineering.
|
|
135
|
-
SOP project
|
|
251
|
+
SOP project links: https://github.com/sharedcode/sop & https://pypi.org/project/sop4py
|
|
@@ -36,7 +36,7 @@ Following steps outlines how to use the Scalable Objects Persistence code librar
|
|
|
36
36
|
* Open the global Redis connection
|
|
37
37
|
* Create a transaction
|
|
38
38
|
* Begin a transaction
|
|
39
|
-
* Create
|
|
39
|
+
* Create new B-tree(s), or Open existing B-tree(s)
|
|
40
40
|
* Manage data, do some CRUD operations
|
|
41
41
|
* Commit the transaction
|
|
42
42
|
|
|
@@ -48,7 +48,9 @@ from sop import btree
|
|
|
48
48
|
from sop import context
|
|
49
49
|
from sop import redis
|
|
50
50
|
|
|
51
|
+
# Store info & Registry home base folders. Array of strings of two elements, one for Active & another, for passive folder.
|
|
51
52
|
stores_folders = ("/disk1", "/disk2")
|
|
53
|
+
|
|
52
54
|
ec = {
|
|
53
55
|
# Erasure Config default entry(key="") will allow different B-tree (data store) to share same EC structure.
|
|
54
56
|
# You can also specify a different one exclusive to a B-tree with the given name.
|
|
@@ -117,8 +119,122 @@ t.commit(ctx)
|
|
|
117
119
|
print("ended.")
|
|
118
120
|
```
|
|
119
121
|
|
|
122
|
+
# Index Specification
|
|
123
|
+
You can specify a Key structure that can be complex like a class and cherry pick the fields you want to affect the indexing and data organization in the B-tree. Like pick two fields from the Key class as comprised your index. And optionally specify the sort order, like 1st field is descending order and the 2nd field ascending.
|
|
124
|
+
|
|
125
|
+
Here is a good example to illustrate this use-case.
|
|
126
|
+
```
|
|
127
|
+
from . import transaction
|
|
128
|
+
from . import btree
|
|
129
|
+
from . import context
|
|
130
|
+
|
|
131
|
+
from .redis import *
|
|
132
|
+
from .test_btree import to
|
|
133
|
+
|
|
134
|
+
from dataclasses import dataclass
|
|
135
|
+
|
|
136
|
+
# Define your Key data class with two fields.
|
|
137
|
+
@dataclass
|
|
138
|
+
class Key:
|
|
139
|
+
address1: str
|
|
140
|
+
address2: str
|
|
141
|
+
|
|
142
|
+
# Define your Value data class.
|
|
143
|
+
@dataclass
|
|
144
|
+
class Person:
|
|
145
|
+
first_name: str
|
|
146
|
+
last_name: str
|
|
147
|
+
|
|
148
|
+
# Create a context for use in Transaction & B-tree API calls.
|
|
149
|
+
ctx = context.Context()
|
|
150
|
+
|
|
151
|
+
class TestBtreeIndexSpecs(unittest.TestCase):
|
|
152
|
+
def setUpClass():
|
|
153
|
+
ro = RedisOptions()
|
|
154
|
+
Redis.open_connection(ro)
|
|
155
|
+
|
|
156
|
+
t = transaction.Transaction(ctx, to)
|
|
157
|
+
t.begin()
|
|
158
|
+
|
|
159
|
+
cache = btree.CacheConfig()
|
|
160
|
+
bo = btree.BtreeOptions("personidx", True, cache_config=cache)
|
|
161
|
+
|
|
162
|
+
# Specify Small size, meaning, both Key & Value object values will be stored in the B-tree node segment.
|
|
163
|
+
# This is very efficient/appropriate for small data structure sizes (of Key & Value pairs).
|
|
164
|
+
bo.set_value_data_size(btree.ValueDataSize.Small)
|
|
165
|
+
|
|
166
|
+
# Specify that the B-tree will host non-primitive Key data type, i.e. - it is a dataclass.
|
|
167
|
+
bo.is_primitive_key = False
|
|
168
|
+
|
|
169
|
+
btree.Btree.new(
|
|
170
|
+
ctx,
|
|
171
|
+
bo,
|
|
172
|
+
t,
|
|
173
|
+
# Specify the Index fields of the Key class. You control how many fields get included
|
|
174
|
+
# and each field's sort order (asc or desc).
|
|
175
|
+
btree.IndexSpecification(
|
|
176
|
+
index_fields=(
|
|
177
|
+
# 1st field is "address1" in descending order.
|
|
178
|
+
btree.IndexFieldSpecification(
|
|
179
|
+
"address1", ascending_sort_order=False
|
|
180
|
+
),
|
|
181
|
+
# 2nd field is "address2" in ascending order (default).
|
|
182
|
+
btree.IndexFieldSpecification("address2"),
|
|
183
|
+
)
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Commit the transaction to finalize it.
|
|
188
|
+
t.commit(ctx)
|
|
189
|
+
|
|
190
|
+
def test_add(self):
|
|
191
|
+
t = transaction.Transaction(ctx, to)
|
|
192
|
+
t.begin()
|
|
193
|
+
|
|
194
|
+
b3 = btree.Btree.open(ctx, "personidx", t)
|
|
195
|
+
|
|
196
|
+
pk = Key(address1="123 main st", address2="Fremont, CA")
|
|
197
|
+
l = [btree.Item(pk, Person(first_name="joe", last_name="petit"))]
|
|
198
|
+
|
|
199
|
+
# Populate with some sample Key & Value pairs of data set.
|
|
200
|
+
for i in range(20):
|
|
201
|
+
pk = Key(address1=f"{i}123 main st", address2="Fremont, CA")
|
|
202
|
+
l.append(btree.Item(pk, Person(first_name=f"joe{i}", last_name="petit")))
|
|
203
|
+
|
|
204
|
+
# Submit the entire generated batch to be added to B-tree in one call.
|
|
205
|
+
b3.add_if_not_exists(ctx, l)
|
|
206
|
+
|
|
207
|
+
# Commit the changes.
|
|
208
|
+
t.commit(ctx)
|
|
209
|
+
|
|
210
|
+
def test_get_items_batch(self):
|
|
211
|
+
t = transaction.Transaction(ctx, to)
|
|
212
|
+
t.begin()
|
|
213
|
+
|
|
214
|
+
b3 = btree.Btree.open(ctx, "personidx", t)
|
|
215
|
+
|
|
216
|
+
# Fetch the data starting with 1st record up to 10th.
|
|
217
|
+
# Paging info is:
|
|
218
|
+
# 0 page offset means the current record where the cursor is located, 0 skipped items, 10 items to fetch.
|
|
219
|
+
# In forward direction.
|
|
220
|
+
items = b3.get_items(
|
|
221
|
+
ctx,
|
|
222
|
+
btree.PagingInfo(0, 0, 10, direction=btree.PagingDirection.Forward.value),
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
print(f"read items from indexed keyed b-tree {items}")
|
|
226
|
+
|
|
227
|
+
# End the transaction by calling commit. Commit in this case will also double check that the fetched items
|
|
228
|
+
# did not change while in the transaction. If there is then it will return an error to denote this and
|
|
229
|
+
# thus, your code can treat it as failure if it needs to, like in a financial transaction.
|
|
230
|
+
t.commit(ctx)
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
** Above is the same code of "sop/test_btree_idx.py" unit test file.
|
|
235
|
+
|
|
120
236
|
# SOP in Github
|
|
121
237
|
SOP open source project (MIT license) is in github. You can checkout the "...sop/jsondb/" package which contains the Go code enabling general purpose JSON data management & the Python wrapper, coding guideline of which, was described above.
|
|
122
238
|
|
|
123
239
|
Please feel free to join the SOP project if you have the bandwidth and participate/co-own/lead! the project engineering.
|
|
124
|
-
SOP project
|
|
240
|
+
SOP project links: https://github.com/sharedcode/sop & https://pypi.org/project/sop4py
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sop4py
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.8
|
|
4
4
|
Summary: Scalable Objects Persistence for Python. Release Candidate 1 (RC1) Release
|
|
5
5
|
Author-email: Gerardo Recinto <gerardorecinto@yahoo.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -47,7 +47,7 @@ Following steps outlines how to use the Scalable Objects Persistence code librar
|
|
|
47
47
|
* Open the global Redis connection
|
|
48
48
|
* Create a transaction
|
|
49
49
|
* Begin a transaction
|
|
50
|
-
* Create
|
|
50
|
+
* Create new B-tree(s), or Open existing B-tree(s)
|
|
51
51
|
* Manage data, do some CRUD operations
|
|
52
52
|
* Commit the transaction
|
|
53
53
|
|
|
@@ -59,7 +59,9 @@ from sop import btree
|
|
|
59
59
|
from sop import context
|
|
60
60
|
from sop import redis
|
|
61
61
|
|
|
62
|
+
# Store info & Registry home base folders. Array of strings of two elements, one for Active & another, for passive folder.
|
|
62
63
|
stores_folders = ("/disk1", "/disk2")
|
|
64
|
+
|
|
63
65
|
ec = {
|
|
64
66
|
# Erasure Config default entry(key="") will allow different B-tree (data store) to share same EC structure.
|
|
65
67
|
# You can also specify a different one exclusive to a B-tree with the given name.
|
|
@@ -128,8 +130,122 @@ t.commit(ctx)
|
|
|
128
130
|
print("ended.")
|
|
129
131
|
```
|
|
130
132
|
|
|
133
|
+
# Index Specification
|
|
134
|
+
You can specify a Key structure that can be complex like a class and cherry pick the fields you want to affect the indexing and data organization in the B-tree. Like pick two fields from the Key class as comprised your index. And optionally specify the sort order, like 1st field is descending order and the 2nd field ascending.
|
|
135
|
+
|
|
136
|
+
Here is a good example to illustrate this use-case.
|
|
137
|
+
```
|
|
138
|
+
from . import transaction
|
|
139
|
+
from . import btree
|
|
140
|
+
from . import context
|
|
141
|
+
|
|
142
|
+
from .redis import *
|
|
143
|
+
from .test_btree import to
|
|
144
|
+
|
|
145
|
+
from dataclasses import dataclass
|
|
146
|
+
|
|
147
|
+
# Define your Key data class with two fields.
|
|
148
|
+
@dataclass
|
|
149
|
+
class Key:
|
|
150
|
+
address1: str
|
|
151
|
+
address2: str
|
|
152
|
+
|
|
153
|
+
# Define your Value data class.
|
|
154
|
+
@dataclass
|
|
155
|
+
class Person:
|
|
156
|
+
first_name: str
|
|
157
|
+
last_name: str
|
|
158
|
+
|
|
159
|
+
# Create a context for use in Transaction & B-tree API calls.
|
|
160
|
+
ctx = context.Context()
|
|
161
|
+
|
|
162
|
+
class TestBtreeIndexSpecs(unittest.TestCase):
|
|
163
|
+
def setUpClass():
|
|
164
|
+
ro = RedisOptions()
|
|
165
|
+
Redis.open_connection(ro)
|
|
166
|
+
|
|
167
|
+
t = transaction.Transaction(ctx, to)
|
|
168
|
+
t.begin()
|
|
169
|
+
|
|
170
|
+
cache = btree.CacheConfig()
|
|
171
|
+
bo = btree.BtreeOptions("personidx", True, cache_config=cache)
|
|
172
|
+
|
|
173
|
+
# Specify Small size, meaning, both Key & Value object values will be stored in the B-tree node segment.
|
|
174
|
+
# This is very efficient/appropriate for small data structure sizes (of Key & Value pairs).
|
|
175
|
+
bo.set_value_data_size(btree.ValueDataSize.Small)
|
|
176
|
+
|
|
177
|
+
# Specify that the B-tree will host non-primitive Key data type, i.e. - it is a dataclass.
|
|
178
|
+
bo.is_primitive_key = False
|
|
179
|
+
|
|
180
|
+
btree.Btree.new(
|
|
181
|
+
ctx,
|
|
182
|
+
bo,
|
|
183
|
+
t,
|
|
184
|
+
# Specify the Index fields of the Key class. You control how many fields get included
|
|
185
|
+
# and each field's sort order (asc or desc).
|
|
186
|
+
btree.IndexSpecification(
|
|
187
|
+
index_fields=(
|
|
188
|
+
# 1st field is "address1" in descending order.
|
|
189
|
+
btree.IndexFieldSpecification(
|
|
190
|
+
"address1", ascending_sort_order=False
|
|
191
|
+
),
|
|
192
|
+
# 2nd field is "address2" in ascending order (default).
|
|
193
|
+
btree.IndexFieldSpecification("address2"),
|
|
194
|
+
)
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
# Commit the transaction to finalize it.
|
|
199
|
+
t.commit(ctx)
|
|
200
|
+
|
|
201
|
+
def test_add(self):
|
|
202
|
+
t = transaction.Transaction(ctx, to)
|
|
203
|
+
t.begin()
|
|
204
|
+
|
|
205
|
+
b3 = btree.Btree.open(ctx, "personidx", t)
|
|
206
|
+
|
|
207
|
+
pk = Key(address1="123 main st", address2="Fremont, CA")
|
|
208
|
+
l = [btree.Item(pk, Person(first_name="joe", last_name="petit"))]
|
|
209
|
+
|
|
210
|
+
# Populate with some sample Key & Value pairs of data set.
|
|
211
|
+
for i in range(20):
|
|
212
|
+
pk = Key(address1=f"{i}123 main st", address2="Fremont, CA")
|
|
213
|
+
l.append(btree.Item(pk, Person(first_name=f"joe{i}", last_name="petit")))
|
|
214
|
+
|
|
215
|
+
# Submit the entire generated batch to be added to B-tree in one call.
|
|
216
|
+
b3.add_if_not_exists(ctx, l)
|
|
217
|
+
|
|
218
|
+
# Commit the changes.
|
|
219
|
+
t.commit(ctx)
|
|
220
|
+
|
|
221
|
+
def test_get_items_batch(self):
|
|
222
|
+
t = transaction.Transaction(ctx, to)
|
|
223
|
+
t.begin()
|
|
224
|
+
|
|
225
|
+
b3 = btree.Btree.open(ctx, "personidx", t)
|
|
226
|
+
|
|
227
|
+
# Fetch the data starting with 1st record up to 10th.
|
|
228
|
+
# Paging info is:
|
|
229
|
+
# 0 page offset means the current record where the cursor is located, 0 skipped items, 10 items to fetch.
|
|
230
|
+
# In forward direction.
|
|
231
|
+
items = b3.get_items(
|
|
232
|
+
ctx,
|
|
233
|
+
btree.PagingInfo(0, 0, 10, direction=btree.PagingDirection.Forward.value),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
print(f"read items from indexed keyed b-tree {items}")
|
|
237
|
+
|
|
238
|
+
# End the transaction by calling commit. Commit in this case will also double check that the fetched items
|
|
239
|
+
# did not change while in the transaction. If there is then it will return an error to denote this and
|
|
240
|
+
# thus, your code can treat it as failure if it needs to, like in a financial transaction.
|
|
241
|
+
t.commit(ctx)
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
** Above is the same code of "sop/test_btree_idx.py" unit test file.
|
|
246
|
+
|
|
131
247
|
# SOP in Github
|
|
132
248
|
SOP open source project (MIT license) is in github. You can checkout the "...sop/jsondb/" package which contains the Go code enabling general purpose JSON data management & the Python wrapper, coding guideline of which, was described above.
|
|
133
249
|
|
|
134
250
|
Please feel free to join the SOP project if you have the bandwidth and participate/co-own/lead! the project engineering.
|
|
135
|
-
SOP project
|
|
251
|
+
SOP project links: https://github.com/sharedcode/sop & https://pypi.org/project/sop4py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|