示例#1
0
    def get_query_rows(self, job_id, offset=None, limit=None):
        """Retrieve a list of rows from a query table by job id.

        Args:
            job_id: The job id that references a BigQuery query.
            offset: The offset of the rows to pull from BigQuery.
            limit: The number of rows to retrieve from a query table.

        Returns:
            A list of dictionaries that represent table rows.
        """

        job_collection = self.bigquery.jobs()
        query_reply = self._get_query_results(
            job_collection, self.project_id, job_id, offset=offset,
            limit=limit)

        if not query_reply['jobComplete']:
            logger.warning('BigQuery job %s not complete' % job_id)
            raise UnfinishedQueryException()

        schema = query_reply['schema']['fields']
        rows = query_reply.get('rows', [])

        return [self._transform_row(row, schema) for row in rows]
示例#2
0
    def get_query_rows(self, job_id, offset=None, limit=None):
        """Retrieve a list of rows from a query table by job id.

        Args:
            job_id: The job id that references a BigQuery query.
            offset: The offset of the rows to pull from BigQuery.
            limit: The number of rows to retrieve from a query table.

        Returns:
            A list of dictionaries that represent table rows.
        """

        job_collection = self.bigquery.jobs()
        query_reply = self._get_query_results(job_collection,
                                              self.project_id,
                                              job_id,
                                              offset=offset,
                                              limit=limit)

        if not query_reply['jobComplete']:
            logger.warning('BigQuery job %s not complete' % job_id)
            raise UnfinishedQueryException()

        schema = query_reply['schema']['fields']
        rows = query_reply.get('rows', [])

        return [self._transform_row(row, schema) for row in rows]
示例#3
0
    def get_query_schema(self, job_id):
        """Retrieve the schema of a query by job id.

        Args:
            job_id: The job_id that references a BigQuery query.
        Returns:
            A list of dictionaries that represent the schema.
        """

        job_collection = self.bigquery.jobs()
        query_reply = self._get_query_results(
            job_collection, self.project_id, job_id, offset=0, limit=0)

        if not query_reply['jobComplete']:
            logger.warning('BigQuery job %s not complete' % job_id)
            raise UnfinishedQueryException()

        return query_reply['schema']['fields']
示例#4
0
    def get_query_schema(self, job_id):
        """Retrieve the schema of a query by job id.

        Args:
            job_id: The job_id that references a BigQuery query.
        Returns:
            A list of dictionaries that represent the schema.
        """

        job_collection = self.bigquery.jobs()
        query_reply = self._get_query_results(job_collection,
                                              self.project_id,
                                              job_id,
                                              offset=0,
                                              limit=0)

        if not query_reply['jobComplete']:
            logger.warning('BigQuery job %s not complete' % job_id)
            raise UnfinishedQueryException()

        return query_reply['schema']['fields']