Exemple #1
0
    def build_query(self, query_type, args):
        """
        Build query based on given query type and arguments.

        :param string query_type: a type of query
        :param dict args: the dict of args to be sent
        :return: the resulting query
        :rtype: Query
        """
        query_dict = {'queryType': query_type}

        for key, val in six.iteritems(args):
            if key == 'aggregations':
                query_dict[key] = build_aggregators(val)
            elif key == 'post_aggregations':
                query_dict['postAggregations'] = Postaggregator.build_post_aggregators(val)
            elif key == 'datasource':
                query_dict['dataSource'] = val
            elif key == 'paging_spec':
                query_dict['pagingSpec'] = val
            elif key == 'limit_spec':
                query_dict['limitSpec'] = val
            elif key == "filter":
                query_dict[key] = Filter.build_filter(val)
            elif key == "having":
                query_dict[key] = Having.build_having(val)
            elif key == 'dimension':
                query_dict[key] = build_dimension(val)
            elif key == 'dimensions':
                query_dict[key] = [build_dimension(v) for v in val]
            else:
                query_dict[key] = val

        self.last_query = Query(query_dict, query_type)
        return self.last_query
Exemple #2
0
    def build_query(self, query_type, args):
        """
        Build query based on given query type and arguments.

        :param string query_type: a type of query
        :param dict args: the dict of args to be sent
        :return: the resulting query
        :rtype: Query
        """
        query_dict = {'queryType': query_type}

        for key, val in six.iteritems(args):
            if key == 'aggregations':
                query_dict[key] = build_aggregators(val)
            elif key == 'post_aggregations':
                query_dict['postAggregations'] = Postaggregator.build_post_aggregators(val)
            elif key == 'datasource':
                query_dict['dataSource'] = val
            elif key == 'paging_spec':
                query_dict['pagingSpec'] = val
            elif key == 'limit_spec':
                query_dict['limitSpec'] = val
            elif key == "filter":
                query_dict[key] = Filter.build_filter(val)
            elif key == "having":
                query_dict[key] = Having.build_having(val)
            elif key == 'dimension':
                query_dict[key] = build_dimension(val)
            elif key == 'dimensions':
                query_dict[key] = [build_dimension(v) for v in val]
            else:
                query_dict[key] = val

        self.last_query = Query(query_dict, query_type)
        return self.last_query
Exemple #3
0
    def build_query(self, query_type, args):
        """
        Build query based on given query type and arguments.

        :param string query_type: a type of query
        :param dict args: the dict of args to be sent
        :return: the resulting query
        :rtype: Query
        """
        query_dict = {"queryType": query_type}

        for key, val in six.iteritems(args):
            if key == "aggregations":
                query_dict[key] = build_aggregators(val)
            elif key == "post_aggregations":
                query_dict[
                    "postAggregations"] = Postaggregator.build_post_aggregators(
                        val)
            elif key == "context":
                query_dict["context"] = val
            elif key == "datasource":
                query_dict["dataSource"] = self.parse_datasource(
                    val, query_type)
            elif key == "paging_spec":
                query_dict["pagingSpec"] = val
            elif key == "limit_spec":
                query_dict["limitSpec"] = val
            elif key == "filter" and val is not None:
                query_dict[key] = Filter.build_filter(val)
            elif key == "having" and val is not None:
                query_dict[key] = Having.build_having(val)
            elif key == "dimension" and val is not None:
                query_dict[key] = build_dimension(val)
            elif key == "dimensions":
                query_dict[key] = [build_dimension(v) for v in val]
            else:
                query_dict[key] = val

        self.last_query = Query(query_dict, query_type)
        return self.last_query
Exemple #4
0
    def build_query_dict(self, query_type, args):
        query_dict = {"queryType": query_type}

        for key, val in six.iteritems(args):
            if key == "aggregations":
                query_dict[key] = build_aggregators(val)
            elif key == "post_aggregations":
                query_dict[
                    "postAggregations"] = Postaggregator.build_post_aggregators(
                        val)
            elif key == "context":
                query_dict["context"] = val
            elif key == "datasource":
                query_dict["dataSource"] = self.parse_datasource(
                    val, query_type)
            elif key == "paging_spec":
                query_dict["pagingSpec"] = val
            elif key == "limit_spec":
                query_dict["limitSpec"] = val
            elif key == "filter" and val is not None:
                query_dict[key] = Filter.build_filter(val)
            elif key == "having" and val is not None:
                query_dict[key] = Having.build_having(val)
            elif key == "dimension" and val is not None:
                query_dict[key] = build_dimension(val)
            elif key == "dimensions":
                query_dict[key] = [build_dimension(v) for v in val]
            elif key == 'virtualColumns':
                query_dict[key] = [
                    VirtualColumn.build_virtual_column(v) for v in val
                ]
            elif key == 'sub_query' and val is not None:
                query_dict['dataSource'] = {
                    'type': 'query',
                    'query': self.build_query_dict(query_type, val)
                }
            elif val is not None:
                query_dict[key] = val
        return query_dict
Exemple #5
0
    def test_build_dimension(self):
        assert build_dimension("raw_dim") == "raw_dim"

        dim_spec = DimensionSpec("dim", "out")
        assert build_dimension(dim_spec) == dim_spec.build()
Exemple #6
0
    def test_build_dimension(self):
        assert build_dimension('raw_dim') == 'raw_dim'

        dim_spec = DimensionSpec('dim', 'out')
        assert build_dimension(dim_spec) == dim_spec.build()
Exemple #7
0
    def test_build_dimension(self):
        assert build_dimension('raw_dim') == 'raw_dim'

        dim_spec = DimensionSpec('dim', 'out')
        assert build_dimension(dim_spec) == dim_spec.build()
    def test_build_dimension(self):
        assert build_dimension("raw_dim") == "raw_dim"

        dim_spec = DimensionSpec("dim", "out")
        assert build_dimension(dim_spec) == dim_spec.build()