googleapis / java-bigtable

Apache License 2.0
71 stars 86 forks source link

BigTable: Having 3 cells in a row does not return the 3rd cell when calling getCells(family, qualifier) #2194

Closed derkd closed 5 months ago

derkd commented 5 months ago

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ..."). General, Core, and Other are also allowed as types
  2. OS type and version: OSX
  3. Java version: 21
  4. bigtable version(s): 2.35.1

Steps to reproduce

In my test I'm having a list of 3 RowCells with the same family but a different qualifier. I'm calling the getCells from the Row.java

  1. RowCell1: family pfeed, qualifier new_pfeed
  2. RowCell2: family pfeed, qualifier picks_pfeed
  3. RowCell3: family pfeed, qualifier pfeed

I would expect that when I call getCells("pfeed", "pfeed") I would get the third one but instead if gives no results.

Code example

The problem is in this piece of code in Row , when high=3 it will never compares the third cell

private int getFirst(@Nonnull String family, @Nullable ByteString qualifier) {
    int low = 0;
    int high = getCells().size();
    int index = -1;

    while (low < high) {
      int mid = (high + low) / 2;
      RowCell midCell = getCells().get(mid);

      int c = midCell.getFamily().compareTo(family);
      if (c == 0 && qualifier != null) {
        c = ByteStringComparator.INSTANCE.compare(midCell.getQualifier(), qualifier);
      }

      if (c < 0) {
        low = mid + 1;
      } else if (c == 0) {
        index = mid;
        high = mid;
      } else {
        high = mid;
      }
    }
    return index;
  }
derkd commented 5 months ago

I created the row myself in a unit test and there this logic won't stand but it does work in an integration test so I guess this is a non issue.