Esempio n. 1
0
 def test_chaining(self):
     f1 = key_filter.tokenize("-", 1).eq("2005")
     f2 = key_filter.tokenize("-", 2).eq("05")
     f3 = f1 & f2
     self.assertEqual(
         list(f3), [["and", [["tokenize", "-", 1], ["eq", "2005"]], [["tokenize", "-", 2], ["eq", "05"]]]]
     )
Esempio n. 2
0
 def test_chaining(self):
     f1 = key_filter.tokenize("-", 1).eq("2005")
     f2 = key_filter.tokenize("-", 2).eq("05")
     f3 = f1 & f2
     self.assertEqual(list(f3), [[
         "and", [["tokenize", "-", 1], ["eq", "2005"]],
         [["tokenize", "-", 2], ["eq", "05"]]
     ]])
Esempio n. 3
0
 def get_log_messages(self, items=10, level='INFO'):
     """Get log messages from Riak.
     """
     client = riak.RiakClient(self._host, self._port)
     query = client.add(self._bucket.get_name())
     filters = (key_filter.tokenize('-', 1) + key_filter.less_than(str(time.time()))) \
                 & (key_filter.tokenize('-', 2) + key_filter.eq(level))
     query.add_key_filters(filters)
     query.map_values_json()\
         .reduce_sort('function(a, b) { return b.created - a.created }')\
         .reduce_limit(items)
     for result in query.run():
         yield result
Esempio n. 4
0
    def test_key_filters_f_chain(self):
        bucket = self.client.bucket("kftest")
        bucket.new("basho-20101215", 1).store()
        bucket.new("google-20110103", 2).store()
        bucket.new("yahoo-20090613", 3).store()

        # compose a chain of key filters using f as the root of
        # two filters ANDed together to ensure that f can be the root
        # of multiple chains
        filters = key_filter.tokenize("-", 1).eq("yahoo") & key_filter.tokenize("-", 2).ends_with("0613")

        result = (
            self.client.add("kftest").add_key_filters(filters).map("function (v, keydata) { return [v.key]; }").run()
        )

        self.assertEqual(result, ["yahoo-20090613"])
Esempio n. 5
0
    def test_key_filters_f_chain(self):
        bucket = self.client.bucket("kftest")
        bucket.new("basho-20101215", 1).store()
        bucket.new("google-20110103", 2).store()
        bucket.new("yahoo-20090613", 3).store()

        # compose a chain of key filters using f as the root of
        # two filters ANDed together to ensure that f can be the root
        # of multiple chains
        filters = key_filter.tokenize("-", 1).eq("yahoo") \
            & key_filter.tokenize("-", 2).ends_with("0613")

        result = self.client \
            .add("kftest") \
            .add_key_filters(filters) \
            .map("function (v, keydata) { return [v.key]; }") \
            .run()

        self.assertEqual(result, ["yahoo-20090613"])
Esempio n. 6
0
 def _make_rangefilter(self, filter, values):
     '''
     makes a range filter depending on the filter name and the tuple of
     range values
     date = (20120525, 20120530)
     from 25th may 2012 to 30th may 2012
     '''
     seperator = self.model.key_seperator
     key_index = self.model.key_order.index(filter) + 1
     tokenize_filter = key_filter.tokenize(seperator, key_index)
     if not len(values) == 2:
         raise ValueError('Range Filter takes only two values')
     final = tokenize_filter + key_filter.between(values[0], values[1])
     return final
Esempio n. 7
0
    def _make_orfilter(self, filter, values):
        '''
        it creates an all fitler depending on the param and the list of values.
        site = [1,2,3]
        site in 1 or 2 or 3
        '''
        seperator = self.model.key_seperator
        key_index = self.model.key_order.index(filter) + 1
        tokenize_filter = key_filter.tokenize(seperator, key_index)

        for v in values:
            try:
                filters = filters | key_filter.eq(str(v))
            except NameError:
                filters = key_filter.eq(str(v))

        final = tokenize_filter + filters
        return final