Ejemplo n.º 1
0
    def test_read_modify_write_row(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = bigtable_pb2.ReadModifyWriteRowResponse(**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"
        rules = []

        response = client.read_modify_write_row(table_name, row_key, rules)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_pb2.ReadModifyWriteRowRequest(
            table_name=table_name, row_key=row_key, rules=rules
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 2
0
    def test_read_modify_write_row(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = bigtable_pb2.ReadModifyWriteRowResponse(
            **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'
        rules = []

        response = client.read_modify_write_row(table_name, row_key, rules)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_pb2.ReadModifyWriteRowRequest(
            table_name=table_name, row_key=row_key, rules=rules)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def read_modify_write_row(
        self,
        table_name,
        row_key,
        rules,
        app_profile_id=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Modifies a row atomically on the server. The method reads the latest
        existing timestamp and value from the specified columns and writes a new
        entry based on pre-defined read/modify/write rules. The new value for the
        timestamp is the greater of the existing timestamp or the current server
        time. The method returns the new contents of all modified cells.

        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 `rules`:
            >>> rules = []
            >>>
            >>> response = client.read_modify_write_row(table_name, row_key, rules)

        Args:
            table_name (str): The unique name of the table to which the read/modify/write rules 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 read/modify/write rules should be applied.
            rules (list[Union[dict, ~google.cloud.bigtable_v2.types.ReadModifyWriteRule]]): Rules specifying how the specified row's contents are to be transformed
                into writes. Entries are applied in order, meaning that earlier rules will
                affect the results of later ones.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.bigtable_v2.types.ReadModifyWriteRule`
            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.ReadModifyWriteRowResponse` 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 "read_modify_write_row" not in self._inner_api_calls:
            self._inner_api_calls[
                "read_modify_write_row"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.read_modify_write_row,
                    default_retry=self._method_configs["ReadModifyWriteRow"].
                    retry,
                    default_timeout=self._method_configs["ReadModifyWriteRow"].
                    timeout,
                    client_info=self._client_info,
                )

        request = bigtable_pb2.ReadModifyWriteRowRequest(
            table_name=table_name,
            row_key=row_key,
            rules=rules,
            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["read_modify_write_row"](
            request, retry=retry, timeout=timeout, metadata=metadata)
Ejemplo n.º 4
0
    def read_modify_write_row(self,
                              table_name,
                              row_key,
                              rules,
                              app_profile_id=None,
                              retry=google.api_core.gapic_v1.method.DEFAULT,
                              timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Modifies a row atomically on the server. The method reads the latest
        existing timestamp and value from the specified columns and writes a new
        entry based on pre-defined read/modify/write rules. The new value for the
        timestamp is the greater of the existing timestamp or the current server
        time. The method returns the new contents of all modified cells.

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

        Args:
            table_name (str): The unique name of the table to which the read/modify/write rules 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 read/modify/write rules should be applied.
            rules (list[Union[dict, ~google.cloud.bigtable_v2.types.ReadModifyWriteRule]]): Rules specifying how the specified row's contents are to be transformed
                into writes. Entries are applied in order, meaning that earlier rules will
                affect the results of later ones.
                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.bigtable_v2.types.ReadModifyWriteRule`
            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.ReadModifyWriteRowResponse` 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.ReadModifyWriteRowRequest(
            table_name=table_name,
            row_key=row_key,
            rules=rules,
            app_profile_id=app_profile_id,
        )
        return self._read_modify_write_row(
            request, retry=retry, timeout=timeout)