Skip to content

Instantly share code, notes, and snippets.

@pilshchikov
Last active October 31, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilshchikov/7434805b7d95973afe600e1c0c83d17a to your computer and use it in GitHub Desktop.
Save pilshchikov/7434805b7d95973afe600e1c0c83d17a to your computer and use it in GitHub Desktop.
timestamp example
1 ----------------------------------------------------------
from pyignite import Client
from pyignite.datatypes import *
from datetime import datetime
client = Client()
client.connect('127.0.0.1', 10800)
cache = client.get_or_create_cache("PY_COLLECTION_ARRAY_LIST_TIMESTAMP_TIMESTAMP")
cache.put(1, (1, [(datetime.strptime('2018-10-31T19:43:34.264437', '%Y-%m-%dT%H:%M:%S.%f'), 264437), (datetime.strptime('2018-10-31T19:43:34.264438', '%Y-%m-%dT%H:%M:%S.%f'), 264438)]), key_hint=IntObject, value_hint=CollectionObject)
# Output:
#
# /usr/bin/python3.7 /home/gridgain/.IntelliJIdea2018.2/config/scratches/buffer1.py
# Traceback (most recent call last):
# File "/buffer1.py", line 8, in <module>
# cache.put(1, (1, [(datetime.strptime('2018-10-31T19:43:34.264437', '%Y-%m-%dT%H:%M:%S.%f'), 264437), (datetime.strptime('2018-10-31T19:43:34.264438', '%Y-%m-%dT%H:%M:%S.%f'), 264438)]), key_hint=IntObject, value_hint=CollectionObject)
# File "ignite/platforms/python/pyignite/utils.py", line 163, in ste_wrapper
# result = fn(*args, **kwargs)
# File "ignite/platforms/python/pyignite/cache.py", line 219, in put
# key_hint=key_hint, value_hint=value_hint
# File "ignite/platforms/python/pyignite/api/key_value.py", line 65, in cache_put
# 'value': value,
# File "ignite/platforms/python/pyignite/queries/__init__.py", line 284, in perform
# _, send_buffer = self.from_python(query_params)
# File "ignite/platforms/python/pyignite/queries/__init__.py", line 260, in from_python
# buffer += c_type.from_python(values[name])
# File "ignite/platforms/python/pyignite/datatypes/complex.py", line 109, in from_python
# buffer += AnyDataObject.from_python(x)
# File "ignite/platforms/python/pyignite/datatypes/internal.py", line 389, in from_python
# return cls.map_python_type(value).from_python(value)
# File "ignite/platforms/python/pyignite/datatypes/internal.py", line 375, in map_python_type
# 'Type `array of {}` is invalid'.format(value_subtype)
# TypeError: Type `array of None` is invalid
2 ----------------------------------------------------------
<?php
require_once '/vendor/autoload.php';
use Apache\Ignite\Client;
use Apache\Ignite\ClientConfiguration;
use Apache\Ignite\Data\Timestamp;
use Apache\Ignite\Type\ObjectType;
use Apache\Ignite\Type\CollectionObjectType;
$client = new Client();
$ENDPOINT = '127.0.0.1:10800';
$client->connect(new ClientConfiguration($ENDPOINT));
try {
$cache = $client->getOrCreateCache("PH_COLLECTION_ARRAY_LIST_TIMESTAMP_TIMESTAMP")->setKeyType(ObjectType::INTEGER)->setValueType(new CollectionObjectType(CollectionObjectType::ARRAY_LIST, ObjectType::TIMESTAMP));
$cache->put(1,array((new Timestamp((DateTime::createFromFormat('Y-m-d H:i:s.u', '2018-10-31 19:43:34.264437'))->getTimestamp() * 1000 + 264, 264437)), (new Timestamp((DateTime::createFromFormat('Y-m-d H:i:s.u', '2018-10-31 19:43:34.264438'))->getTimestamp() * 1000 + 264, 264438))));
} finally {
$client->disconnect();
}
// SUCCESSFUL
from pyignite import Client
from pyignite.datatypes import *
from datetime import datetime
from time import mktime
client = Client()
client.connect('127.0.0.1', 10800)
cache = client.get_or_create_cache("PH_COLLECTION_ARRAY_LIST_TIMESTAMP_TIMESTAMP")
result = cache.get(1, key_hint=IntObject)
print(result)
// Output
// (1, [(datetime.datetime(2018, 10, 31, 19, 43, 34, 264000), 264437), (datetime.datetime(2018, 10, 31, 19, 43, 34, 264000), 264438)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment