Beispiel #1
0
    def test_mutate_row(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = bigtable_pb2.MutateRowResponse(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = bigtable_v2.BigtableClient()

        # Setup Request
        table_name = client.table_path("[PROJECT]", "[INSTANCE]", "[TABLE]")
        row_key = b"122"
        mutations = []

        response = client.mutate_row(table_name, row_key, mutations)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_pb2.MutateRowRequest(
            table_name=table_name, row_key=row_key, mutations=mutations
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Beispiel #2
0
    def test_mutate_row(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = bigtable_pb2.MutateRowResponse(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = bigtable_v2.BigtableClient(channel=channel)

        # Setup Request
        table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]')
        row_key = b'122'
        mutations = []

        response = client.mutate_row(table_name, row_key, mutations)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_pb2.MutateRowRequest(table_name=table_name,
                                                         row_key=row_key,
                                                         mutations=mutations)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def mutate_row(
        self,
        table_name,
        row_key,
        mutations,
        app_profile_id=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Mutates a row atomically. Cells already present in the row are left
        unchanged unless explicitly changed by ``mutation``.

        Example:
            >>> from google.cloud import bigtable_v2
            >>>
            >>> client = bigtable_v2.BigtableClient()
            >>>
            >>> table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]')
            >>>
            >>> # TODO: Initialize `row_key`:
            >>> row_key = b''
            >>>
            >>> # TODO: Initialize `mutations`:
            >>> mutations = []
            >>>
            >>> response = client.mutate_row(table_name, row_key, mutations)

        Args:
            table_name (str): The unique name of the table to which the mutation should be applied.
                Values are of the form
                ``projects/<project>/instances/<instance>/tables/<table>``.
            row_key (bytes): The key of the row to which the mutation should be applied.
            mutations (list[Union[dict, ~google.cloud.bigtable_v2.types.Mutation]]): Changes to be atomically applied to the specified row. Entries are applied
                in order, meaning that earlier mutations can be masked by later ones.
                Must contain at least one entry and at most 100000.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.bigtable_v2.types.Mutation`
            app_profile_id (str): This value specifies routing for replication. If not specified, the
                "default" application profile will be used.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will
                be retried using a default configuration.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.bigtable_v2.types.MutateRowResponse` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "mutate_row" not in self._inner_api_calls:
            self._inner_api_calls[
                "mutate_row"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.mutate_row,
                    default_retry=self._method_configs["MutateRow"].retry,
                    default_timeout=self._method_configs["MutateRow"].timeout,
                    client_info=self._client_info,
                )

        request = bigtable_pb2.MutateRowRequest(
            table_name=table_name,
            row_key=row_key,
            mutations=mutations,
            app_profile_id=app_profile_id,
        )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("table_name", table_name)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header)
            metadata.append(routing_metadata)

        return self._inner_api_calls["mutate_row"](request,
                                                   retry=retry,
                                                   timeout=timeout,
                                                   metadata=metadata)
Beispiel #4
0
    def mutate_row(self,
                   table_name,
                   row_key,
                   mutations,
                   app_profile_id=None,
                   retry=google.api_core.gapic_v1.method.DEFAULT,
                   timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Mutates a row atomically. Cells already present in the row are left
        unchanged unless explicitly changed by ``mutation``.

        Example:
            >>> from google.cloud import bigtable_v2
            >>>
            >>> client = bigtable_v2.BigtableClient()
            >>>
            >>> table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]')
            >>> row_key = b''
            >>> mutations = []
            >>>
            >>> response = client.mutate_row(table_name, row_key, mutations)

        Args:
            table_name (str): The unique name of the table to which the mutation should be applied.
                Values are of the form
                ``projects/<project>/instances/<instance>/tables/<table>``.
            row_key (bytes): The key of the row to which the mutation should be applied.
            mutations (list[Union[dict, ~google.cloud.bigtable_v2.types.Mutation]]): Changes to be atomically applied to the specified row. Entries are applied
                in order, meaning that earlier mutations can be masked by later ones.
                Must contain at least one entry and at most 100000.
                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.bigtable_v2.types.Mutation`
            app_profile_id (str): This is a private alpha release of Cloud Bigtable replication. This feature
                is not currently available to most Cloud Bigtable customers. This feature
                might be changed in backward-incompatible ways and is not recommended for
                production use. It is not subject to any SLA or deprecation policy.

                This value specifies routing for replication. If not specified, the
                \"default\" application profile will be used.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.

        Returns:
            A :class:`~google.cloud.bigtable_v2.types.MutateRowResponse` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        request = bigtable_pb2.MutateRowRequest(
            table_name=table_name,
            row_key=row_key,
            mutations=mutations,
            app_profile_id=app_profile_id,
        )
        return self._mutate_row(request, retry=retry, timeout=timeout)