# Exp 3 - HBase shell
# start: hbase shell        (exit with: exit)
# run whole file: hbase shell commands.txt   (lines starting with # are comments, type exit at end)

status                                                    # servers up / dead
version
list                                                      # all tables

# ---- create (table name + column families) ----
create 'student', 'info', 'marks'
describe 'student'
exists 'student'

# ---- insert: put 'table', 'rowkey', 'family:qualifier', 'value' ----
put 'student', 's1', 'info:name', 'Tanvi'
put 'student', 's1', 'info:city', 'Mumbai'
put 'student', 's1', 'marks:bda', '82'
put 'student', 's1', 'marks:ai',  '76'
put 'student', 's2', 'info:name', 'Omkar'
put 'student', 's2', 'marks:bda', '67'
put 'student', 's3', 'info:name', 'Riya'
put 'student', 's3', 'info:city', 'Pune'
put 'student', 's3', 'marks:bda', '91'

# ---- read ----
get 'student', 's1'                                       # one full row
get 'student', 's1', 'marks'                              # one family
get 'student', 's1', {COLUMN => 'info:name'}              # one cell
scan 'student'                                            # whole table
scan 'student', {COLUMNS => ['info:name', 'marks:bda']}
scan 'student', {STARTROW => 's1', STOPROW => 's3'}       # s1, s2 (stop row not included)
scan 'student', {LIMIT => 2}
scan 'student', {FILTER => "ValueFilter(=, 'binary:Mumbai')"}   # rows having value Mumbai
count 'student'

# ---- update = put again (new version, old one kept as history) ----
alter 'student', {NAME => 'marks', VERSIONS => 3}         # keep 3 versions in marks
put 'student', 's2', 'marks:bda', '72'
put 'student', 's2', 'marks:bda', '75'
get 'student', 's2', {COLUMN => 'marks:bda', VERSIONS => 3}

# ---- delete ----
delete 'student', 's1', 'info:city'                       # one cell
deleteall 'student', 's3'                                 # whole row
scan 'student'

# ---- change schema ----
alter 'student', NAME => 'extra'                          # add family
alter 'student', 'delete' => 'extra'                      # remove family
describe 'student'

# ---- drop (must disable first) ----
disable 'student'
is_disabled 'student'
drop 'student'
list

# ---- viva ----
# hbase = distributed column-family nosql db on top of hdfs, zookeeper coordinates
# gives random real time read/write, hdfs alone only does big sequential reads
# model: table -> row key (sorted) -> column family -> qualifier -> timestamp/version -> value
# families fixed at create, qualifiers added any time -> sparse table
# HMaster assigns regions, RegionServer serves regions (range of row keys)
# write path: WAL + MemStore -> flushed to HFiles on hdfs, compaction merges them
# no sql, no joins. disable before alter/drop so no region server is using it
# CAP: hbase is CP. bloom filters used per HFile to skip files without the row key
