README
¶
Trino CLI
A high-performance, feature-rich terminal user interface for Trino built with Go.
Table of Contents
- Trino CLI
Overview
Trino CLI is a modern terminal-based interface for Trino (formerly PrestoSQL), designed to enhance productivity for data engineers and analysts. It provides a rich interactive experience with features like syntax highlighting, intelligent autocompletion, persistent query history, and an interactive schema browser.
See the docs folder for design goals.
Who is Trino CLI for
- Data Engineers: Streamline SQL workflows without a UI-heavy tool
- Data Scientists: Fetch and analyze data quickly
- BI Analysts: Run and export queries interactively
- DevOps Teams: Integrate Trino queries into automation pipelines
- Enterprise Teams (Planned): Role-based access, secure credential management, and audit logging
Quickstart
# Install Trino CLI
git clone https://github.com/TFMV/trino-cli.git
cd trino-cli
go build -o trino-cli
sudo mv trino-cli /usr/local/bin/
# Verify installation
trino-cli --help
# Create a minimal config file
cat > ~/.trino-cli.yaml << EOF
profiles:
default:
host: localhost
port: 8080
user: user
catalog: default
schema: public
EOF
# Run a test query
trino-cli -e "SELECT 1 AS test"
# Start interactive mode
trino-cli
Examples
The examples directory contains a demonstration of:
- Configuration handling
- Query execution
- Schema metadata browsing
- Query history management
- Result export in multiple formats
See the README in the examples directory for details.
Technology Stack
- Core Language: Go 1.18+
- Terminal UI: tview and tcell
- Database Connectivity: trino-go-client
- Command Line Interface: Cobra
- Configuration: YAML with Viper
- Logging: zap
- Data Formats: Native support for CSV, JSON, Apache Arrow, and Parquet
- Local Storage: SQLite for query history via go-sqlite3
Features
Interactive Query Interface
- Terminal UI with syntax highlighting
- Real-time query execution with progress indicators
- Tabular result display with pagination
Intelligent SQL Autocompletion
- Context-aware suggestions based on query structure
- Schema-aware completions for catalogs, schemas, tables, and columns
- Automatic schema refresh with configurable intervals
- Fuzzy matching algorithm for flexible completions
Persistent Query History
- SQLite-backed storage of executed queries
- Comprehensive metadata including execution time and result size
- Advanced search capabilities with fuzzy matching
- Query replay functionality
Interactive Schema Browser
- TUI-based hierarchical explorer for database objects
- Connection pooling for responsive navigation
- Metadata caching with configurable TTL
- Fuzzy search across all schema objects
Performance Optimizations
- Connection Pooling → Reduces connection overhead by 50% by maintaining a pool of pre-established connections to Trino
- Schema Metadata Caching → Stores schema information locally for 5 minutes, dramatically reducing load times and server load
- Asynchronous Query Execution → Non-blocking execution allows the UI to remain responsive during long-running queries
- Intelligent Refresh Strategies → Only updates schema metadata when needed, minimizing redundant queries
- Efficient Memory Management → Optimized data structures for handling large result sets with minimal memory footprint
- Parallel Query Execution (Planned) → Future support for concurrent query processing to maximize throughput
Export Capabilities
- Multiple formats: CSV, JSON, Arrow, Parquet
- Configurable output destinations
How Does Trino CLI Compare
| Feature | Trino CLI (This Project) | Default Trino CLI | pgcli / mycli |
|---|---|---|---|
| Interactive UI | ✅ Rich TUI with tables & colors | ❌ Basic REPL | ✅ Basic TUI |
| Autocompletion | ✅ Schema-aware with fuzzy search | ❌ No | ✅ Basic schema awareness |
| Query History | ✅ Persistent (SQLite) with search | ✅ Session-only | ✅ Persistent but limited |
| Schema Browser | ✅ Interactive TUI with search | ❌ Basic list commands only | ❌ No |
| Export Formats | ✅ CSV, JSON, Arrow, Parquet | ❌ Text only | ✅ CSV only |
| Performance Optimized | ✅ Connection pooling, caching | ❌ No | ⚠️ Limited |
| Multiple Profiles | ✅ YAML-based profiles | ✅ Command-line only | ✅ Limited |
| Keyboard Shortcuts | ✅ Extensive | ❌ Minimal | ✅ Moderate |
| Result Caching | ✅ Yes | ❌ No | ❌ No |
| Go Implementation | ✅ Yes (fast, low resource usage) | ❌ No (Java-based) | ❌ No (Python-based) |
Performance Benchmarks
Trino CLI is optimized for speed and efficiency:
| Feature | Performance |
|---|---|
| Query Execution | <200ms latency (simple queries) |
| Schema Browser | 5-minute metadata cache reduces load times by 90% |
| Result Caching | Instant replay for cached queries |
| Connection Pooling | 50% lower connection overhead |
| Fuzzy Search | <10ms response time for most schema objects |
Installation
# Clone the repository
git clone https://github.com/TFMV/trino-cli.git
cd trino-cli
# Build the binary
go build -o trino-cli
# Move to a directory in your PATH (optional)
sudo mv trino-cli /usr/local/bin/
Configuration
Create a configuration file at ~/.trino-cli.yaml:
profiles:
default:
host: localhost
port: 8080
user: user
catalog: default
schema: public
prod:
host: trino.production.example.com
port: 443
user: prod_user
catalog: hive
schema: analytics
ssl: true
# Optional advanced connection parameters
connection_timeout: 30s
query_timeout: 5m
max_connections: 10
Usage
Interactive Mode
# Start interactive mode with default profile
trino-cli
# Start with a specific profile
trino-cli --profile prod
The interactive mode provides a full-featured terminal UI with:
- SQL input field with syntax highlighting
- Result display area with tabular formatting
- Status bar showing execution state
- Keyboard shortcuts for common operations
Batch Mode
# Execute a single query and exit
trino-cli -e "SELECT * FROM orders LIMIT 10"
# Execute a query and export results
trino-cli export --format csv "SELECT * FROM users" > users.csv
Query History Management
The CLI maintains a persistent history of all executed queries in a local SQLite database.
# List recent queries
trino-cli history list
# List with pagination
trino-cli history list --limit 50 --offset 10
# Search for queries containing specific terms
trino-cli history search "orders"
# Use fuzzy search for more flexible matching
trino-cli history search "join users" --fuzzy
# Replay a specific query by its ID
trino-cli history replay 1630522845123456789
# Clear query history
trino-cli history clear
# Clear history older than a specific number of days
trino-cli history clear --days 30
Each history entry includes:
| Field | Description |
|---|---|
| Query ID | Unique identifier for the query |
| Timestamp | When the query was executed |
| Profile | Connection profile used |
| Duration | Execution time in milliseconds |
| Row Count | Number of rows returned |
| SQL | The query text |
Schema Browser
The interactive schema browser provides a hierarchical view of your Trino catalogs, schemas, tables, and columns.
# Launch the schema browser
trino-cli schema browse
Key Features:
- Tree-based navigation with keyboard controls
- Metadata display for selected objects
- Fuzzy search for quick object location
- Cached metadata for improved performance
Navigation:
- Arrow keys: Navigate the tree
- Enter: Expand/collapse nodes or load children
- Escape: Exit the browser
- Ctrl+F: Focus the search field
Cache Management
# List cached queries
trino-cli cache list
# Replay a cached query result
trino-cli cache replay query_1234 --pretty
Architecture
The Trino CLI is built with a modular architecture:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Command Layer │────▶│ Service Layer │────▶│ Data Layer │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ UI │ │ Query Engine │ │ Trino Database │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Command Layer: Implements the CLI commands using Cobra
- Service Layer: Contains business logic for features like history, caching, and schema browsing
- Data Layer: Handles database connections and query execution
- UI Layer: Implements the terminal user interface using tview
Key Components
- Schema Browser: Implements a hierarchical tree view with metadata caching
- Query Engine: Manages connections to Trino and executes queries
- History Manager: Stores and retrieves query history from SQLite
- Autocomplete Engine: Provides context-aware SQL suggestions
Development
Prerequisites
- Go 1.18+
- Access to a Trino instance for testing
Building from Source
# Get dependencies
go mod download
# Run tests
go test ./...
# Build
go build -o trino-cli
Code Structure
trino-cli/
├── cmd/ # Command definitions
├── config/ # Configuration handling
├── engine/ # Query execution engine
├── ui/ # Terminal UI components
├── schema/ # Schema browser implementation
├── history/ # Query history management
├── cache/ # Result caching
├── autocomplete/ # SQL autocompletion
└── main.go # Application entry point
Roadmap
Near-term Goals
-
Enhanced SQL Intelligence:
- Improved autocomplete with schema awareness
- Smart query suggestions based on history
- Syntax error detection
-
Visualization Capabilities:
- Terminal-based charts (histograms, bar charts)
- Column metadata previews
Medium-term Goals
-
Advanced Caching:
- Arrow-powered local result storage
- Offline query capability against cached results
- Local joins between cached results
-
Performance Optimizations:
- Connection pooling
- Parallel query execution
- Streaming result processing
Long-term Goals
-
Extended UI Features:
- Multi-line editing with syntax highlighting
- Query plan visualization
-
Enterprise Features:
- Role-based access control integration
- Secure credential management
- Query auditing and logging
Contributing
We welcome any contributions. Please submit a PR.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Documentation
¶
There is no documentation for this package.