Complete the code to select the shard key based on user ID.
shard_key = [1]The shard key should be a stable and evenly distributed attribute like user_id to ensure balanced data distribution.
Complete the code to ensure shard key supports range queries.
if shard_key == [1]: enable_range_queries = True
timestamp is suitable for range queries because it represents a continuous timeline.
Fix the error in shard key selection to avoid hotspotting.
shard_key = [1] # Avoid using this key to prevent hotspots
Using a fixed_value as shard key causes all data to go to one shard, creating a hotspot.
Fill both blanks to create a shard key that balances distribution and supports queries.
shard_key = ([1], [2]) # Composite shard key
Combining user_id and timestamp helps balance data and supports range queries.
Fill all three blanks to define shard key selection logic with validation.
def select_shard_key(record): key = record.get([1]) if key is None or not isinstance(key, [2]): raise ValueError('Invalid shard key') return key if key [3] 0 else None
The function gets 'user_id' from the record, checks it is an int, and ensures it is positive with > 0.