Esempio n. 1
0
    def bake_query(self):
        """
        Doing a 2 phase query where we limit the number of series.
        """
        client = utils.get_pydruid_client()
        qry = self.query_obj()
        orig_filter = qry['filter'] if 'filter' in qry else ''
        qry['granularity'] = "all"
        client.groupby(**qry)
        df = client.export_pandas()
        if not df is None:
            dims =  qry['dimensions']
            filters = []
            for index, row in df.iterrows():
                fields = []
                for dim in dims:
                    f = Filter.build_filter(Dimension(dim) == row[dim])
                    fields.append(f)
                if len(fields) > 1:
                    filters.append(Filter.build_filter(Filter(type="and", fields=fields)))
                elif fields:
                    filters.append(fields[0])

            qry = self.query_obj()
            if filters:
                ff = Filter(type="or", fields=filters)
                if not orig_filter:
                    qry['filter'] = ff
                else:
                    qry['filter'] = Filter(type="and", fields=[
                        Filter.build_filter(ff),
                        Filter.build_filter(orig_filter)])
            del qry['limit_spec']
            client.groupby(**qry)
        return client.export_pandas()
Esempio n. 2
0
 def autocomplete(self, datasource, column):
     client = utils.get_pydruid_client()
     top = client.topn(
         datasource=datasource,
         granularity='all',
         intervals='2013-10-04/2020-10-10',
         aggregations={"count": doublesum("count")},
         dimension=column,
         metric='count',
         threshold=1000,
     )
     values = sorted([d[column] for d in top[0]['result']])
     return json.dumps(values)
Esempio n. 3
0
 def autocomplete(self, datasource, column):
     client = utils.get_pydruid_client()
     top = client.topn(
         datasource=datasource,
         granularity='all',
         intervals='2013-10-04/2020-10-10',
         aggregations={"count": doublesum("count")},
         dimension=column,
         metric='count',
         threshold=1000,
     )
     values = sorted([d[column] for d in top[0]['result']])
     return json.dumps(values)
Esempio n. 4
0
    def bake_query(self):
        """
        Doing a 2 phase query where we limit the number of series.
        """
        client = utils.get_pydruid_client()
        qry = self.query_obj()
        orig_filter = qry['filter'] if 'filter' in qry else ''
        qry['granularity'] = "all"
        client.groupby(**qry)
        df = client.export_pandas()
        if not df is None:
            dims = qry['dimensions']
            filters = []
            for index, row in df.iterrows():
                fields = []
                for dim in dims:
                    f = Filter.build_filter(Dimension(dim) == row[dim])
                    fields.append(f)
                if len(fields) > 1:
                    filters.append(
                        Filter.build_filter(Filter(type="and", fields=fields)))
                elif fields:
                    filters.append(fields[0])

            qry = self.query_obj()
            if filters:
                ff = Filter(type="or", fields=filters)
                if not orig_filter:
                    qry['filter'] = ff
                else:
                    qry['filter'] = Filter(type="and",
                                           fields=[
                                               Filter.build_filter(ff),
                                               Filter.build_filter(orig_filter)
                                           ])
            del qry['limit_spec']
            client.groupby(**qry)
        return client.export_pandas()
Esempio n. 5
0
from flask.ext.appbuilder import Model
from datetime import datetime, timedelta
from flask.ext.appbuilder.models.mixins import AuditMixin, FileColumn, ImageColumn
from flask.ext.appbuilder.security.sqla.models import User
from sqlalchemy import Column, Integer, String, ForeignKey, Text, Boolean
from sqlalchemy.orm import relationship
from app import db, utils
from dateutil.parser import parse
import json


client = utils.get_pydruid_client()

class Datasource(Model, AuditMixin):
    __tablename__ = 'datasources'
    id = Column(Integer, primary_key=True)
    datasource_name = Column(String(256), unique=True)
    is_featured = Column(Boolean, default=False)
    is_hidden = Column(Boolean, default=False)
    description = Column(Text)
    default_endpoint = Column(Text)
    user_id = Column(Integer,
        ForeignKey('ab_user.id'))
    owner = relationship('User', backref='datasources', foreign_keys=[user_id])

    @property
    def metrics_combo(self):
        return sorted(
            [(m.metric_name, m.verbose_name) for m in self.metrics],
            key=lambda x: x[1])
Esempio n. 6
0
from flask.ext.appbuilder import Model
from datetime import datetime, timedelta
from flask.ext.appbuilder.models.mixins import AuditMixin, FileColumn, ImageColumn
from flask.ext.appbuilder.security.sqla.models import User
from sqlalchemy import Column, Integer, String, ForeignKey, Text, Boolean
from sqlalchemy.orm import relationship
from app import db, utils
from dateutil.parser import parse
import json

client = utils.get_pydruid_client()


class Datasource(Model, AuditMixin):
    __tablename__ = 'datasources'
    id = Column(Integer, primary_key=True)
    datasource_name = Column(String(256), unique=True)
    is_featured = Column(Boolean, default=False)
    is_hidden = Column(Boolean, default=False)
    description = Column(Text)
    default_endpoint = Column(Text)
    user_id = Column(Integer, ForeignKey('ab_user.id'))
    owner = relationship('User', backref='datasources', foreign_keys=[user_id])

    @property
    def metrics_combo(self):
        return sorted([(m.metric_name, m.verbose_name) for m in self.metrics],
                      key=lambda x: x[1])

    def __repr__(self):
        return self.datasource_name
Esempio n. 7
0
 def get_query(self):
     client = utils.get_pydruid_client()
     client.groupby(**self.query_obj())
     return client.query_dict
Esempio n. 8
0
 def bake_query(self):
     client = utils.get_pydruid_client()
     client.groupby(**self.query_obj())
     return client.export_pandas()
Esempio n. 9
0
 def get_query(self):
     client = utils.get_pydruid_client()
     client.groupby(**self.query_obj())
     return client.query_dict
Esempio n. 10
0
 def bake_query(self):
     client = utils.get_pydruid_client()
     client.groupby(**self.query_obj())
     return client.export_pandas()