Getting Started with CQLAI
CQLAI is a modern, AI-powered CQL shell for Apache Cassandra that enhances productivity with intelligent query suggestions, data analysis, and seamless import/export capabilities.
What is CQLAI?
Section titled “What is CQLAI?”CQLAI is a next-generation command-line interface for Cassandra that combines:
- Modern CQL Shell - Fast, feature-rich alternative to cqlsh
- AI Assistance - Natural language to CQL translation
- Data Tools - Easy import/export with multiple formats
- Enhanced UX - Syntax highlighting, auto-completion, query history
Installation
Section titled “Installation”Download Binary
Section titled “Download Binary”# Linux (AMD64)curl -L https://github.com/axonops/cqlai/releases/latest/download/cqlai-linux-amd64 -o cqlaichmod +x cqlaisudo mv cqlai /usr/local/bin/
# Linux (ARM64)curl -L https://github.com/axonops/cqlai/releases/latest/download/cqlai-linux-arm64 -o cqlaichmod +x cqlaisudo mv cqlai /usr/local/bin/
# macOS (Intel)curl -L https://github.com/axonops/cqlai/releases/latest/download/cqlai-darwin-amd64 -o cqlaichmod +x cqlaisudo mv cqlai /usr/local/bin/
# macOS (Apple Silicon)curl -L https://github.com/axonops/cqlai/releases/latest/download/cqlai-darwin-arm64 -o cqlaichmod +x cqlaisudo mv cqlai /usr/local/bin/Using Homebrew (macOS)
Section titled “Using Homebrew (macOS)”brew install axonops/tap/cqlaiVerify Installation
Section titled “Verify Installation”cqlai --versionQuick Start
Section titled “Quick Start”Connect to Cassandra
Section titled “Connect to Cassandra”# Local connection (default: localhost:9042)cqlai
# Specify host and portcqlai -h 192.168.1.10 -p 9042
# With authenticationcqlai -h 192.168.1.10 -u cassandra -p cassandra
# Connect to specific keyspacecqlai -h 192.168.1.10 -k my_keyspaceBasic Commands
Section titled “Basic Commands”-- List keyspacesDESCRIBE KEYSPACES;
-- Use a keyspaceUSE my_keyspace;
-- List tablesDESCRIBE TABLES;
-- Run a querySELECT * FROM users LIMIT 10;
-- ExitEXIT;AI Features
Section titled “AI Features”Natural Language Queries
Section titled “Natural Language Queries”# Enable AI mode with providercqlai --ai-provider openai --ai-key YOUR_API_KEY
# Or set environment variableexport CQLAI_AI_PROVIDER=openaiexport CQLAI_AI_KEY=YOUR_API_KEYcqlaiAsk AI
Section titled “Ask AI”cqlai> .ai show me all users who signed up last month
Generated CQL:SELECT * FROM usersWHERE created_at >= '2024-11-01' AND created_at < '2024-12-01'ALLOW FILTERING;
Execute? [Y/n]:Schema Suggestions
Section titled “Schema Suggestions”cqlai> .ai suggest a schema for storing IoT sensor data
Suggested schema:CREATE TABLE sensor_readings ( sensor_id text, bucket text, reading_time timestamp, temperature double, humidity double, PRIMARY KEY ((sensor_id, bucket), reading_time)) WITH CLUSTERING ORDER BY (reading_time DESC);
Explanation:- Partition by sensor_id and time bucket for even distribution- Cluster by time for efficient range queries- Descending order for latest-first queriesData Import/Export
Section titled “Data Import/Export”Export Data
Section titled “Export Data”# Export to CSVcqlai> .export users /tmp/users.csv
# Export to JSONcqlai> .export users /tmp/users.json --format json
# Export query resultscqlai> .export "SELECT * FROM orders WHERE status = 'pending'" /tmp/pending.csvImport Data
Section titled “Import Data”# Import from CSVcqlai> .import /tmp/users.csv users
# Import from JSONcqlai> .import /tmp/users.json users --format json
# Preview before importcqlai> .import /tmp/users.csv users --previewConfiguration
Section titled “Configuration”Configuration File
Section titled “Configuration File”CQLAI supports both JSON and YAML configuration formats:
// ~/.config/cqlai/config.json (or ~/.cqlai.json or ./cqlai.json){ "host": "localhost", "port": 9042, "username": "cassandra", "keyspace": "default_ks", "pageSize": 100, "ai": { "provider": "openai", "model": "gpt-4" }}See Configuration for all available options and file locations.
Environment Variables
Section titled “Environment Variables”# Connectionexport CQLAI_HOST=192.168.1.10export CQLAI_PORT=9042export CQLAI_USERNAME=cassandraexport CQLAI_PASSWORD=secret
# AIexport CQLAI_AI_PROVIDER=openaiexport CQLAI_AI_KEY=sk-...export CQLAI_AI_MODEL=gpt-4Keyboard Shortcuts
Section titled “Keyboard Shortcuts”| Shortcut | Action |
|---|---|
Tab | Auto-complete |
Ctrl+R | Search history |
Ctrl+C | Cancel query |
Ctrl+D | Exit |
Up/Down | Navigate history |
Command Reference
Section titled “Command Reference”| Command | Description |
|---|---|
.help | Show help |
.ai <prompt> | AI natural language query |
.export <table> <file> | Export data |
.import <file> <table> | Import data |
.desc <table> | Describe table |
.clear | Clear screen |
.history | Show command history |
.settings | Show current settings |
Next Steps
Section titled “Next Steps”- Features - Full feature reference
- AI Features - AI capabilities
- Data Import/Export - Data migration
- Configuration - Advanced configuration