Skip to content

Instantly share code, notes, and snippets.

@kzhangkzhang
Last active November 3, 2018 03:12
Show Gist options
  • Save kzhangkzhang/b6faab34696ffed1e484180fb322955b to your computer and use it in GitHub Desktop.
Save kzhangkzhang/b6faab34696ffed1e484180fb322955b to your computer and use it in GitHub Desktop.
Hive Common Line Cheat Sheet

This document the common usage of the HIVE command line

Run Query

hive -e 'SELECT a.col from tabl1 a'

Run Query in Silent mode

hive -S -e 'SELECT a.col from tabl1 a' > result.txt

Set Hive Configuration Variables

hive -e 'select a.col from tab1 a' -hiveconf hive.root.logger=DEBUG,console

Use Initialization Script

hive -i initialize.hql

Run Non-Interactive Script

hive -f script.hql

Variable Substition (Namespace)

4 namespaces

  • hivevar

    • -d, --define, --hivevar
    • set hivevar:name=value
$hive -d srctable=movies
hive>set hivevar:cond=123;
hive>SELECT a, b, c FROM pluralsight.${hivevar:srctable} WHERE a =${hivevar:cond};

$hive -v -d src=movies -d db=pluralsight -e 'SELECT * FROM \
            ${hivevar:db}.${hivevar:src} LIMIT 100;'

  • hiveconf

    • --hiveconf
    • set hiveconf:property=value
  • system

    • set system:property=value
  • env

    • set env:property=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment