CQLAI Data Import/Export
Import and export data using CQLAI with support for multiple formats.
Export Data
Section titled “Export Data”Export Table to CSV
Section titled “Export Table to CSV”cqlai> .export users /tmp/users.csv
Exporting users to /tmp/users.csv...Exported 10,532 rows in 2.3sExport to JSON
Section titled “Export to JSON”cqlai> .export users /tmp/users.json --format json
Exporting users to /tmp/users.json...Exported 10,532 rows in 2.8sExport Query Results
Section titled “Export Query Results”cqlai> .export "SELECT user_id, email FROM users WHERE status = 'active'" /tmp/active_users.csv
Exporting query results to /tmp/active_users.csv...Exported 8,234 rows in 1.9sExport Options
Section titled “Export Options”cqlai> .export users /tmp/users.csv \ --format csv \ --delimiter ";" \ --quote "'" \ --header true \ --null-value "NULL" \ --batch-size 5000| Option | Description | Default |
|---|---|---|
--format | Output format (csv, json, jsonl) | csv |
--delimiter | CSV field delimiter | , |
--quote | CSV quote character | " |
--header | Include header row | true |
--null-value | Representation for NULL | (empty) |
--batch-size | Rows per batch | 1000 |
--compress | Gzip output | false |
Export with Compression
Section titled “Export with Compression”cqlai> .export users /tmp/users.csv.gz --compress
Exporting users to /tmp/users.csv.gz (compressed)...Exported 10,532 rows in 1.8s (compressed 12MB → 2.1MB)Export Specific Columns
Section titled “Export Specific Columns”cqlai> .export "SELECT user_id, username, email FROM users" /tmp/users_subset.csvImport Data
Section titled “Import Data”Import from CSV
Section titled “Import from CSV”cqlai> .import /tmp/users.csv users
Importing /tmp/users.csv into users...Imported 10,532 rows in 4.2sImport from JSON
Section titled “Import from JSON”cqlai> .import /tmp/users.json users --format json
Importing /tmp/users.json into users...Imported 10,532 rows in 5.1sImport Options
Section titled “Import Options”cqlai> .import /tmp/users.csv users \ --format csv \ --delimiter "," \ --skip-header true \ --batch-size 100 \ --consistency LOCAL_QUORUM \ --skip-errors true \ --max-errors 100| Option | Description | Default |
|---|---|---|
--format | Input format (csv, json, jsonl) | auto-detect |
--delimiter | CSV field delimiter | , |
--skip-header | Skip first row | true |
--batch-size | Rows per batch insert | 100 |
--consistency | Write consistency level | LOCAL_ONE |
--skip-errors | Continue on errors | false |
--max-errors | Max errors before abort | 0 (unlimited) |
--dry-run | Validate without inserting | false |
Preview Before Import
Section titled “Preview Before Import”cqlai> .import /tmp/users.csv users --preview
Preview of /tmp/users.csv:
Detected columns: user_id (uuid), username (text), email (text), created_at (timestamp)
Sample rows:┌──────────────────────────────────────┬──────────┬─────────────────────┬─────────────────────┐│ user_id │ username │ email │ created_at │├──────────────────────────────────────┼──────────┼─────────────────────┼─────────────────────┤│ 123e4567-e89b-12d3-a456-426614174000 │ alice │ alice@example.com │ 2024-01-15 10:30:00 ││ 223e4567-e89b-12d3-a456-426614174001 │ bob │ bob@example.com │ 2024-01-16 14:22:00 ││ 323e4567-e89b-12d3-a456-426614174002 │ charlie │ charlie@example.com │ 2024-01-17 09:15:00 │└──────────────────────────────────────┴──────────┴─────────────────────┴─────────────────────┘
Total rows: 10,532Proceed with import? [y/N]:Column Mapping
Section titled “Column Mapping”cqlai> .import /tmp/legacy_users.csv users \ --mapping "id:user_id,name:username,mail:email"
Column mapping: id → user_id name → username mail → emailSupported Formats
Section titled “Supported Formats”user_id,username,email,created_at123e4567-e89b-12d3-a456-426614174000,alice,alice@example.com,2024-01-15T10:30:00Z223e4567-e89b-12d3-a456-426614174001,bob,bob@example.com,2024-01-16T14:22:00ZJSON (Array)
Section titled “JSON (Array)”[ { "user_id": "123e4567-e89b-12d3-a456-426614174000", "username": "alice", "email": "alice@example.com", "created_at": "2024-01-15T10:30:00Z" }, { "user_id": "223e4567-e89b-12d3-a456-426614174001", "username": "bob", "email": "bob@example.com" }]JSON Lines (JSONL)
Section titled “JSON Lines (JSONL)”{"user_id": "123e4567-e89b-12d3-a456-426614174000", "username": "alice", "email": "alice@example.com"}{"user_id": "223e4567-e89b-12d3-a456-426614174001", "username": "bob", "email": "bob@example.com"}Data Type Handling
Section titled “Data Type Handling”Automatic Type Conversion
Section titled “Automatic Type Conversion”| Source Format | Cassandra Type | Notes |
|---|---|---|
| String | uuid | Auto-parsed if valid UUID |
| ISO 8601 | timestamp | 2024-01-15T10:30:00Z |
| Unix timestamp | timestamp | Milliseconds since epoch |
| true/false | boolean | Case-insensitive |
| JSON array | list | ["a", "b", "c"] |
| JSON object | map | {"key": "value"} |
| Base64 | blob | Auto-detected |
Complex Types
Section titled “Complex Types”# List typeuser_id,tags123...,["admin","active","verified"]
# Map typeuser_id,preferences123...,{"theme": "dark", "notifications": "true"}
# Set typeuser_id,roles123...,["user","moderator"]Migration Workflows
Section titled “Migration Workflows”Table-to-Table Copy
Section titled “Table-to-Table Copy”cqlai> .export source_keyspace.users /tmp/users.json --format jsoncqlai> USE target_keyspace;cqlai> .import /tmp/users.json users --format jsonSchema Migration
Section titled “Schema Migration”# Export schemacqlai> DESCRIBE KEYSPACE source_ks > /tmp/schema.cql
# Export datacqlai> .export source_ks.table1 /tmp/table1.csvcqlai> .export source_ks.table2 /tmp/table2.csv
# Create schema on targetcqlai -h target-host -f /tmp/schema.cql
# Import datacqlai -h target-hostcqlai> .import /tmp/table1.csv table1cqlai> .import /tmp/table2.csv table2Incremental Export
Section titled “Incremental Export”cqlai> .export "SELECT * FROM events WHERE event_date = '2024-01-15'" \ /tmp/events_20240115.csvError Handling
Section titled “Error Handling”View Import Errors
Section titled “View Import Errors”cqlai> .import /tmp/users.csv users --skip-errors --error-log /tmp/errors.log
Import completed with errors: Imported: 10,432 rows Failed: 100 rows Error log: /tmp/errors.logError Log Format
Section titled “Error Log Format”Line 1523: Invalid UUID format: "not-a-uuid" for column user_idLine 2891: Type mismatch: expected timestamp, got "invalid-date"Line 3042: Missing required column: user_idPerformance Tips
Section titled “Performance Tips”- Use appropriate batch size - Default 100, increase for faster imports
- Lower consistency for bulk imports - Use LOCAL_ONE
- Compress large exports - Use
--compressfor network transfer - Use JSONL for streaming - Better memory efficiency than JSON array
- Disable tracing during bulk operations - Reduces overhead
Next Steps
Section titled “Next Steps”- Features - Full feature reference
- AI Features - AI-powered queries
- Configuration - Advanced settings