Command recall map
Answer First: Choose the command family by the system boundary you are inspecting: hdfs dfs for namespace data operations, hdfs dfsadmin and fsck for HDFS health, yarn for applications and resources, Beeline/Hive SQL for metadata and queries, and sqoop for legacy RDBMS transfer.
Memory Map: namespace -> blocks -> cluster -> applications -> SQL metadata -> ingestion.
Run destructive commands only after confirming the path, ownership, trash policy, and recovery plan. Examples below retain their operational caveats and expected output.
π Note
Legacy-tool note: Apache Sqoop was retired to the Apache Attic in 2021. The Sqoop section is retained for operating and migrating existing estates; prefer a supported connector or ingestion service for new systems.
Canonical source guide
Merged from HD_04_Commands_Reference.md; the legacy source remains unchanged.
Hadoop Commands Reference β Interview Quick-Fire Guide
β οΈ Common Trap
Purpose: Every command interviewers test, with real examples and traps to avoid
Interviewers expect you to type these from memory
Levels: β¬ Direct (what/define) | π¨ Mid-level (how/why) | π₯ Scenario (debug/fix)
Format: What it does β Command syntax β Practical example β Interview tip
SECTION 1: HDFS COMMANDS (hadoop fs / hdfs dfs)
Key distinction: hdfs dfs invokes the Hadoop FileSystem shell and is the conventional spelling when working with HDFS. It is not HDFS-only: commands resolve the URI scheme or configured default filesystem, so explicit hdfs://, file://, and supported object-store connectors can be addressed. hadoop fs invokes the same shell and is documented as a synonym for hdfs dfs when HDFS is in use.
ls / ls -R β List files and directories
What it does: Lists files and directories in HDFS, similar to Linux ls.
Syntax:
hdfs dfs -ls <path>
hdfs dfs -ls -R <path>
hdfs dfs -ls -h <path>
Practical example:
hdfs dfs -ls /data/travelco/bookings/
hdfs dfs -ls -R /user/hive/warehouse/bookings_db.db/flights/
hdfs dfs -ls -h /data/travelco/bookings/
Interview tip: The output columns are: permissions, replication factor, owner, group, size (bytes), date, time, path. The replication factor column is what catches people β they forget it's there. Files show replication (e.g., 3), directories show -.
mkdir / mkdir -p β Create directories
What it does: Creates directories in HDFS. -p creates parent directories if they don't exist.
Syntax:
hdfs dfs -mkdir <path>
hdfs dfs -mkdir -p <path>
Practical example:
hdfs dfs -mkdir /data/travelco/
hdfs dfs -mkdir -p /data/travelco/bookings/year=2026/month=03/day=25
hdfs dfs -mkdir -p /data/staging/flights/
hdfs dfs -mkdir -p /data/processed/flights/
Interview tip: Without -p, the command fails if the parent doesn't exist. Always use -p in scripts and pipelines β it's idempotent (safe to run multiple times).
put / copyFromLocal β Upload files to HDFS
What it does: Copies a file from the local filesystem to HDFS. put and copyFromLocal are almost identical; put also reads from stdin.
Syntax:
hdfs dfs -put <localPath> <hdfsPath>
hdfs dfs -copyFromLocal <localPath> <hdfsPath>
hdfs dfs -put -f <localPath> <hdfsPath>
Practical example:
hdfs dfs -put /home/krishna/booking_data.csv /data/travelco/staging/
hdfs dfs -put -f /home/krishna/daily_export.csv /data/travelco/staging/daily_export.csv
hdfs dfs -put /home/krishna/logs/*.log /data/travelco/raw_logs/
Interview tip: put fails if the destination file already exists (unless you use -f). The trap question: "What's the difference between put and copyFromLocal?" Answer: put can also read from stdin (echo "test" | hdfs dfs -put - /data/test.txt), while copyFromLocal only works with local files. In practice, they're interchangeable for file uploads.
get / copyToLocal β Download files from HDFS
What it does: Copies a file from HDFS to the local filesystem.
Syntax:
hdfs dfs -get <hdfsPath> <localPath>
hdfs dfs -copyToLocal <hdfsPath> <localPath>
Practical example:
hdfs dfs -get /data/travelco/reports/monthly_summary.csv /home/krishna/
hdfs dfs -get /data/travelco/bookings/year=2026/month=03/ /home/krishna/march_data/
hdfs dfs -get -f /data/travelco/reports/latest.csv /home/krishna/latest.csv
Interview tip: get downloads to the edge node's local filesystem, not to your laptop. For large files, prefer processing in HDFS rather than downloading β that defeats the purpose of distributed storage.
cat / head / tail β View file content
What it does: Reads and displays file content from HDFS.
Syntax:
hdfs dfs -cat <hdfsPath>
hdfs dfs -head <hdfsPath>
hdfs dfs -tail <hdfsPath>
hdfs dfs -cat <hdfsPath> | head -20
Practical example:
hdfs dfs -cat /data/travelco/config/etl_params.json
hdfs dfs -head /data/travelco/raw_logs/access.log
hdfs dfs -tail /data/travelco/raw_logs/access.log
hdfs dfs -cat /data/travelco/staging/bookings.csv | head -20
Interview tip: NEVER cat a large file (GBs) β it will stream the entire file to your terminal and kill your session. Always pipe to head for large files. head and tail in HDFS show only 1 KB, not lines β different from Linux.
mv / cp β Move and copy within HDFS
What it does: mv moves/renames files within HDFS. cp copies files within HDFS.
Syntax:
hdfs dfs -mv <source> <destination>
hdfs dfs -cp <source> <destination>
Practical example:
hdfs dfs -mv /data/staging/bookings_2026.orc /data/processed/bookings_2026.orc
hdfs dfs -mv /data/travelco/old_name.csv /data/travelco/new_name.csv
hdfs dfs -cp /data/travelco/bookings/current.orc /data/travelco/bookings/backup_current.orc
hdfs dfs -mv /data/staging/batch_20260325/ /data/processed/batch_20260325/
Interview tip: mv within HDFS is a metadata-only operation (instant, no data movement) as long as source and destination are in the same filesystem. cp actually copies the data blocks β slow for large files. This is why Hive partition operations using ALTER TABLE ... SET LOCATION are fast β it's just a metadata change.
rm / rm -r β Delete files and directories
What it does: Deletes files or directories from HDFS. Deleted items go to the HDFS Trash (if enabled).
Syntax:
hdfs dfs -rm <filePath>
hdfs dfs -rm -r <directoryPath>
hdfs dfs -rm -r -skipTrash <path>
hdfs dfs -rm -r -f <path>
Practical example:
hdfs dfs -rm /data/staging/temp_file.csv
hdfs dfs -rm -r /data/staging/batch_20260324/
hdfs dfs -rm -r -skipTrash /data/old_logs/2024/
hdfs dfs -rm -r -f /data/staging/temp_dir/
Interview tip: By default, deleted files go to /user//.Trash/. The Trash auto-purge interval is set by fs.trash.interval in core-site.xml (default: 0 = disabled, common setting: 1440 = 24 hours). If the cluster is running low on space, use -skipTrash. Interview trap: "A DataNode disk is 95% full but you deleted files yesterday β why?" Answer: files are still in Trash.
du / du -s / du -h β Disk usage
What it does: Shows disk space used by files and directories in HDFS.
Syntax:
hdfs dfs -du <path>
hdfs dfs -du -s <path>
hdfs dfs -du -s -h <path>
Practical example:
hdfs dfs -du -h /data/travelco/
hdfs dfs -du -s -h /data/travelco/bookings/
hdfs dfs -du -h /user/hive/warehouse/bookings_db.db/flights/year=2026/
Interview tip: du shows TWO numbers: raw file size and actual disk consumed (raw x replication factor). If replication=3, the second number is 3x the first. Interviewers ask: "Your HDFS is 80% full but data is only 10 TB β why?" Answer: with replication 3, 10 TB actually consumes 30 TB of disk.
chmod / chown β Permissions management
What it does: Changes file/directory permissions (chmod) or ownership (chown) in HDFS.
Syntax:
hdfs dfs -chmod <permissions> <path>
hdfs dfs -chmod -R <permissions> <path>
hdfs dfs -chown <owner>:<group> <path>
hdfs dfs -chown -R <owner>:<group> <path>
Practical example:
hdfs dfs -chmod 755 /data/travelco/bookings/
hdfs dfs -chmod -R 770 /user/hive/warehouse/bookings_db.db/
hdfs dfs -chown -R hive:hadoop /user/hive/warehouse/bookings_db.db/
hdfs dfs -chown etl_user:etl_group /data/staging/
hdfs dfs -chmod 750 /data/staging/
Interview tip: HDFS permissions work like POSIX (Unix) permissions but with an important difference: there's no setuid/setgid concept. Also, HDFS has ACLs (Access Control Lists) for fine-grained permissions beyond the basic owner/group/others model. In production, Apache Ranger is used instead of raw chmod/chown for enterprise authorization.
count β File and directory count
What it does: Counts the number of directories, files, and total bytes under a path.
Syntax:
hdfs dfs -count <path>
hdfs dfs -count -q <path>
hdfs dfs -count -h <path>
Practical example:
hdfs dfs -count /user/hive/warehouse/bookings_db.db/flights/
hdfs dfs -count -h /user/hive/warehouse/bookings_db.db/flights/
hdfs dfs -count -q -h /data/travelco/
Interview tip: This is the go-to command for detecting the small files problem. If count shows 100,000 files but only 5 GB total, you have a small files problem (average file size = 50 KB, should be 128-256 MB). Each file consumes ~150 bytes of NameNode memory, so 100 million small files can crash the NameNode.
stat β File statistics
What it does: Displays statistics about a file or directory in a custom format.
Syntax:
hdfs dfs -stat <format> <path>
Practical example:
hdfs dfs -stat %r /data/travelco/bookings/booking_2026.orc
hdfs dfs -stat %o /data/travelco/bookings/booking_2026.orc
hdfs dfs -stat "%b %y" /data/travelco/bookings/booking_2026.orc
hdfs dfs -stat "%n: replication=%r, blocksize=%o" /data/travelco/bookings/booking_2026.orc
Interview tip: Use stat to quickly verify replication factor and block size during troubleshooting. If a critical file has replication=1, it's a single point of failure. Default block size is 128 MB (Hadoop 2+), was 64 MB in Hadoop 1.
touchz β Create empty file
What it does: Creates a zero-length (empty) file in HDFS. Fails if the file already exists.
Syntax:
Practical example:
hdfs dfs -touchz /data/travelco/bookings/year=2026/month=03/day=25/_SUCCESS
hdfs dfs -touchz /data/travelco/locks/daily_etl.lock
hdfs dfs -touchz /data/staging/batch_complete_20260325
Interview tip: touchz is commonly used to create _SUCCESS flag files that signal job completion. Oozie and custom ETL pipelines check for these files before triggering downstream jobs. Unlike Linux touch, HDFS touchz fails if the file already exists β it's NOT idempotent.
setrep β Set replication factor
What it does: Changes the replication factor of a file or directory in HDFS.
Syntax:
hdfs dfs -setrep <replication> <path>
hdfs dfs -setrep -R <replication> <path>
hdfs dfs -setrep -w <replication> <path>
Practical example:
hdfs dfs -setrep 5 /data/travelco/bookings/current_month.orc
hdfs dfs -setrep -R 2 /data/travelco/archive/2024/
hdfs dfs -setrep -w 3 /data/travelco/bookings/today.orc
hdfs dfs -setrep -R 1 /data/staging/
Interview tip: Changing replication factor is async β the command returns immediately but blocks are replicated/removed in the background. Use -w to wait. Interview question: "How do you handle hot vs cold data in HDFS?" Answer: hot data at replication 3, cold/archive data at replication 2, staging at replication 1. In Hadoop 3, use erasure coding instead of reducing replication β it gives fault tolerance with only 1.5x overhead vs 3x.
getmerge β Merge HDFS files to local
What it does: Merges multiple HDFS files into a single local file. Useful for exporting MapReduce/Hive output.
Syntax:
hdfs dfs -getmerge <hdfsDir> <localFile>
hdfs dfs -getmerge -nl <hdfsDir> <localFile>
Practical example:
hdfs dfs -getmerge /output/job_20260325/ /home/krishna/merged_output.csv
hdfs dfs -getmerge /user/hive/warehouse/temp_results/ /home/krishna/query_results.txt
hdfs dfs -getmerge -nl /output/daily_reports/ /home/krishna/full_report.csv
Interview tip: getmerge downloads to the LOCAL filesystem, not HDFS. It's useful for getting MapReduce/Hive output that's split across many part-00000, part-00001 files into one usable file. Warning: don't use this on huge directories β it's pulling everything to one machine.
fsck β Filesystem check
What it does: Checks the health of the HDFS filesystem, reports missing blocks, under-replicated blocks, and corrupt files.
Syntax:
hdfs fsck <path> [options]
hdfs fsck <path> -files
hdfs fsck <path> -blocks
hdfs fsck <path> -locations
hdfs fsck <path> -racks
hdfs fsck <path> -files -blocks -locations
Practical example:
hdfs fsck /
hdfs fsck /data/travelco/bookings/ -files -blocks -locations
hdfs fsck /data/travelco/bookings/booking_2026.orc -files -blocks -locations
hdfs fsck / -list-corruptfileblocks
Interview tip: hdfs fsck is THE command for diagnosing data loss and under-replication. If you see "Missing blocks" > 0, data is potentially lost. "Under-replicated" means blocks have fewer copies than the replication factor β not yet lost but at risk. Interviewers love: "You get an alert that HDFS has missing blocks β what do you do?" Answer: run fsck, identify affected files, check DataNode health with dfsadmin -report, check DataNode logs for disk failures.
balancer β Rebalance blocks across DataNodes
What it does: Redistributes blocks across DataNodes to achieve even disk usage. Required after adding new nodes or when some nodes are significantly fuller than others.
Syntax:
hdfs balancer
hdfs balancer -threshold <percentage>
hdfs balancer -policy datanode
Practical example:
hdfs balancer
hdfs balancer -threshold 5
hdfs balancer -threshold 10
hdfs dfsadmin -report | grep "DFS Used%"
Interview tip: The balancer runs as a background process and is bandwidth-limited to avoid saturating the network. Default bandwidth is 10 MB/s per DataNode (dfs.datanode.balance.bandwidthPerSec). Interview question: "You added 10 new DataNodes but new data still goes to old nodes β why?" Answer: existing data is not automatically rebalanced. New writes are balanced, but you need to run the balancer for existing data. Also, HDFS prefers writing to local DataNode first (data locality), so new data naturally goes to wherever the writers run.
dfsadmin -report β Cluster health report
What it does: Displays a comprehensive report of the HDFS cluster including capacity, usage, and DataNode status.
Syntax:
hdfs dfsadmin -report
hdfs dfsadmin -report -live
hdfs dfsadmin -report -dead
Practical example:
hdfs dfsadmin -report
hdfs dfsadmin -report -dead
Interview tip: This is the FIRST command you run when troubleshooting any HDFS issue. It shows you dead DataNodes, disk usage, under-replicated blocks β everything at a glance. Interviewers ask: "How do you monitor HDFS health?" Answer: dfsadmin -report for manual checks, plus Ambari/Cloudera Manager/Grafana dashboards for continuous monitoring with alerting on missing blocks, capacity thresholds, and dead DataNodes.
dfsadmin -safemode β Safe mode operations
What it does: Safe mode is a read-only state where HDFS doesn't allow any modifications. NameNode enters safe mode on startup until enough DataNodes report their blocks.
Syntax:
hdfs dfsadmin -safemode get
hdfs dfsadmin -safemode enter
hdfs dfsadmin -safemode leave
hdfs dfsadmin -safemode wait
Practical example:
hdfs dfsadmin -safemode get
hdfs dfsadmin -safemode enter
hdfs dfsadmin -safemode leave
hdfs dfsadmin -safemode wait
echo "HDFS is ready, starting ETL jobs..."
Interview tip: NameNode auto-enters safe mode on startup and waits until 99.9% of blocks are reported by DataNodes (configurable via dfs.namenode.safemode.threshold-pct). Classic interview scenario: "Your ETL job fails with 'Cannot create file, NameNode is in safe mode' β what happened?" Answer: the NameNode restarted (or is still starting up), or someone manually entered safe mode for maintenance. Fix: check why NameNode restarted, wait for safe mode to auto-exit, or manually leave with safemode leave (only if you understand why it was in safe mode).
SECTION 2: YARN COMMANDS
YARN = Yet Another Resource Negotiator. It manages cluster resources (CPU + memory) across all applications.
yarn application -list β List running applications
What it does: Lists all running (or filtered by state) YARN applications.
Syntax:
yarn application -list
yarn application -list -appStates ALL
yarn application -list -appStates FINISHED
yarn application -list -appStates FAILED,KILLED
yarn application -list -appTypes SPARK
Practical example:
yarn application -list
yarn application -list -appStates FINISHED
yarn application -list -appStates FAILED -appTypes SPARK
Interview tip: This is your first command when the cluster seems slow β check if rogue applications are consuming all resources. Look for apps stuck at 0% progress (possible data skew or deadlock) or apps running for hours in a queue that should take minutes.
yarn application -status β Application details
What it does: Shows detailed status of a specific YARN application.
Syntax:
yarn application -status <applicationId>
Practical example:
yarn application -status application_1711350000000_0042
Interview tip: Key things to check: the Queue (is it in the right queue?), Allocated Resources (is it hogging too much?), Running Containers (are they as expected?), and Start-Time (has it been running too long?). If Final-Status is UNDEFINED while State is RUNNING, the job is still in progress.
yarn application -kill β Kill an application
What it does: Forcefully kills a running YARN application.
Syntax:
yarn application -kill <applicationId>
Practical example:
yarn application -kill application_1711350000000_0042
for app_id in $(yarn application -list -appStates RUNNING | grep "stuck_job" | awk '{print $1}'); do
yarn application -kill $app_id
done
Interview tip: You need sufficient permissions to kill an application β either be the owner or have admin rights. In a production environment, always check what the application is doing BEFORE killing it. Killing a Hive INSERT OVERWRITE mid-way can leave partial data. Interview scenario: "A Spark job is using 80% of cluster resources and blocking other jobs β what do you do?" Answer: check the queue configuration first (Capacity Scheduler limits), then kill if necessary, then fix the root cause (add resource limits, use separate queues).
yarn logs β Application logs
What it does: Retrieves logs for a completed or running YARN application.
Syntax:
yarn logs -applicationId <appId>
yarn logs -applicationId <appId> -containerId <containerId>
yarn logs -applicationId <appId> -nodeAddress <nodeAddress>
yarn logs -applicationId <appId> -log_files stderr
Practical example:
yarn logs -applicationId application_1711350000000_0042 > /home/krishna/job_logs.txt
yarn logs -applicationId application_1711350000000_0042 -log_files stderr
yarn logs -applicationId application_1711350000000_0042 \
-containerId container_1711350000000_0042_01_000005
yarn logs -applicationId application_1711350000000_0042 \
-nodeAddress datanode15.cluster.local:8041
Interview tip: Logs are available AFTER the application finishes (unless log aggregation is enabled). Log aggregation (yarn.log-aggregation-enable=true) collects logs from all NodeManagers and stores them in HDFS (/app-logs/ by default). Without log aggregation, you must SSH to each NodeManager to read logs. Interview trap: "Your Spark job failed yesterday but you can't find the logs β why?" Answer: log aggregation might be disabled, or the aggregated logs have been cleaned up (check yarn.log-aggregation.retain-seconds).
yarn node -list β List cluster nodes
What it does: Lists all NodeManagers in the YARN cluster with their status and resources.
Syntax:
yarn node -list
yarn node -list -states RUNNING
yarn node -list -all
Practical example:
yarn node -list -states RUNNING
yarn node -list -all
Interview tip: Healthy NodeManagers regularly heartbeat to the ResourceManager. If a NodeManager stops heartbeating past the configured expiry interval, the ResourceManager marks it LOST and reports its containers as completed/lost. Replacement behavior is application-specific: retry policy belongs to the framework-specific ApplicationMaster, which may request new containers and relaunch task attempts. MapReduce does this for eligible failed attempts; other applications may not. The scheduler does not automatically restart arbitrary work or guarantee recovery by itself.
What it does: Shows the status and resource allocation of a specific YARN queue.
Syntax:
yarn queue -status <queueName>
Practical example:
yarn queue -status production
yarn queue -status adhoc
Interview tip: Queue configuration is how enterprises control resource sharing. Capacity Scheduler (default in HDP) defines percentage-based queues. Fair Scheduler (default in CDH) shares resources equally. Interview question: "How do you prevent one team from monopolizing cluster resources?" Answer: configure separate queues with capacity limits (e.g., production=60%, analytics=30%, adhoc=10%) and set maximum-capacity to prevent elastic growth beyond a threshold.
yarn top β Resource usage overview
What it does: Shows real-time cluster resource usage, similar to Linux top.
Syntax:
Practical example:
Interview tip: yarn top gives you the real-time bird's eye view. If memory usage is at 95%, new applications will be queued (pending). If vCores are maxed out, jobs will run but slower. The balance between memory and vCores matters β you can have free memory but no vCores, or vice versa.
SECTION 3: HIVE COMMANDS (beeline / hive CLI)
π Note
Note: The hive CLI is deprecated since Hive 2.0. Use beeline for all production work.
beeline connects to HiveServer2 via JDBC, supports authentication and concurrent sessions.
beeline β Connection string
What it does: Connects to HiveServer2 for executing Hive queries.
Syntax:
beeline -u "jdbc:hive2://<host>:<port>/<database>"
beeline -u "jdbc:hive2://<host>:<port>/<database>" -n <username> -p <password>
beeline -u "jdbc:hive2://<host>:10000/default" --hiveconf hive.execution.engine=tez
Practical example:
beeline -u "jdbc:hive2://hiveserver.cluster.local:10000/default"
beeline -u "jdbc:hive2://hiveserver.cluster.local:10000/default;principal=hive/_HOST@REALM.COM"
beeline -u "jdbc:hive2://hiveserver.cluster.local:10000/default" \
-e "SELECT count(*) FROM bookings WHERE year=2026"
beeline -u "jdbc:hive2://hiveserver.cluster.local:10000/default" \
-f /home/krishna/etl_daily.hql
Interview tip: beeline vs hive CLI β know the difference. hive CLI runs an embedded Metastore and doesn't go through HiveServer2, so it bypasses security (no authentication). beeline connects via JDBC to HiveServer2, supports Kerberos, LDAP, and concurrent users. In interviews, always say you use beeline.
What it does: Explores databases, tables, and schema metadata.
Syntax:
SHOW DATABASES;
SHOW TABLES;
SHOW TABLES IN <database>;
DESCRIBE <table>;
DESCRIBE FORMATTED <table>;
DESCRIBE EXTENDED <table>;
SHOW PARTITIONS <table>;
SHOW CREATE TABLE <table>;
Practical example:
SHOW DATABASES;
USE bookings_db;
SHOW TABLES;
DESCRIBE flights;
DESCRIBE FORMATTED flights;
SHOW PARTITIONS flights;
SHOW CREATE TABLE flights;
Interview tip: DESCRIBE FORMATTED is the most powerful metadata command β it shows the HDFS location, file format (ORC/Parquet), SerDe, partition columns, and whether it's MANAGED or EXTERNAL. Interview question: "How do you find where a Hive table's data is stored?" Answer: DESCRIBE FORMATTED table_name β look for the Location field.
CREATE TABLE β Internal, external, partitioned, bucketed
What it does: Creates Hive tables with various storage configurations.
Syntax and examples:
CREATE TABLE bookings (
booking_id BIGINT,
passenger STRING,
flight_code STRING,
amount DOUBLE,
booking_time TIMESTAMP
)
STORED AS ORC
TBLPROPERTIES ('orc.compress'='SNAPPY');
CREATE EXTERNAL TABLE flights_raw (
flight_id INT,
origin STRING,
destination STRING,
departure STRING
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE
LOCATION '/data/travelco/raw/flights/';
CREATE EXTERNAL TABLE bookings_partitioned (
booking_id BIGINT,
passenger STRING,
flight_code STRING,
amount DOUBLE
)
PARTITIONED BY (year INT, month INT, day INT)
STORED AS ORC
LOCATION '/data/travelco/bookings/';
CREATE TABLE bookings_bucketed (
booking_id BIGINT,
passenger STRING,
flight_code STRING,
amount DOUBLE
)
CLUSTERED BY (booking_id) INTO 32 BUCKETS
STORED AS ORC;
Interview tip: The #1 Hive interview question: "Internal vs External table β when to use which?" Answer: Use EXTERNAL for raw/shared data (dropping table won't delete data, safe for multiple consumers). Use INTERNAL/MANAGED for intermediate/temp tables where Hive should manage lifecycle. In production, 90% of tables are EXTERNAL. Bucketing: use when you frequently join two large tables on the same key β bucketed tables enable bucket map join (no shuffle).
LOAD DATA / INSERT β Loading data into tables
What it does: Loads data from files or query results into Hive tables.
Syntax:
LOAD DATA INPATH '<hdfs_path>' INTO TABLE <table>;
LOAD DATA INPATH '<hdfs_path>' OVERWRITE INTO TABLE <table>;
LOAD DATA LOCAL INPATH '<local_path>' INTO TABLE <table>;
INSERT INTO TABLE <target> SELECT * FROM <source>;
INSERT OVERWRITE TABLE <target> SELECT * FROM <source>;
INSERT OVERWRITE TABLE bookings PARTITION (year, month, day)
SELECT booking_id, passenger, flight_code, amount, year, month, day
FROM staging_bookings;
Practical example:
LOAD DATA INPATH '/data/staging/bookings_20260325.csv' INTO TABLE bookings_raw;
LOAD DATA LOCAL INPATH '/home/krishna/test_data.csv' INTO TABLE test_table;
SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
INSERT OVERWRITE TABLE bookings_orc PARTITION (year, month)
SELECT
booking_id, passenger, flight_code, amount,
year(booking_time) AS year,
month(booking_time) AS month
FROM bookings_raw
WHERE booking_date = '2026-03-25';
INSERT OVERWRITE TABLE bookings_orc PARTITION (year=2026, month=3)
SELECT booking_id, passenger, flight_code, amount
FROM bookings_raw
WHERE year(booking_time) = 2026 AND month(booking_time) = 3;
Interview tip: LOAD DATA INPATH MOVES the file (not copies) β the source file is gone after the load. Use LOAD DATA LOCAL INPATH to copy from local. INSERT OVERWRITE with a partition spec only overwrites THAT partition, not the entire table. Dynamic partitioning requires hive.exec.dynamic.partition.mode=nonstrict β without this, Hive requires at least one static partition. Interview trap: "Your INSERT OVERWRITE deleted all data instead of just one partition" β you forgot the PARTITION clause.
ALTER TABLE β Modify table structure
What it does: Modifies table schema, properties, partitions, or location.
Syntax and examples:
ALTER TABLE bookings ADD PARTITION (year=2026, month=3, day=25)
LOCATION '/data/travelco/bookings/year=2026/month=03/day=25';
ALTER TABLE bookings DROP PARTITION (year=2024, month=1);
ALTER TABLE old_bookings RENAME TO bookings_archive;
ALTER TABLE bookings ADD COLUMNS (loyalty_tier STRING);
ALTER TABLE bookings CHANGE old_column_name new_column_name BIGINT;
ALTER TABLE bookings SET TBLPROPERTIES ('orc.compress'='ZLIB');
ALTER TABLE bookings SET LOCATION '/data/travelco/bookings_v2/';
Interview tip: Adding partitions with ALTER TABLE ADD PARTITION is called static partitioning β you manually define each partition. This is needed when data is already in HDFS but Hive doesn't know about it. More common: use MSCK REPAIR TABLE to auto-discover all partitions. ALTER TABLE on an external table only changes metadata β the data in HDFS is untouched.
MSCK REPAIR TABLE β Sync partitions
What it does: Scans the HDFS directory structure and automatically adds any partitions that exist in HDFS but not in the Hive Metastore.
Syntax:
MSCK REPAIR TABLE <table>;
Practical example:
MSCK REPAIR TABLE bookings;
SHOW PARTITIONS bookings;
Interview tip: MSCK REPAIR TABLE is essential when external tools (Spark, Sqoop, manual hdfs dfs -put) create partition directories without going through Hive. It only ADDS partitions β it does NOT remove partitions whose HDFS directories were deleted. For large tables with thousands of partitions, MSCK REPAIR can be slow β prefer ALTER TABLE ADD PARTITION for specific partitions. Interview question: "Spark wrote data to HDFS but Hive query returns 0 rows β why?" Answer: partitions not registered in Metastore. Fix: MSCK REPAIR TABLE.
EXPLAIN β Query execution plan
What it does: Shows the execution plan of a Hive query without running it. Essential for optimization.
Syntax:
EXPLAIN <query>;
EXPLAIN EXTENDED <query>;
EXPLAIN FORMATTED <query>;
Practical example:
EXPLAIN
SELECT b.booking_id, f.origin, f.destination
FROM bookings b
JOIN flights f ON b.flight_code = f.flight_code
WHERE b.year = 2026 AND b.month = 3;
EXPLAIN
SELECT count(*) FROM bookings WHERE year = 2026;
Interview tip: Always EXPLAIN before running expensive queries. Look for: (1) partition pruning β is Hive scanning only needed partitions? (2) join strategy β map join (broadcast) vs reduce join (shuffle). (3) number of stages β fewer stages = faster. Interview scenario: "Your Hive query scans 5 TB but should only scan 50 GB β what's wrong?" Answer: run EXPLAIN, check if partition pruning is happening. If WHERE clause uses a function on the partition column (e.g., WHERE year(dt) = 2026 instead of WHERE year = 2026), Hive can't do partition pruning.
SET β Configuration at runtime
What it does: Sets Hive configuration parameters for the current session.
Key settings for interviews:
SET hive.execution.engine=tez;
SET hive.vectorized.execution.enabled=true;
SET hive.vectorized.execution.reduce.enabled=true;
SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
SET hive.auto.convert.join=true;
SET hive.mapjoin.smalltable.filesize=25000000;
SET hive.cbo.enable=true;
SET hive.compute.query.using.stats=true;
SET hive.stats.fetch.column.stats=true;
SET hive.exec.compress.output=true;
SET mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;
SET hive.exec.parallel=true;
SET hive.exec.parallel.thread.number=8;
Interview tip: The top 3 Hive performance settings interviewers expect you to know: (1) hive.execution.engine=tez β switch from MapReduce to Tez, (2) vectorized execution β processes batches of 1024 rows, (3) CBO with ANALYZE TABLE for statistics. These three alone can improve query performance by 10-50x.
SECTION 4: SQOOP COMMANDS
Sqoop = SQL-to-Hadoop. Imports data from RDBMS (Oracle, MySQL, PostgreSQL) into HDFS/Hive and exports back.
Uses MapReduce under the hood for parallel data transfer.
sqoop import β Basic import
What it does: Imports a table from an RDBMS into HDFS or Hive.
Syntax and examples:
sqoop import \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--table bookings \
--target-dir /data/travelco/sqoop_import/bookings/ \
--as-avrodatafile \
--num-mappers 8
sqoop import \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--table bookings \
--hive-import \
--hive-table bookings_db.bookings_raw \
--hive-overwrite \
--num-mappers 8
sqoop import \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--table bookings \
--where "booking_date >= '2026-03-01'" \
--target-dir /data/travelco/sqoop_import/bookings_march/ \
--num-mappers 4
sqoop import \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--query "SELECT b.*, f.origin, f.destination FROM bookings b JOIN flights f ON b.flight_code = f.flight_code WHERE \$CONDITIONS" \
--split-by b.booking_id \
--target-dir /data/travelco/sqoop_import/enriched_bookings/ \
--num-mappers 8
Interview tip: --split-by determines how Sqoop parallelizes the import. By default, it uses the primary key. If no primary key, you MUST specify --split-by or use --num-mappers 1. The --split-by column should be numeric and evenly distributed β if it's skewed (e.g., 90% of values in one range), most mappers will be idle. With --query, you must include WHERE $CONDITIONS β Sqoop replaces this with range conditions for each mapper. Always use --password-file instead of --password to avoid credentials in process listings.
sqoop import --incremental β Incremental imports
What it does: Imports only new or modified rows, not the entire table.
Syntax:
sqoop import \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--table bookings \
--incremental append \
--check-column booking_id \
--last-value 1000000 \
--target-dir /data/travelco/sqoop_import/bookings/ \
--num-mappers 4
sqoop import \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--table bookings \
--incremental lastmodified \
--check-column updated_at \
--last-value "2026-03-24 00:00:00" \
--target-dir /data/travelco/sqoop_import/bookings/ \
--merge-key booking_id \
--num-mappers 4
Interview tip: Two modes β know the difference: append is for INSERT-only tables (new rows have higher ID, no updates). lastmodified is for tables with updates (uses a timestamp column). append just adds new files to HDFS. lastmodified with --merge-key does a MapReduce merge of old and new data β slower but handles updates. Interview question: "How do you do incremental loads from Oracle to HDFS?" Answer: Sqoop --incremental lastmodified with --check-column on updated_at and --merge-key on primary key. Store --last-value in a Sqoop job or external metadata table.
sqoop export β Export to RDBMS
What it does: Exports data from HDFS/Hive back to an RDBMS table.
Syntax:
sqoop export \
--connect jdbc:mysql://db.travelco.local:3306/reports_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--table daily_summary \
--export-dir /data/travelco/reports/daily_summary/ \
--input-fields-terminated-by ',' \
--num-mappers 4
sqoop export \
--connect jdbc:mysql://db.travelco.local:3306/reports_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--table booking_metrics \
--export-dir /user/hive/warehouse/bookings_db.db/booking_metrics/ \
--update-key booking_date \
--update-mode allowinsert \
--num-mappers 4
Interview tip: By default, Sqoop export does INSERT. If the target table has a unique key constraint and a row already exists, the export FAILS. Use --update-key with --update-mode allowinsert for upsert behavior. Sqoop export is NOT atomic β if it fails halfway, partial data is already in the RDBMS. Solution: export to a staging table, then do a SQL INSERT INTO final_table SELECT * FROM staging_table in a transaction.
sqoop eval β Test connection and run queries
What it does: Executes a SQL query on the source database. Used to test connectivity and verify schemas before import.
Syntax:
sqoop eval \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--query "SELECT count(*) FROM bookings"
Practical example:
sqoop eval \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--query "SELECT 1"
sqoop eval \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--query "SELECT count(*) FROM bookings WHERE booking_date = '2026-03-25'"
sqoop eval \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password \
--query "DESCRIBE bookings"
Interview tip: Always run sqoop eval first to verify: (1) network connectivity to the database, (2) credentials work, (3) the table exists and schema is as expected. This saves you from debugging a failed 2-hour import that failed in the first second due to wrong credentials.
sqoop list-databases / list-tables β Discovery
What it does: Lists available databases or tables in the source RDBMS.
Syntax:
sqoop list-databases \
--connect jdbc:mysql://db.travelco.local:3306/ \
--username etl_user \
--password-file /home/krishna/.sqoop_password
sqoop list-tables \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password
Practical example:
sqoop list-databases \
--connect jdbc:mysql://db.travelco.local:3306/ \
--username etl_user \
--password-file /home/krishna/.sqoop_password
sqoop list-tables \
--connect jdbc:mysql://db.travelco.local:3306/bookings_db \
--username etl_user \
--password-file /home/krishna/.sqoop_password
Interview tip: These commands are useful during the discovery phase of a migration project. When migrating an entire Oracle/MySQL database to Hadoop, first run list-tables to inventory everything, then plan imports table by table with appropriate --split-by columns and file formats.
SECTION 5: QUICK-FIRE INTERVIEW QUESTIONS
π‘ Interview Tip
These are rapid-fire questions interviewers ask to check your hands-on experience.
Answer in 1-2 sentences + the exact command.
Q1: How do you check HDFS cluster health?
Answer: Run hdfs dfsadmin -report β it shows total capacity, used space, remaining space, number of live/dead DataNodes, under-replicated blocks, and missing blocks. For a quick filesystem integrity check, run hdfs fsck /.
hdfs dfsadmin -report
hdfs fsck /
Q2: How do you find which DataNode a specific block is on?
Answer: Use hdfs fsck with the -files -blocks -locations flags on the specific file. It shows every block ID and the DataNodes holding each replica.
hdfs fsck /data/travelco/bookings/booking_2026.orc -files -blocks -locations
Q3: How do you check if NameNode is in safe mode?
Answer: Run hdfs dfsadmin -safemode get. If it returns "Safe mode is ON", no write operations are allowed. The NameNode auto-enters safe mode on startup until enough blocks are reported.
hdfs dfsadmin -safemode get
hdfs dfsadmin -safemode leave
Q4: How do you decommission a DataNode?
Answer: Decommissioning is a graceful removal β HDFS first replicates all blocks from that node to other nodes before shutting it down. This ensures no data loss.
echo "datanode15.cluster.local" >> /etc/hadoop/conf/dfs.exclude
hdfs dfsadmin -refreshNodes
hdfs dfsadmin -report
Key point: Never just shut down a DataNode without decommissioning. If replication factor is 3 and you kill a node, those blocks temporarily have only 2 replicas. If another node dies before HDFS re-replicates, you lose data.
Q5: How do you check YARN resource usage?
Answer: Use yarn top for real-time monitoring, or yarn node -list to see per-node container counts. For queue-level usage, use yarn queue -status .
yarn top
yarn node -list
yarn queue -status production
yarn application -list
Q6: How do you kill a stuck YARN application?
Answer: First identify the application ID with yarn application -list, then kill it with yarn application -kill. Always check what the application is doing before killing it.
yarn application -list
yarn application -kill application_1711350000000_0042
yarn application -status application_1711350000000_0042
Answer: Use SHOW PARTITIONS to list all partitions, and DESCRIBE FORMATTED to see partition columns and table metadata including HDFS location.
SHOW PARTITIONS bookings;
DESCRIBE FORMATTED bookings;
hdfs dfs -ls -R /user/hive/warehouse/bookings_db.db/bookings/ | head -20
hdfs dfs -du -h /user/hive/warehouse/bookings_db.db/bookings/
MEMORY MAP: COMMAND CATEGORIES
HDFS COMMANDS β Remember: "CRUD + Health"
βββββββββββββββββββββββββββββββββββββββββ
C = Create β mkdir, touchz, put/copyFromLocal
R = Read β ls, cat, head, tail, stat, count, du
U = Update β mv, cp, chmod, chown, setrep
D = Delete β rm, rm -r
Health β fsck, balancer, dfsadmin -report, dfsadmin -safemode
YARN COMMANDS β Remember: "LASK-N-Q-T"
βββββββββββββββββββββββββββββββββββββββ
L = List β yarn application -list
A = App status β yarn application -status
S = Stop (kill)β yarn application -kill
K = Know logs β yarn logs -applicationId
N = Nodes β yarn node -list
Q = Queues β yarn queue -status
T = Top β yarn top
HIVE COMMANDS β Remember: "SCALD-ME"
βββββββββββββββββββββββββββββββββββββ
S = Show β SHOW DATABASES, TABLES, PARTITIONS
C = Create β CREATE TABLE (internal, external, partitioned, bucketed)
A = Alter β ALTER TABLE (add partition, rename, add column)
L = Load β LOAD DATA, INSERT INTO, INSERT OVERWRITE
D = Describe β DESCRIBE FORMATTED (the power command)
M = MSCK β MSCK REPAIR TABLE (sync partitions)
E = Explain β EXPLAIN (query plan)
SQOOP COMMANDS β Remember: "I-I-E-E-L"
βββββββββββββββββββββββββββββββββββββββ
I = Import β sqoop import (full table)
I = Incremental β sqoop import
E = Export β sqoop export (HDFS to RDBMS)
E = Eval β sqoop eval (test connection)
L = List β sqoop list-databases, list-tables
β
Pro Tip
Final Interview Tip: When asked "What commands do you use daily?", frame it as a senior engineer:
"On a typical day, I check cluster health with dfsadmin -report, monitor jobs with yarn application -list and yarn top, optimize Hive queries using EXPLAIN, and manage data pipelines that use Sqoop for RDBMS ingestion with incremental loads. For troubleshooting, hdfs fsck and yarn logs are my go-to tools."