Example #1
0
def _render_conditions(conditions):
    """Render the conditions part of a query.

    Args:
        conditions: a list of dictionary items to filter a table.
            Each dict should be formatted as {'field': 'start_time',
            'value': {'value': 1, 'negate': False}, 'comparator': '>',
            'type': 'FLOAT'} which is represetned as
            'start_time > FLOAT('1')' in the query.

    Returns:
        a string that represents the where part of a query.
    """

    if not conditions:
        return ""

    rendered_conditions = []

    for condition in conditions:
        field = condition.get('field')
        field_type = condition.get('type')
        comparators = condition.get('comparators')

        if None in (field, field_type, comparators) or not comparators:
            logger.warn('Invalid condition passed in: %s' % condition)
            continue

        rendered_conditions.append(
            _render_condition(field, field_type, comparators))

    if not rendered_conditions:
        return ""

    return "WHERE %s" % (" AND ".join(rendered_conditions))
Example #2
0
    def get_table_schema(self, dataset, table):
        """Return the table schema.

        Args:
            dataset: the dataset containing the table.
            table: the table to get the schema for.

        Returns:
            A list of dicts that represent the table schema. If the table
            doesn't exist, None is returned.
        """

        try:
            result = self.bigquery.tables().get(projectId=self.project_id,
                                                tableId=table,
                                                datasetId=dataset).execute()
        except HttpError, e:
            if int(e.resp['status']) == 404:
                logger.warn('Table %s.%s does not exist', dataset, table)
                return None
            raise
Example #3
0
    def get_table_schema(self, dataset, table):
        """Return the table schema.

        Args:
            dataset: the dataset containing the table.
            table: the table to get the schema for.

        Returns:
            A list of dicts that represent the table schema. If the table
            doesn't exist, None is returned.
        """

        try:
            result = self.bigquery.tables().get(
                projectId=self.project_id,
                tableId=table,
                datasetId=dataset).execute()
        except HttpError, e:
            if int(e.resp['status']) == 404:
                logger.warn('Table %s.%s does not exist', dataset, table)
                return None
            raise