Search code examples
selectcassandrapartitioningbigtable

Model `select by partition key in Cassandra` in BigTable


What would the equivalent of modeling a select by partition key in Cassandra be in BigTable?

For example; if I had a Cassandra table

CREATE TABLE emp (
  empID int,
  deptID int,
  first_name varchar,
  last_name varchar,
  PRIMARY KEY (empID, deptID));

I can query

SELECT deptid FROM emp WHERE empid = 104; 

In BigTable; I think this is equivalent to adding columns to a Row? If so is that a relatively standard design pattern?

Or if not; is there another pattern that can be used?

Thanks Brent


Solution

  • This is mostly addressed in the comments. Bigtable does not have separate partition key and primary key concepts and only has a single index.

    Your example you would probably want to make both your employee ID and department ID part of your row key. Keys are stored lexicographically and you can use prefixes to do more efficient subscans, so you would need to determine whether to concatenate either employee ID followed by department ID, or vice versa.

    This is somewhat akin to the reverse domain name pattern and you may want to review the guidance suggested here:

    https://cloud.google.com/bigtable/docs/schema-design#types_of_row_keys