A modern, interactive command-line interface for Apache Hive, inspired by
psqlandusql.
- Interactive REPL: Query Hive with an intuitive readline-based interface
- Meta Commands: Browse databases, tables, and schemas with
\d,\dt,\lcommands - Syntax Highlighting: Beautiful SQL syntax highlighting with Pygments
- Auto-completion: Tab-complete tables, columns, and commands
- Multiple Output Formats: Table, CSV, JSON, TSV, and vertical output
- Variable Substitution: Use
:variablesyntax in your queries - Connection Management: Save named connections for quick access
- Configuration: Persistent settings via
config.yaml - History: Query history with
~/.hive-cli-history
pip install hive-cligit clone https://github.com/yourusername/hive-cli.git
cd hive-cli
pip install -e .pip install "hive-cli[kerberos]"# Connect with connection string
hive-cli hive://user:password@host:10000/default
# Or use environment variables
export HIVE_HOST=localhost
export HIVE_PORT=10000
export HIVE_USERNAME=user
export HIVE_PASSWORD=password
hive-clihive-cli -c "SELECT COUNT(*) FROM my_table"hive-cli -f query.sqlhive-cli --output json -c "SELECT * FROM my_table LIMIT 10"Meta commands (backslash commands) provide shortcuts for common operations:
| Command | Description |
|---|---|
\? |
Show help |
\q |
Quit hive-cli |
\c[onnect] [DSN] |
Connect to database |
\d[+] [TABLE] |
Describe table |
\dt [PATTERN] |
List tables |
\dv [PATTERN] |
List views |
\df [PATTERN] |
List functions |
\db [PATTERN] |
List databases |
\l |
List databases (alias) |
\i FILE |
Execute commands from file |
\o [FILE] |
Send output to file |
\set NAME [VALUE] |
Set variable |
\unset NAME |
Unset variable |
| `\timing [on | off]` |
\H |
Toggle HTML output |
| `\x [on | off]` |
Create ~/.config/hive-cli/config.yaml:
# Named connections
connections:
production: hive://user:pass@prod-host:10000/default
development: hive://user:pass@dev-host:10000/default
# Initialization script
init: |
\set PROMPT1 '%S%M%/%R%# '
\set SYNTAX_HL_STYLE monokai
# Output settings
output:
format: table
border: true
time_format: RFC3339
# Behavior
behavior:
timing: true
echo: false
on_error_stop: falsehive://host:port/database
hive://user:pass@host:port/database
hive://user@host:port/database?auth=KERBEROS
hive-cli --output table # Table format (default)
hive-cli --output csv # CSV format
hive-cli --output json # JSON format
hive-cli --output tsv # TSV format
hive-cli --output vertical # Vertical format (like \G in MySQL)
Use variables in your queries:
\set start_date '2024-01-01'
\set end_date '2024-12-31'
SELECT * FROM my_table
WHERE date BETWEEN :'start_date' AND :'end_date';Query history is saved to ~/.hive-cli-history. Use Up/Down arrows to navigate.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.
