示例#1
0
    def find(cls, dataset, query_args=None, as_cursor=False,
             include_deleted=False):
        """Return observation rows matching parameters.

        :param dataset: Dataset to return rows for.
        :param include_deleted: If True, return delete records, default False.
        :param query_args: An optional QueryArgs to hold the query arguments.

        :raises: `JSONError` if the query could not be parsed.

        :returns: A list of dictionaries matching the passed in `query` and
            other parameters.
        """
        encoding = cls.encoding(dataset) or {}
        query_args = query_args or QueryArgs()

        query_args.query = parse_timestamp_query(query_args.query,
                                                 dataset.schema)
        query_args.encode(encoding, {DATASET_ID: dataset.dataset_id})

        if not include_deleted:
            query = query_args.query
            query[cls.DELETED_AT] = 0
            query_args.query = query

        # exclude deleted at column
        query_args.select = query_args.select or {cls.DELETED_AT: 0}

        distinct = query_args.distinct
        records = super(cls, cls).find(query_args, as_dict=True,
                                       as_cursor=(as_cursor or distinct))

        return records.distinct(encoding.get(distinct, distinct)) if distinct\
            else records
示例#2
0
文件: observation.py 项目: j/bamboo
    def find(cls, dataset, query_args=QueryArgs(), as_cursor=False):
        """Return observation rows matching parameters.

        :param dataset: Dataset to return rows for.
        :param query_args: An optional QueryArgs to hold the query arguments.

        :raises: `JSONError` if the query could not be parsed.

        :returns: A list of dictionaries matching the passed in `query` and
            other parameters.
        """
        query = query_args.query

        if dataset.schema:
            query = parse_timestamp_query(query, dataset.schema)

        query[DATASET_OBSERVATION_ID] = dataset.dataset_observation_id
        query_args.query = query

        return super(cls, cls).find(
            query_args, as_dict=True, as_cursor=as_cursor)
    def find(cls,
             dataset,
             query_args=None,
             as_cursor=False,
             include_deleted=False):
        """Return observation rows matching parameters.

        :param dataset: Dataset to return rows for.
        :param include_deleted: If True, return delete records, default False.
        :param query_args: An optional QueryArgs to hold the query arguments.

        :raises: `JSONError` if the query could not be parsed.

        :returns: A list of dictionaries matching the passed in `query` and
            other parameters.
        """
        encoding = cls.encoding(dataset) or {}
        query_args = query_args or QueryArgs()

        query_args.query = parse_timestamp_query(query_args.query,
                                                 dataset.schema)
        query_args.encode(encoding, {DATASET_ID: dataset.dataset_id})

        if not include_deleted:
            query = query_args.query
            query[cls.DELETED_AT] = 0
            query_args.query = query

        # exclude deleted at column
        query_args.select = query_args.select or {cls.DELETED_AT: 0}

        distinct = query_args.distinct
        records = super(cls, cls).find(query_args,
                                       as_dict=True,
                                       as_cursor=(as_cursor or distinct))

        return records.distinct(encoding.get(distinct, distinct)) if distinct\
            else records
示例#4
0
    def find(cls, dataset, query=None, select=None, limit=0, order_by=None,
             as_cursor=False):
        """Return observation rows matching parameters.

        :param dataset: Dataset to return rows for.
        :param query: Optional query to restrict matching rows to.
        :param select: Optional select to limit returned values.
        :param limit: Limit on the number of returned rows.
        :param order_by: Order parameter for rows.

        :raises: `JSONError` if the query could not be parsed.

        :returns: A list of dictionaries matching the passed in `query` and
            other parameters.
        """
        try:
            query = (query and json.loads(
                query, object_hook=json_util.object_hook)) or {}

            if dataset.schema:
                query = parse_timestamp_query(query, dataset.schema)
        except ValueError, err:
            raise JSONError('cannot decode query: %s' % err.__str__())