I am working on the example "create_binary.py", instead of doing put to the cache, I tried put_all
for multiple records to cache. While put
is successful, but put_all
gives error.
student_cache = client.get_or_create_cache({
PROP_NAME: 'SQL_PUBLIC_STUDENT',
PROP_SQL_SCHEMA: 'PUBLIC',
PROP_QUERY_ENTITIES: [
{
'table_name': 'Student'.upper(),
'key_field_name': 'SID',
'key_type_name': 'java.lang.Integer',
'field_name_aliases': [],
'query_fields': [
{
'name': 'SID',
'type_name': 'java.lang.Integer',
'is_key_field': True,
'is_notnull_constraint_field': True,
},
{
'name': 'NAME',
'type_name': 'java.lang.String',
},
{
'name': 'LOGIN',
'type_name': 'java.lang.String',
},
{
'name': 'AGE',
'type_name': 'java.lang.Integer',
},
{
'name': 'GPA',
'type_name': 'java.math.Double',
},
],
'query_indexes': [],
'value_type_name': 'SQL_PUBLIC_STUDENT_TYPE',
'value_field_name': None,
},
],
})
student_cache.put(
1,
Student(LOGIN='jdoe', NAME='John Doe', AGE=17, GPA=4.25),
key_hint=IntObject
)
student_cache.put_all({1: Student(LOGIN='jdoe', NAME='John Doe', AGE=17, GPA=4.25), 2: Student(LOGIN='jdoe2', NAME='John Doe2', AGE=18, GPA=4.25)})
put_all
gives error:
Traceback (most recent call last): File "C:/ignite/pyignite/examples/create_binary.py", line 105, in student_cache.put_all({1: Student(LOGIN='jdoe', NAME='John Doe', AGE=17, GPA=4.25), 2: Student(LOGIN='jdoe2', NAME='John Doe2', AGE=18, GPA=4.25)}) File "C:\Users\nbkmqoi\AppData\Roaming\Python\Python35\site-packages\pyignite\utils.py", line 169, in ste_wrapper raise exc(result.message) pyignite.exceptions.CacheError: Failed to update keys (retry update if possible).: [1, 2]
How can I make put_all working? Thanks!
I figured out. Need to add datatype in the turple with the key
student_cache.put_all({(1, IntObject): Student(LOGIN='jdoe', NAME='John Doe', AGE=17, GPA=4.25), (2, IntObject): Student(LOGIN='jdoe2', NAME='John Doe2', AGE=18, GPA=4.25)})