'Building a query object'

def query_obj(self):

    form_data = self.form_data
    gb = (form_data.get(u'groupby') or [])
    metrics = (form_data.get(u'metrics') or [])
    columns = (form_data.get(u'columns') or [])
    groupby = []
    for o in (gb + columns):
        if (o not in groupby):
            groupby.append(o)
    is_timeseries = self.is_timeseries
    if (DTTM_ALIAS in groupby):
        groupby.remove(DTTM_ALIAS)
        is_timeseries = True
    extra_filters = self.get_extra_filters()
    granularity = (form_data.get(u'granularity') or form_data.get(u'granularity_sqla'))
    limit = int((form_data.get(u'limit') or 0))
    timeseries_limit_metric = form_data.get(u'timeseries_limit_metric')
    row_limit = int((form_data.get(u'row_limit') or config.get(u'ROW_LIMIT')))
    since = (extra_filters.get(u'__from') or form_data.get(u'since') or config.get(u'SUPERSET_DEFAULT_SINCE', u'1    year    ago'))
    from_dttm = utils.parse_human_datetime(since)
    now = datetime.now()
    if (from_dttm > now):
        from_dttm = (now - (from_dttm - now))
    until = (extra_filters.get(u'__to') or form_data.get(u'until', u'now'))
    to_dttm = utils.parse_human_datetime(until)
    if (from_dttm > to_dttm):
        raise Exception(u'From    date    cannot    be    larger    than    to    date')
    extras = {u'where': form_data.get(u'where', u''), u'having': form_data.get(u'having', u''), u'having_druid': (form_data.get(u'having_filters') if (u'having_filters' in form_data) else []), u'time_grain_sqla': form_data.get(u'time_grain_sqla', u''), u'druid_time_origin': form_data.get(u'druid_time_origin', u'')}
    filters = (form_data[u'filters'] if (u'filters' in form_data) else [])
    for (col, vals) in self.get_extra_filters().items():
        if ((not (col and vals)) or col.startswith(u'__')):
            continue
        elif (col in self.datasource.filterable_column_names):
            filters += [{u'col': col, u'op': u'in', u'val': vals}]
    d = {u'granularity': granularity, u'from_dttm': from_dttm, u'to_dttm': to_dttm, u'is_timeseries': is_timeseries, u'groupby': groupby, u'metrics': metrics, u'row_limit': row_limit, u'filter': filters, u'timeseries_limit': limit, u'extras': extras, u'timeseries_limit_metric': timeseries_limit_metric, u'form_data': form_data}
    return d
