B. TypeError because user_id is string and timestamp is int
C. NameError because function is not defined
D. No error, code runs fine
Solution
Step 1: Analyze the function parameters and operation
user_id is a string, timestamp is an integer; adding them directly causes a type error.
Step 2: Understand Python type rules for + operator
Python cannot add string and int directly without conversion.
Final Answer:
TypeError because user_id is string and timestamp is int -> Option B
Quick Check:
String + int without conversion = TypeError [OK]
Hint: Cannot add string and int directly in Python [OK]
Common Mistakes:
Ignoring data types in addition
Assuming implicit conversion
Thinking syntax or name error
5. You want to design a row key for a large Hadoop table storing user activity logs. The goal is to avoid hot-spotting and allow fast range scans by time. Which strategy is best?
hard
A. Use only user ID as the row key
B. Use timestamp as the row key without modification
C. Use a reversed timestamp prefix followed by user ID, like row_key = reversed_timestamp + '_' + user_id
D. Use a random UUID as the row key
Solution
Step 1: Understand hot-spotting and range scan needs
Hot-spotting happens when many writes go to the same key range; reversed timestamp spreads writes.
Step 2: Evaluate each option for balancing and scan speed
Reversed timestamp prefix balances data and allows scanning by time; user ID alone or random UUIDs do not support range scans well.
Final Answer:
Use a reversed timestamp prefix followed by user ID, like row_key = reversed_timestamp + '_' + user_id -> Option C
Quick Check:
Reverse timestamp + user ID = balanced, fast scans [OK]
Hint: Reverse timestamp to avoid hot-spotting [OK]
Common Mistakes:
Using only user ID causes hot-spotting
Using raw timestamp causes write concentration
Random UUIDs prevent range scans
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.