Professional Data Engineer free question 6 / 10 · Domain 3: Storing the data
A Bigtable table holds meter data, and the row key is built as meter type#meter ID#date recorded, such as meter#a7c3e912#20260310. Which statement matches the "Schema design best practices" page?
- If you specify the meter type and the ID, you can fetch those rows as a row range in a single read request, without specifying the date
- Even if the date part is not padded with zeros, Bigtable sorts it numerically, so reads over a date range are not affected
- If you specify the meter type and the date, you can fetch those rows as a row range in a single read request, without specifying the ID
- If you specify the meter ID and the date, you can fetch those rows as a row range in a single read request, without specifying the type
Show the answer and explanation
Answer: A
Why this is correct
The Row keys section says the most efficient Bigtable reads fetch a single row key, a row key prefix, or a range of rows defined by a start and end row key. Any other kind of query results in a full table scan, which is far less efficient. For a row key divided by delimiters, the first delimited value (or the first consecutive set of delimited values) is the prefix. As in the page's example (device type#device ID#date recorded), with a key of type#ID#date you can fetch just the type, or the type and ID together, as a row range in a single request.
Why the other options are wrong
"If you specify the meter type and the date, you can fetch those rows as a row range in a single read request, without specifying the ID" … The type is the first delimited value, so it can be a prefix for a range read, but the date is the third value, at the end of the row key (a suffix). You cannot skip the ID in the middle and define a range by the date. The page says you cannot request a range of rows based only on a trailing or middle delimited value without the first, and that finding rows by the date value needs a filtered read.
"Even if the date part is not padded with zeros, Bigtable sorts it numerically, so reads over a date range are not affected" … The page says Bigtable stores data lexicographically, and gives an example in which, lexicographically, 3 is greater than 20, but 20 is greater than 03. It recommends padding integers with leading zeros so they sort numerically, especially for timestamps you read by range. Without the padding, the date order breaks in range reads.
"If you specify the meter ID and the date, you can fetch those rows as a row range in a single read request, without specifying the type" … The ID is a middle delimited value and the date is the last one, so neither is a row key prefix. You cannot request a range of rows based only on a middle or trailing delimited value without the first, so reading without the type becomes a filtered read that scans the whole table.
Design essentials
The page says to design the row key around the queries you will use to fetch the data, and that it is often best to start with the common values and end with the more granular ones. Choosing the row key correctly now avoids a painful data migration later. If you often read all meters together by date, rethink how you build the row key to fit that read pattern.