Bird
Raised Fist0
Hadoopdata~10 mins

CRUD operations in HBase in Hadoop - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - CRUD operations in HBase
Start
↓
Create Table
↓
Insert Data (Put)
↓
Read Data (Get/Scan)
↓
Update Data (Put)
↓
Delete Data (Delete)
↓
End
This flow shows the main steps of CRUD in HBase: create a table, insert data, read data, update data, and delete data.
Execution Sample
Hadoop
create 'users', 'info'
put 'users', 'row1', 'info:name', 'Alice'
get 'users', 'row1'
put 'users', 'row1', 'info:name', 'Alicia'
get 'users', 'row1'
delete 'users', 'row1', 'info:name'
get 'users', 'row1'
This code creates a table, inserts a row, reads it, updates the row, reads again, and then deletes the cell followed by a final read.
Execution Table
StepCommandActionResult
1create 'users', 'info'Create table 'users' with column family 'info'Table 'users' created
2put 'users', 'row1', 'info:name', 'Alice'Insert 'Alice' into 'row1' under 'info:name'Data inserted
3get 'users', 'row1'Read data from 'row1'{'info:name' => 'Alice'}
4put 'users', 'row1', 'info:name', 'Alicia'Update 'info:name' in 'row1' to 'Alicia'Data updated
5get 'users', 'row1'Read updated data from 'row1'{'info:name' => 'Alicia'}
6delete 'users', 'row1', 'info:name'Delete 'info:name' from 'row1'Data deleted
7get 'users', 'row1'Read data from 'row1' after deletion{}
💡 All CRUD operations completed; final get shows empty result after deletion.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
Table 'users'Not createdCreatedCreatedCreatedCreated
Row 'row1' dataEmpty{'info:name': 'Alice'}{'info:name': 'Alicia'}{}{}
Key Moments - 2 Insights
Why does the 'get' command after deletion return an empty result?
Because the 'delete' command removed the 'info:name' cell from 'row1', so no data remains to retrieve, as shown in execution_table step 7.
Is 'put' used for both inserting and updating data?
Yes, 'put' inserts data if the cell is empty or updates it if the cell already exists, as seen in steps 2 and 4 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what data is returned by the 'get' command?
A{'info:name' => 'Alice'}
B{}
C{'info:name' => 'Alicia'}
DError: No such row
💡 Hint
Refer to execution_table row 3 under 'Result' column.
At which step does the data in 'row1' change from 'Alice' to 'Alicia'?
AStep 2
BStep 4
CStep 6
DStep 7
💡 Hint
Check execution_table steps 2 and 4 for 'put' commands and their results.
If we skip the delete command at step 6, what would the final 'get' at step 7 return?
A{}
B{'info:name' => 'Alice'}
C{'info:name' => 'Alicia'}
DError: Table not found
💡 Hint
Look at variable_tracker for 'Row row1 data' after step 4 and consider no deletion happened.
Concept Snapshot
CRUD in HBase:
- Create table: create 'table', 'family'
- Insert/Update: put 'table', 'row', 'family:qualifier', 'value'
- Read: get 'table', 'row'
- Delete: delete 'table', 'row', 'family:qualifier'
- 'put' works for insert and update
- 'get' returns current data or empty if none
Full Transcript
This visual execution shows CRUD operations in HBase. First, we create a table named 'users' with a column family 'info'. Then, we insert data into row 'row1' under 'info:name' with value 'Alice'. Next, we read the data from 'row1' and see 'Alice'. We update the same cell to 'Alicia' using another put command. Reading again shows the updated value. Then, we delete the cell 'info:name' from 'row1'. Finally, reading after deletion returns empty data. The variable tracker shows the table creation and how the row data changes after each operation. Key moments clarify that 'put' is used for both insert and update, and that deletion removes data so 'get' returns empty. The quiz tests understanding of data changes and command effects. This step-by-step trace helps beginners see exactly how HBase CRUD commands work.

Practice

(1/5)
1. Which HBase operation is used to retrieve data from a table?
easy
A. Get
B. Put
C. Delete
D. Scan

Solution

  1. Step 1: Understand HBase CRUD operations

    HBase uses Get to read data, Put to create or update, Delete to remove, and Scan to read multiple rows.
  2. Step 2: Identify the read operation

    Get is the specific operation to retrieve data for a single row.
  3. Final Answer:

    Get -> Option A
  4. Quick Check:

    Read = Get [OK]
Hint: Remember: Get = Read, Put = Create/Update [OK]
Common Mistakes:
  • Confusing Put with Get
  • Using Delete to read data
  • Thinking Scan is for single row read
