Skip to content

Commit

Permalink
[feature] Update pyreindexer API (#12)
Browse files Browse the repository at this point in the history
* [fea] Update API:
- remove 'commit' method
- add 'delete_meta' method

---------

Co-authored-by: Alexander.A.Utkin <[email protected]>
  • Loading branch information
AlexAUtkin and Alexander.A.Utkin authored Oct 4, 2024
1 parent b04322a commit 5629795
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 246 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__
.idea/*
build/*
dist/*
pyreindexer.egg-info/*
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Gets a list of namespaces available

__Arguments:__

enum_not_opeden (bool, optional): An enumeration mode flag. If it is
enum_not_opened (bool, optional): An enumeration mode flag. If it is
set then closed namespaces are in result list too. Defaults to False.

__Returns:__
Expand Down Expand Up @@ -238,58 +238,59 @@ __Raises:__
Exception: Raises with an error message of API return on non-zero error code.


<h3 id="pyreindexer.rx_connector.RxConnector.commit">commit</h3>
<h3 id="pyreindexer.rx_connector.RxConnector.meta_put">meta_put</h3>

```python
RxConnector.commit(self, namespace)
RxConnector.meta_put(self, namespace, key, value)
```
Flushes changes to a storage of Reindexer
Puts metadata to a storage of Reindexer by key

__Arguments:__

namespace (string): A name of a namespace
key (string): A key in a storage of Reindexer for metadata keeping
value (string): A metadata for storage

__Raises:__

Exception: Raises with an error message of API return if Reindexer instance is not initialized yet.
Exception: Raises with an error message of API return on non-zero error code.


<h3 id="pyreindexer.rx_connector.RxConnector.meta_put">meta_put</h3>
<h3 id="pyreindexer.rx_connector.RxConnector.meta_get">meta_get</h3>

```python
RxConnector.meta_put(self, namespace, key, value)
RxConnector.meta_get(self, namespace, key)
```
Puts metadata to a storage of Reindexer by key
Gets metadata from a storage of Reindexer by key specified

__Arguments:__

namespace (string): A name of a namespace
key (string): A key in a storage of Reindexer for metadata keeping
value (string): A metadata for storage
key (string): A key in a storage of Reindexer where metadata is kept

__Returns:__

string: A metadata value

__Raises:__

Exception: Raises with an error message of API return if Reindexer instance is not initialized yet.
Exception: Raises with an error message of API return on non-zero error code.


<h3 id="pyreindexer.rx_connector.RxConnector.meta_get">meta_get</h3>
<h3 id="pyreindexer.rx_connector.RxConnector.meta_delete">meta_delete</h3>

```python
RxConnector.meta_get(self, namespace, key)
RxConnector.meta_delete(self, namespace, key)
```
Gets metadata from a storage of Reindexer by key specified
Deletes metadata from a storage of Reindexer by key specified

__Arguments:__

namespace (string): A name of a namespace
key (string): A key in a storage of Reindexer where metadata is kept

__Returns:__

string: A metadata value

__Raises:__

Exception: Raises with an error message of API return if Reindexer instance is not initialized yet.
Expand Down
4 changes: 2 additions & 2 deletions pyreindexer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.10)

project(pyreindexer)

Expand All @@ -11,7 +11,7 @@ endif()
enable_testing()

set(PY_MIN_VERSION 3.6)
set(RX_MIN_VERSION 3.2.2)
set(RX_MIN_VERSION 3.24.0)
find_package(PythonInterp ${PY_MIN_VERSION})
find_package(PythonLibs ${PY_MIN_VERSION})
find_package(reindexer CONFIG ${RX_MIN_VERSION})
Expand Down
8 changes: 4 additions & 4 deletions pyreindexer/example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_index_example(db, namespace):
'is_sparse': False,
'collate_mode': 'none',
'sort_order_letters': '',
'expire_after':0,
'expire_after': 0,
'config': {},
}

Expand All @@ -36,16 +36,16 @@ def update_index_example(db, namespace):
'is_sparse': False,
'collate_mode': 'none',
'sort_order_letters': '',
'expire_after':0,
'expire_after': 0,
'config': {},
}
db.index_update(namespace, index_definition_modified)


def create_items_example(db, namespace):
ITEMS_COUNT = 10
items_count = 10

for i in range(0, ITEMS_COUNT):
for i in range(0, items_count):
item = {'id': i + 1, 'name': 'item_' + str(i % 2)}
db.item_upsert(namespace, item)

Expand Down
19 changes: 12 additions & 7 deletions pyreindexer/index_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ class IndexDefinition(dict):
# Arguments:
name (str): An index name.
json_paths (:obj:`list` of :obj:`str`): A name for mapping a value to a json field.
field_type (str): A type of a field. Possible values are: `int`, `int64`, `double`, `string`, `bool`, `composite`.
field_type (str): A type of field. Possible values are: `int`, `int64`, `double`, `string`, `bool`, `composite`.
index_type (str): An index type. Possible values are: `hash`, `tree`, `text`, `-`.
is_pk (bool): True if a field is a primary key.
is_array (bool): True if an index is an array.
is_dense (bool): True if an index is dense. reduce index size. Saves 8 bytes per unique key value for 'hash' and 'tree' index types.
For '-' index type saves 4-8 bytes per each element. Useful for indexes with high selectivity, but for tree and hash indexes with low selectivity could
is_dense (bool): True if an index is dense. reduce index size. Saves 8 bytes per unique key value for 'hash'
and 'tree' index types.
For '-' index type saves 4-8 bytes per each element. Useful for indexes with high selectivity,
but for tree and hash indexes with low selectivity could
significantly decrease update performance.
is_sparse (bool): True if a value of an index may be not presented.
collate_mode (str): Sets an order of values by collate mode. Possible values are: `none`, `ascii`, `utf8`, `numeric`, `custom`.
collate_mode (str): Sets an order of values by collate mode. Possible values are:
`none`, `ascii`, `utf8`, `numeric`, `custom`.
sort_order_letters (str): Order for a sort sequence for a custom collate mode.
config (dict): A config for a fulltext engine. [More](https://github.com/Restream/reindexer/blob/master/fulltext.md) .
config (dict): A config for a fulltext engine.
[More](https://github.com/Restream/reindexer/blob/master/fulltext.md) .
"""

def __getitem__(self, attr):
Expand All @@ -33,11 +37,12 @@ def __setitem__(self, attr, value):
super(IndexDefinition, self).update({attr: value})
return self

def update(self, dict_part={}):
def update(self, dict_part=None):
raise NotImplementedError(
'Bulk update is not implemented for IndexDefinition instance')

def _get_known_attrs(self):
@staticmethod
def _get_known_attrs() -> list[str]:
return ['name', 'json_paths', 'field_type', 'index_type', 'is_pk',
'is_array', 'is_dense', 'is_sparse', 'collate_mode', 'sort_order_letters', 'expire_after', 'config']

Expand Down
12 changes: 5 additions & 7 deletions pyreindexer/lib/include/pyobjtools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ void pyDictSerialize(PyObject **dict, reindexer::WrSerializer &wrSer) {
}

void PyObjectToJson(PyObject **obj, reindexer::WrSerializer &wrSer) {
if (!PyList_Check(*obj) && !PyDict_Check(*obj)) {
throw reindexer::Error(errParseJson,
std::string("PyObject must be a dictionary or a list for JSON serializing, got ") + Py_TYPE(*obj)->tp_name);
}

if (PyDict_Check(*obj)) {
pyDictSerialize(obj, wrSer);
} else {
} else if (PyList_Check(*obj) ) {
pyListSerialize(obj, wrSer);
} else {
throw reindexer::Error(errParseJson,
std::string("PyObject must be a dictionary or a list for JSON serializing, got ") + Py_TYPE(*obj)->tp_name);
}
}

Expand All @@ -117,7 +115,7 @@ std::vector<std::string> ParseListToStrVec(PyObject **list) {
}

PyObject *pyValueFromJsonValue(const gason::JsonValue &value) {
PyObject *pyValue = NULL;
PyObject *pyValue = nullptr;

switch (value.getTag()) {
case gason::JSON_NUMBER:
Expand Down
Loading

0 comments on commit 5629795

Please sign in to comment.