Exemplo n.º 1
0
    def test__filter_row_ranges_all_ranges_added_back(self):
        last_scanned_key = b"row_key14"
        request_manager = self._make_one(self.request, last_scanned_key, 2)
        row_ranges = request_manager._filter_row_ranges()

        exp_row_range1 = data_v2_pb2.RowRange(start_key_closed=b"row_key21",
                                              end_key_open=b"row_key29")
        exp_row_range2 = data_v2_pb2.RowRange(start_key_closed=b"row_key31",
                                              end_key_open=b"row_key39")
        exp_row_range3 = data_v2_pb2.RowRange(start_key_closed=b"row_key41",
                                              end_key_open=b"row_key49")
        exp_row_ranges = [exp_row_range1, exp_row_range2, exp_row_range3]

        self.assertEqual(exp_row_ranges, row_ranges)
Exemplo n.º 2
0
    def build_updated_request(self):
        """Updates the given message request as per last scanned key"""
        r_kwargs = {
            "table_name": self.message.table_name,
            "filter": self.message.filter,
        }

        if self.message.rows_limit != 0:
            r_kwargs["rows_limit"] = max(
                1, self.message.rows_limit - self.rows_read_so_far
            )

        # if neither RowSet.row_keys nor RowSet.row_ranges currently exist,
        # add row_range that starts with last_scanned_key as start_key_open
        # to request only rows that have not been returned yet
        if "rows" not in self.message:
            row_range = data_v2_pb2.RowRange(start_key_open=self.last_scanned_key)
            r_kwargs["rows"] = data_v2_pb2.RowSet(row_ranges=[row_range])
        else:
            row_keys = self._filter_rows_keys()
            row_ranges = self._filter_row_ranges()
            r_kwargs["rows"] = data_v2_pb2.RowSet(
                row_keys=row_keys, row_ranges=row_ranges
            )
        return data_messages_v2_pb2.ReadRowsRequest(**r_kwargs)
Exemplo n.º 3
0
    def test__filter_row_ranges_some_ranges_already_read(self):
        last_scanned_key = b"row_key22"
        request_manager = self._make_one(self.request, last_scanned_key, 2)
        request_manager.new_message = _ReadRowsRequestPB(
            table_name=self.table_name)
        row_ranges = request_manager._filter_row_ranges()

        exp_row_range1 = data_v2_pb2.RowRange(start_key_open=b"row_key22",
                                              end_key_open=b"row_key29")
        exp_row_range2 = data_v2_pb2.RowRange(start_key_closed=b"row_key31",
                                              end_key_open=b"row_key39")
        exp_row_range3 = data_v2_pb2.RowRange(start_key_closed=b"row_key41",
                                              end_key_open=b"row_key49")
        exp_row_ranges = [exp_row_range1, exp_row_range2, exp_row_range3]

        self.assertEqual(exp_row_ranges, row_ranges)
Exemplo n.º 4
0
def test_RRRM__filter_row_ranges_all_ranges_added_back(rrrm_data):
    from google.cloud.bigtable_v2.types import data as data_v2_pb2

    request = rrrm_data["request"]
    last_scanned_key = b"row_key14"
    request_manager = _make_read_rows_request_manager(request,
                                                      last_scanned_key, 2)
    row_ranges = request_manager._filter_row_ranges()

    exp_row_range1 = data_v2_pb2.RowRange(start_key_closed=b"row_key21",
                                          end_key_open=b"row_key29")
    exp_row_range2 = data_v2_pb2.RowRange(start_key_closed=b"row_key31",
                                          end_key_open=b"row_key39")
    exp_row_range3 = data_v2_pb2.RowRange(start_key_closed=b"row_key41",
                                          end_key_open=b"row_key49")
    exp_row_ranges = [exp_row_range1, exp_row_range2, exp_row_range3]

    assert exp_row_ranges == row_ranges
Exemplo n.º 5
0
def test_RRRM__filter_row_ranges_some_ranges_already_read(rrrm_data):
    from google.cloud.bigtable_v2.types import data as data_v2_pb2

    request = rrrm_data["request"]
    last_scanned_key = b"row_key22"
    request_manager = _make_read_rows_request_manager(request,
                                                      last_scanned_key, 2)
    request_manager.new_message = _ReadRowsRequestPB(table_name=TABLE_NAME)
    row_ranges = request_manager._filter_row_ranges()

    exp_row_range1 = data_v2_pb2.RowRange(start_key_open=b"row_key22",
                                          end_key_open=b"row_key29")
    exp_row_range2 = data_v2_pb2.RowRange(start_key_closed=b"row_key31",
                                          end_key_open=b"row_key39")
    exp_row_range3 = data_v2_pb2.RowRange(start_key_closed=b"row_key41",
                                          end_key_open=b"row_key49")
    exp_row_ranges = [exp_row_range1, exp_row_range2, exp_row_range3]

    assert exp_row_ranges == row_ranges