GitHub - sinoyster/hive-cli: A modern, interactive CLI for Apache Hive inspired by psql and usql. Features readline-based REPL, meta commands, syntax highlighting, and multiple output formats. · GitHub
Skip to content

sinoyster/hive-cli

Repository files navigation

hive-cli

A modern, interactive command-line interface for Apache Hive, inspired by psql and usql.

Python Version License Code Style

Features

  • Interactive REPL: Query Hive with an intuitive readline-based interface
  • Meta Commands: Browse databases, tables, and schemas with \d, \dt, \l commands
  • 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 :variable syntax in your queries
  • Connection Management: Save named connections for quick access
  • Configuration: Persistent settings via config.yaml
  • History: Query history with ~/.hive-cli-history

Installation

From PyPI

pip install hive-cli

From Source

git clone https://github.com/yourusername/hive-cli.git
cd hive-cli
pip install -e .

With Kerberos Support

pip install "hive-cli[kerberos]"

Quick Start

Interactive Mode

# 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-cli

Execute Single Command

hive-cli -c "SELECT COUNT(*) FROM my_table"

Execute SQL File

hive-cli -f query.sql

With Custom Output Format

hive-cli --output json -c "SELECT * FROM my_table LIMIT 10"

Meta Commands

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]`

Configuration

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: false

Connection Strings

hive://host:port/database
hive://user:pass@host:port/database
hive://user@host:port/database?auth=KERBEROS

Connection Parameters

Parameter Default Description
host localhost HiveServer2 host
port 10000 HiveServer2 port
database default Default database
auth LDAP Auth mechanism (NOSASL, PLAIN, LDAP, KERBEROS)
username $USER Username
password Password (if required)

Output Formats

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)

Variable Substitution

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';

History

Query history is saved to ~/.hive-cli-history. Use Up/Down arrows to navigate.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE for details.

Acknowledgments

  • Inspired by usql and PostgreSQL's psql
  • Uses PyHive for Hive connectivity
  • Built with click and rich

Links

About

A modern, interactive CLI for Apache Hive inspired by psql and usql. Features readline-based REPL, meta commands, syntax highlighting, and multiple output formats.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages