Exemple #1
0
def _load_json_schema(filename='data/schema.json'):
    from google.cloud.bigquery.table import _parse_schema_resource

    json_filename = os.path.join(WHERE, filename)

    with open(json_filename, 'r') as schema_file:
        return _parse_schema_resource(json.load(schema_file))
Exemple #2
0
    def schema(self):
        """Schema for query results.

        See:
        https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#schema

        :rtype: list of :class:`SchemaField`, or ``NoneType``
        :returns: fields describing the schema (None until set by the server).
        """
        return _parse_schema_resource(self._properties.get('schema', {}))
    def schema(self):
        """Schema for query results.

        See
        https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#schema

        :rtype: list of :class:`SchemaField`, or ``NoneType``
        :returns: fields describing the schema (None until set by the server).
        """
        return _parse_schema_resource(self._properties.get('schema', {}))
Exemple #4
0
    def schema(self):
        """Schema for query results.

        See
        https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#body.QueryResponse.FIELDS.schema

        Returns:
            Optional[List[SchemaField]]:
                Fields describing the schema (None until set by the server).
        """
        return _parse_schema_resource(self._properties.get("schema", {}))
    def from_api_repr(cls, resource):
        """Factory: construct a CSVOptions given its API representation

        :type resource: dict
        :param resource:
            An extract job configuration in the same representation as is
            returned from the API.

        :rtype: :class:`~google.cloud.bigquery.external_config.CSVOptions`
        :returns: Configuration parsed from ``resource``.
        """
        config = cls(resource['sourceFormat'])
        schema = resource.get('schema')
        for optcls in _OPTION_CLASSES:
            opts = resource.get(optcls._RESOURCE_NAME)
            if opts is not None:
                config._options = optcls.from_api_repr(opts)
                break
        config._properties = copy.deepcopy(resource)
        if schema:
            config.schema = _parse_schema_resource(schema)
        return config
    def from_api_repr(cls, resource):
        """Factory: construct a CSVOptions given its API representation

        :type resource: dict
        :param resource:
            An extract job configuration in the same representation as is
            returned from the API.

        :rtype: :class:`~google.cloud.bigquery.external_config.CSVOptions`
        :returns: Configuration parsed from ``resource``.
        """
        config = cls(resource['sourceFormat'])
        schema = resource.get('schema')
        for optcls in _OPTION_CLASSES:
            opts = resource.get(optcls._RESOURCE_NAME)
            if opts is not None:
                config._options = optcls.from_api_repr(opts)
                break
        config._properties = copy.deepcopy(resource)
        if schema:
            config.schema = _parse_schema_resource(schema)
        return config
Exemple #7
0
 def _scrub_local_properties(self, cleaned):
     """Helper:  handle subclass properties in cleaned."""
     schema = cleaned.pop('schema', {'fields': ()})
     self.schema = _parse_schema_resource(schema)
Exemple #8
0
 def _scrub_local_properties(self, cleaned):
     """Helper:  handle subclass properties in cleaned."""
     schema = cleaned.pop('schema', {'fields': ()})
     self.schema = _parse_schema_resource(schema)