def _build_resource(self): """Generate a resource for ``create`` or ``update``.""" resource = { 'tableReference': { 'projectId': self._dataset.project, 'datasetId': self._dataset.name, 'tableId': self.name }, } if self.description is not None: resource['description'] = self.description if self.expires is not None: value = _millis_from_datetime(self.expires) resource['expirationTime'] = value if self.friendly_name is not None: resource['friendlyName'] = self.friendly_name if self.location is not None: resource['location'] = self.location if self.partitioning_type is not None: resource['timePartitioning'] = self._properties['timePartitioning'] if self.view_query is not None: view = resource['view'] = {} view['query'] = self.view_query if self._schema: resource['schema'] = { 'fields': _build_schema_resource(self._schema) } return resource
def _build_resource(self): """Generate a resource for ``create`` or ``update``.""" resource = { 'tableReference': { 'projectId': self._dataset.project, 'datasetId': self._dataset.name, 'tableId': self.name}, } if self.description is not None: resource['description'] = self.description if self.expires is not None: value = _millis_from_datetime(self.expires) resource['expirationTime'] = value if self.friendly_name is not None: resource['friendlyName'] = self.friendly_name if self.location is not None: resource['location'] = self.location if self.partitioning_type is not None: resource['timePartitioning'] = self._properties['timePartitioning'] if self.view_query is not None: view = resource['view'] = {} view['query'] = self.view_query elif self._schema: resource['schema'] = { 'fields': _build_schema_resource(self._schema) } else: raise ValueError("Set either 'view_query' or 'schema'.") return resource
def expires(self, value): """Update datetime at which the table will be removed. :type value: ``datetime.datetime`` :param value: (Optional) the new expiration time, or None """ if not isinstance(value, datetime.datetime) and value is not None: raise ValueError("Pass a datetime, or None") self._properties['expirationTime'] = _millis_from_datetime(value)
def expires(self, value): """Update datetime at which the table will be removed. :type value: ``datetime.datetime``, or ``NoneType`` :param value: the new expiration time, or None """ if not isinstance(value, datetime.datetime) and value is not None: raise ValueError("Pass a datetime, or None") self._properties['expirationTime'] = _millis_from_datetime(value)
def _call_fut(self, value): from google.cloud._helpers import _millis_from_datetime return _millis_from_datetime(value)
def patch(self, client=None, friendly_name=_MARKER, description=_MARKER, location=_MARKER, expires=_MARKER, view_query=_MARKER, schema=_MARKER): """API call: update individual table properties via a PATCH request See https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/patch :type client: :class:`~google.cloud.bigquery.client.Client` or ``NoneType`` :param client: the client to use. If not passed, falls back to the ``client`` stored on the current dataset. :type friendly_name: str :param friendly_name: (Optional) a descriptive name for this table. :type description: str :param description: (Optional) a description of this table. :type location: str :param location: (Optional) the geographic location where the table resides. :type expires: :class:`datetime.datetime` :param expires: (Optional) point in time at which the table expires. :type view_query: str :param view_query: SQL query defining the table as a view :type schema: list of :class:`SchemaField` :param schema: fields describing the schema :raises: ValueError for invalid value types. """ client = self._require_client(client) partial = {} if expires is not _MARKER: if (not isinstance(expires, datetime.datetime) and expires is not None): raise ValueError("Pass a datetime, or None") partial['expirationTime'] = _millis_from_datetime(expires) if description is not _MARKER: partial['description'] = description if friendly_name is not _MARKER: partial['friendlyName'] = friendly_name if location is not _MARKER: partial['location'] = location if view_query is not _MARKER: if view_query is None: partial['view'] = None else: partial['view'] = {'query': view_query} if schema is not _MARKER: if schema is None: partial['schema'] = None else: partial['schema'] = {'fields': _build_schema_resource(schema)} api_response = client._connection.api_request(method='PATCH', path=self.path, data=partial) self._set_properties(api_response)
def _populate_expires_resource(self, resource): resource['expirationTime'] = _millis_from_datetime(self.expires)
def _call_fut(self, value): from google.cloud._helpers import _millis_from_datetime return _millis_from_datetime(value)
def patch(self, client=None, friendly_name=_MARKER, description=_MARKER, location=_MARKER, expires=_MARKER, view_query=_MARKER, schema=_MARKER): """API call: update individual table properties via a PATCH request See https://cloud.google.com/bigquery/docs/reference/v2/tables/patch :type client: :class:`~google.cloud.bigquery.client.Client` or ``NoneType`` :param client: the client to use. If not passed, falls back to the ``client`` stored on the current dataset. :type friendly_name: str or ``NoneType`` :param friendly_name: point in time at which the table expires. :type description: str or ``NoneType`` :param description: point in time at which the table expires. :type location: str or ``NoneType`` :param location: point in time at which the table expires. :type expires: :class:`datetime.datetime` or ``NoneType`` :param expires: point in time at which the table expires. :type view_query: str :param view_query: SQL query defining the table as a view :type schema: list of :class:`SchemaField` :param schema: fields describing the schema :raises: ValueError for invalid value types. """ client = self._require_client(client) partial = {} if expires is not _MARKER: if (not isinstance(expires, datetime.datetime) and expires is not None): raise ValueError("Pass a datetime, or None") partial['expirationTime'] = _millis_from_datetime(expires) if description is not _MARKER: partial['description'] = description if friendly_name is not _MARKER: partial['friendlyName'] = friendly_name if location is not _MARKER: partial['location'] = location if view_query is not _MARKER: if view_query is None: partial['view'] = None else: partial['view'] = {'query': view_query} if schema is not _MARKER: if schema is None: partial['schema'] = None else: partial['schema'] = { 'fields': _build_schema_resource(schema)} api_response = client.connection.api_request( method='PATCH', path=self.path, data=partial) self._set_properties(api_response)
def _populate_expires_resource(self, resource): resource['expirationTime'] = _millis_from_datetime(self.expires)