コード例 #1
0
    def test_sample_row_keys(self):
        # Setup Expected Response
        row_key = b"122"
        offset_bytes = 889884095
        expected_response = {"row_key": row_key, "offset_bytes": offset_bytes}
        expected_response = bigtable_pb2.SampleRowKeysResponse(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[iter([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]")

        response = client.sample_row_keys(table_name)
        resources = list(response)
        assert len(resources) == 1
        assert expected_response == resources[0]

        assert len(channel.requests) == 1
        expected_request = bigtable_pb2.SampleRowKeysRequest(table_name=table_name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #2
0
    def test_sample_row_keys(self):
        # Setup Expected Response
        row_key = b'122'
        offset_bytes = 889884095
        expected_response = {'row_key': row_key, 'offset_bytes': offset_bytes}
        expected_response = bigtable_pb2.SampleRowKeysResponse(
            **expected_response)

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

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

        response = client.sample_row_keys(table_name)
        resources = list(response)
        assert len(resources) == 1
        assert expected_response == resources[0]

        assert len(channel.requests) == 1
        expected_request = bigtable_pb2.SampleRowKeysRequest(
            table_name=table_name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #3
0
    def sample_row_keys(self,
                        table_name,
                        app_profile_id=None,
                        retry=google.api_core.gapic_v1.method.DEFAULT,
                        timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Returns a sample of row keys in the table. The returned row keys will
        delimit contiguous sections of the table of approximately equal size,
        which can be used to break up the data for distributed tasks like
        mapreduces.

        Example:
            >>> from google.cloud import bigtable_v2
            >>>
            >>> client = bigtable_v2.BigtableClient()
            >>>
            >>> table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]')
            >>>
            >>> for element in client.sample_row_keys(table_name):
            ...     # process element
            ...     pass

        Args:
            table_name (str): The unique name of the table from which to sample row keys.
                Values are of the form
                ``projects/<project>/instances/<instance>/tables/<table>``.
            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:
            Iterable[~google.cloud.bigtable_v2.types.SampleRowKeysResponse].

        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.SampleRowKeysRequest(
            table_name=table_name,
            app_profile_id=app_profile_id,
        )
        return self._sample_row_keys(request, retry=retry, timeout=timeout)
コード例 #4
0
    def sample_row_keys(
        self,
        table_name,
        app_profile_id=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Returns a sample of row keys in the table. The returned row keys will
        delimit contiguous sections of the table of approximately equal size,
        which can be used to break up the data for distributed tasks like
        mapreduces.

        Example:
            >>> from google.cloud import bigtable_v2
            >>>
            >>> client = bigtable_v2.BigtableClient()
            >>>
            >>> table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]')
            >>>
            >>> for element in client.sample_row_keys(table_name):
            ...     # process element
            ...     pass

        Args:
            table_name (str): The unique name of the table from which to sample row keys. Values are
                of the form ``projects/<project>/instances/<instance>/tables/<table>``.
            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:
            Iterable[~google.cloud.bigtable_v2.types.SampleRowKeysResponse].

        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 "sample_row_keys" not in self._inner_api_calls:
            self._inner_api_calls[
                "sample_row_keys"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.sample_row_keys,
                    default_retry=self._method_configs["SampleRowKeys"].retry,
                    default_timeout=self._method_configs["SampleRowKeys"].
                    timeout,
                    client_info=self._client_info,
                )

        request = bigtable_pb2.SampleRowKeysRequest(
            table_name=table_name, 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["sample_row_keys"](request,
                                                        retry=retry,
                                                        timeout=timeout,
                                                        metadata=metadata)