sop4py 2.0.7__py3-none-any.whl → 2.0.8__py3-none-any.whl

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sop4py
3
- Version: 2.0.7
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 a new B-tree, or Open an existing B-tree
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 link: https://github.com/sharedcode/sop
251
+ SOP project links: https://github.com/sharedcode/sop & https://pypi.org/project/sop4py
@@ -16,7 +16,7 @@ sop/redis.py,sha256=M2gZEDAPntG2HpV74Uc1FDneCWVFvsf3nv3zZ1Zx-3A,1165
16
16
  sop/test_btree.py,sha256=dmzto0m_y81RsU7e6i1GIQjq_eGQ_lSj0Ayilh2IqNY,13093
17
17
  sop/test_btree_idx.py,sha256=4Nus9UzaYWqfX1DfPbbeFffhvelVeVsBbaqpJB-5RXs,2254
18
18
  sop/transaction.py,sha256=Rl92TCdHgYIrCZBIrncOcjDhoT1THKYX5mFHN1sr85c,5767
19
- sop4py-2.0.7.dist-info/METADATA,sha256=PN5kzeDStPv0BoZU3tff6a5K29AqTWSgVuCDZjtipfE,6949
20
- sop4py-2.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
21
- sop4py-2.0.7.dist-info/top_level.txt,sha256=Xg42qRXwoOKelr7Lc8cpmy9uuBU3LtD3tPLHVnt0aHs,4
22
- sop4py-2.0.7.dist-info/RECORD,,
19
+ sop4py-2.0.8.dist-info/METADATA,sha256=G7_0tLKWzhlBFtXI7BQ2iCMYlenJ0IPGvEdMXMhk_9U,11149
20
+ sop4py-2.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
21
+ sop4py-2.0.8.dist-info/top_level.txt,sha256=Xg42qRXwoOKelr7Lc8cpmy9uuBU3LtD3tPLHVnt0aHs,4
22
+ sop4py-2.0.8.dist-info/RECORD,,
File without changes