def test_query_description_via_table(self): query = 'describe {table}' table = Table(self.client, 'GeoCheckin') ts_obj = table.query(query) self.assertIsNotNone(ts_obj) self.assertEqual(len(ts_obj.columns), 5) self.assertEqual(len(ts_obj.rows), 5)
def test_create_error_via_put(self): table = Table(self.client, table_name) ts_obj = table.new([]) with self.assertRaises(RiakError) as cm: ts_obj.store() logging.debug("[test_timeseries_ttb] saw exception: {}".format( cm.exception))
def test_create_error_via_put(self): table = Table(self.client, table_name) ts_obj = table.new([]) with self.assertRaises(RiakError) as cm: ts_obj.store() logging.debug( "[test_timeseries_ttb] saw exception: {}" .format(cm.exception))
def test_stream_keys(self): table = Table(self.client, 'GeoCheckin') streamed_keys = [] for keylist in table.stream_keys(): self.assertNotEqual([], keylist) streamed_keys += keylist for key in keylist: self.assertIsInstance(key, list) self.assertEqual(len(key), 3) self.assertEqual('hash1', key[0]) self.assertEqual('user2', key[1]) self.assertIsInstance(key[2], datetime.datetime) self.assertGreater(len(streamed_keys), 0)
def test_stream_keys(self): table = Table(self.client, table_name) streamed_keys = [] for keylist in table.stream_keys(): self.assertNotEqual([], keylist) streamed_keys += keylist for key in keylist: self.assertIsInstance(key, list) self.assertEqual(len(key), 3) self.assertEqual(bytes_to_str(key[0]), 'hash1') self.assertEqual(bytes_to_str(key[1]), 'user2') self.assertIsInstance(key[2], datetime.datetime) self.assertGreater(len(streamed_keys), 0)
def ts_stream_keys(self, table, timeout=None): """ Lists all keys in a time series table via a stream. This is a generator method which should be iterated over. The caller should explicitly close the returned iterator, either using :func:`contextlib.closing` or calling ``close()`` explicitly. Consuming the entire iterator will also close the stream. If it does not, the associated connection might not be returned to the pool. Example:: from contextlib import closing # Using contextlib.closing with closing(client.ts_stream_keys(mytable)) as keys: for key_list in keys: do_something(key_list) # Explicit close() stream = client.ts_stream_keys(mytable) for key_list in stream: do_something(key_list) stream.close() :param table: the table from which to stream keys :type table: string or :class:`Table <riak.table.Table>` :param timeout: a timeout value in milliseconds :type timeout: int :rtype: iterator """ if not riak.disable_list_exceptions: raise ListError() t = table if isinstance(t, six.string_types): t = Table(self, table) _validate_timeout(timeout) resource = self._acquire() transport = resource.object stream = transport.ts_stream_keys(t, timeout) stream.attach(resource) try: for keylist in stream: if len(keylist) > 0: yield keylist finally: stream.close()
def setUpClass(cls): cls.ts0ms = unix_time_millis(ts0) if cls.ts0ms != ex0ms: raise AssertionError('expected {:d} to equal {:d}'.format( cls.ts0ms, ex0ms)) cls.ts1ms = unix_time_millis(ts1) if cls.ts1ms != ex1ms: raise AssertionError('expected {:d} to equal {:d}'.format( cls.ts1ms, ex1ms)) cls.rows = [[bd0, 0, 1.2, ts0, True, None], [bd1, 3, 4.5, ts1, False, blob0]] cls.test_key = ['hash1', 'user2', ts0] cls.table = Table(None, table_name)
def ts_describe(self, transport, table): """ ts_describe(table) Retrieve a time series table description from the Riak cluster. .. note:: This request is automatically retried :attr:`retries` times if it fails due to network error. :param table: The timeseries table. :type table: string or :class:`Table <riak.table.Table>` :rtype: :class:`TsObject <riak.ts_object.TsObject>` """ t = table if isinstance(t, six.string_types): t = Table(self, table) return transport.ts_describe(t)
def ts_delete(self, transport, table, key): """ ts_delete(table, key) Delete timeseries value by key .. note:: This request is automatically retried :attr:`retries` times if it fails due to network error. :param table: The timeseries table. :type table: string or :class:`Table <riak.table.Table>` :param key: The timeseries value's key. :type key: list or dict :rtype: boolean """ t = table if isinstance(t, six.string_types): t = Table(self, table) return transport.ts_delete(t, key)
def table(self, name): """ Gets the table by the specified name. Tables do not always exist (unlike buckets), but this will always return a :class:`Table <riak.table.Table>` object. :param name: the table name :type name: str :rtype: :class:`Table <riak.table.Table>` """ if not isinstance(name, string_types): raise TypeError('Table name must be a string') if name in self._tables: return self._tables[name] else: table = Table(self, name) self._tables[name] = table return table
def setUpClass(cls): cls.c = RiakPbcCodec() cls.ts0ms = cls.c._unix_time_millis(ts0) if cls.ts0ms != ex0ms: raise AssertionError( 'expected {:d} to equal {:d}'.format(cls.ts0ms, ex0ms)) cls.ts1ms = cls.c._unix_time_millis(ts1) if cls.ts1ms != ex1ms: raise AssertionError( 'expected {:d} to equal {:d}'.format(cls.ts1ms, ex1ms)) cls.rows = [ [bd0, 0, 1.2, ts0, True], [bd1, 3, 4.5, ts1, False] ] cls.test_key = ['hash1', 'user2', ts0] cls.table = Table(None, 'test-table')
def ts_query(self, transport, table, query, interpolations=None): """ ts_query(table, query, interpolations=None) Queries time series data in the Riak cluster. .. note:: This request is automatically retried :attr:`retries` times if it fails due to network error. :param table: The timeseries table. :type table: string or :class:`Table <riak.table.Table>` :param query: The timeseries query. :type query: string :rtype: :class:`TsObject <riak.ts_object.TsObject>` """ t = table if isinstance(t, six.string_types): t = Table(self, table) return transport.ts_query(t, query, interpolations)
def ts_get(self, transport, table, key): """ ts_get(table, key) Retrieve timeseries value by key .. note:: This request is automatically retried :attr:`retries` times if it fails due to network error. :param table: The timeseries table. :type table: string or :class:`Table <riak.table.Table>` :param key: The timeseries value's key. :type key: list :rtype: :class:`TsObject <riak.ts_object.TsObject>` """ t = table if isinstance(t, string_types): t = Table(self, table) return transport.ts_get(t, key)
def test_create_error_via_put(self): table = Table(self.client, table_name) ts_obj = table.new([]) with self.assertRaises(RiakError): ts_obj.store()
def test_get_description_via_table(self): table = Table(self.client, 'GeoCheckin') ts_obj = table.describe() self.assertIsNotNone(ts_obj) self.assertEqual(len(ts_obj.columns), 5) self.assertEqual(len(ts_obj.rows), 5)
def test_get_single_value_via_table(self): key = ['hash1', 'user2', self.fiveMinsAgo] table = Table(self.client, table_name) ts_obj = table.get(key) self.assertIsNotNone(ts_obj) self.validate_data(ts_obj)
def test_get_description_via_table(self): table = Table(self.client, table_name) ts_obj = table.describe() self.assertIsNotNone(ts_obj) self.validate_len(ts_obj, (5, 7, 8))
def test_query_description_via_table(self): query = 'describe {table}' table = Table(self.client, table_name) ts_obj = table.query(query) self.assertIsNotNone(ts_obj) self.validate_len(ts_obj, (5, 7, 8))
def test_stream_keys(self): table = Table(self.client, table_name) streamed_keys = [] for keylist in table.stream_keys(): self.validate_keylist(streamed_keys, keylist) self.assertGreater(len(streamed_keys), 0)
def setUp(self): self.table = Table(None, table_name)