Exemplo n.º 1
0
 def _run_test(self, data, query, expect, dimensions):
     new_settings = self.utils.fill_container({
         "query": query,
         "data": data
     },
                                              tjson=True)
     db = FromES(settings=new_settings)
     db.namespaces += [Rename(dimensions=dimensions, source=db)]
     result = db.query(query)
     self.compare_to_expected(query, result, expect)
Exemplo n.º 2
0
class SaveQueries(object):
    @override
    def __init__(self,
                 host,
                 index,
                 type="query",
                 max_size=10,
                 batch_size=10,
                 kwargs=None):
        """
        settings ARE FOR THE ELASTICSEARCH INDEX
        """
        es = Cluster(kwargs).get_or_create_index(schema=convert.json2value(
            convert.value2json(SCHEMA), leaves=True),
                                                 limit_replicas=True,
                                                 kwargs=kwargs)
        #ENSURE THE TYPE EXISTS FOR PROBING
        try:
            es.add({
                "id": "dummy",
                "value": {
                    "hash": "dummy",
                    "create_time": Date.now(),
                    "last_used": Date.now(),
                    "query": {}
                }
            })
        except Exception, e:
            Log.warning("Problem saving query", cause=e)
        es.add_alias(es.settings.alias)
        es.flush()
        self.queue = es.threaded_queue(max_size=max_size,
                                       batch_size=batch_size,
                                       period=1)
        self.es = FromES(es.settings)
Exemplo n.º 3
0
    def test_rename_edge_to_struct(self):
        query = {
            "from": TEST_TABLE,
            "edges": ["w"],
            "format": "table"
        }

        self.utils.fill_container({"query":query, "data": deep_test_data})
        db = FromES(settings=base_test_case.settings.backend_es)
        db.namespaces += [Rename(dimensions={"name": "w", "fields": {"a": "a.v", "b": "a.b"}}), Typed()]
        result = db.query(query)
        self.compare_to_expected(query, result, {
            "header": ["w.a", "w.b", "count"],
            "data": [
                [2, "x", 1],
                [5, "x", 1],
                [7, "x", 1],
                [NULL, NULL, 1]
            ]
        })
Exemplo n.º 4
0
class FromESTester(object):
    def __init__(self, index):
        self.es = FakeES({
            "host":"example.com",
            "index":"index"
        })
        self.esq = FromES(self.es)

    def query(self, query):
        try:
            with self.esq:
                self.esq.query(query)
                return None
        except Exception, e:
            f = Except(ERROR, unicode(e), trace=extract_tb(1))
            try:
                details = str(f)
                query = convert.json2value(strings.between(details, ">>>>", "<<<<"))
                return query
            except Exception, g:
                Log.error("problem", f)
Exemplo n.º 5
0
 def __init__(self, index):
     self.es = FakeES({
         "host":"example.com",
         "index":"index"
     })
     self.esq = FromES(self.es)