2. Which of the following is the correct syntax to insert data into HBase using Java API?
easy
A. Delete delete = new Delete(Bytes.toBytes("row1")); table.put(delete);
B. Get get = new Get(Bytes.toBytes("row1")); table.put(get);
C. Put put = new Put(Bytes.toBytes("row1")); put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual"), Bytes.toBytes("value")); table.put(put);
D. Put put = new Put("row1"); put.add("cf", "qual", "value"); table.get(put);

Solution

  1. Step 1: Review correct Put syntax in HBase Java API

    Put requires a row key as bytes, then addColumn with column family, qualifier, and value as bytes, then call table.put(put).
  2. Step 2: Check each option

    Put put = new Put(Bytes.toBytes("row1")); put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual"), Bytes.toBytes("value")); table.put(put); matches correct syntax. Get get = new Get(Bytes.toBytes("row1")); table.put(get); wrongly uses Get with put. Delete delete = new Delete(Bytes.toBytes("row1")); table.put(delete); uses Delete with put. Put put = new Put("row1"); put.add("cf", "qual", "value"); table.get(put); uses wrong constructors and methods.
  3. Final Answer:

    Put put = new Put(Bytes.toBytes("row1")); put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual"), Bytes.toBytes("value")); table.put(put); -> Option C
  4. Quick Check:

    Put syntax correct = Put put = new Put(Bytes.toBytes("row1")); put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual"), Bytes.toBytes("value")); table.put(put); [OK]
Hint: Put needs Bytes.toBytes for all keys and values [OK]
Common Mistakes:
  • Using Get or Delete with put()
  • Not converting strings to bytes
  • Wrong method names like add() instead of addColumn()
3. What will be the output of the following HBase Java code snippet?
Put put = new Put(Bytes.toBytes("row1"));
put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("name"), Bytes.toBytes("Alice"));
table.put(put);

Get get = new Get(Bytes.toBytes("row1"));
Result result = table.get(get);
byte[] value = result.getValue(Bytes.toBytes("cf"), Bytes.toBytes("name"));
System.out.println(Bytes.toString(value));
medium
A. Compilation Error
B. null
C. cf:name
D. Alice

Solution

  1. Step 1: Insert data with Put operation

    The code puts value "Alice" in column family "cf" and qualifier "name" for row "row1".
  2. Step 2: Retrieve data with Get operation

    The Get fetches the row "row1" and extracts the value for "cf:name" which is "Alice".
  3. Final Answer:

    Alice -> Option D
  4. Quick Check:

    Put then Get returns inserted value [OK]
Hint: Put then Get returns inserted value exactly [OK]
Common Mistakes:
  • Expecting null if not flushed
  • Confusing column family and qualifier
  • Forgetting to convert bytes to string
4. Identify the error in the following HBase delete operation code snippet:
Delete delete = new Delete("row1");
delete.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual"));
table.delete(delete);
medium
A. Delete constructor argument should be bytes, not string
B. addColumn method is deprecated, should use addColumns
C. table.delete() method does not exist
D. No error, code is correct

Solution

  1. Step 1: Check Delete constructor parameter type

    The Delete constructor requires a byte array for the row key, not a plain string.
  2. Step 2: Verify method usage

    addColumn is valid for deleting a specific column. table.delete() is correct method.
  3. Final Answer:

    Delete constructor argument should be bytes, not string -> Option A
  4. Quick Check:

    Delete row key must be bytes [OK]
Hint: Always convert row keys to bytes in HBase operations [OK]
Common Mistakes:
  • Passing string directly instead of bytes
  • Confusing addColumn with addColumns
  • Thinking table.delete() is invalid
5. You want to update the value of a column "status" in column family "info" for row "user123" in HBase. Which sequence of operations is correct to ensure the update is saved and can be read back immediately?
hard
A. Create a Delete for the old value, call table.delete(delete), then create a Put with new value and call table.put(put)
B. Create a Put with new value, call table.put(put), then call table.get(get) to read updated value
C. Call table.get(get) first, then create a Put with new value and call table.put(put)
D. Create a Put with new value, call table.get(get), then call table.put(put)

Solution

  1. Step 1: Use Put to update the column value

    In HBase, Put operation overwrites existing values for the same column, so create a Put with the new "status" value for "user123".
  2. Step 2: Save and verify update

    Call table.put(put) to save the update, then use table.get(get) to read back the updated value immediately.
  3. Final Answer:

    Create a Put with new value, call table.put(put), then call table.get(get) to read updated value -> Option B
  4. Quick Check:

    Put updates value, Get reads updated value [OK]
Hint: Put overwrites; Get reads latest value after put [OK]
Common Mistakes:
  • Deleting before putting is unnecessary
  • Getting before putting returns old value
  • Calling get before put misses update
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard