CQLAI Parquet Support
CQLAI provides comprehensive support for Apache Parquet format, enabling efficient data exchange between Cassandra and modern analytics ecosystems.
Why Parquet?
Section titled “Why Parquet?”| Benefit | Description |
|---|---|
| Efficient Storage | Columnar format with 50-80% smaller file sizes than CSV |
| Fast Analytics | Optimized for analytical queries in Spark, Presto, DuckDB |
| Type Preservation | Maintains Cassandra data types including UDTs and collections |
| ML Ready | Direct compatibility with pandas, PyArrow, and ML frameworks |
| Streaming | Memory-efficient for large datasets |
Quick Start
Section titled “Quick Start”Export to Parquet
Section titled “Export to Parquet”-- Basic export (format auto-detected from extension)COPY users TO 'users.parquet';
-- With compressionCOPY events TO 'events.parquet' WITH COMPRESSION='ZSTD';
-- Explicit format specificationCOPY orders TO 'data.parquet' WITH FORMAT='PARQUET';
-- Export specific columnsCOPY users (id, name, email) TO 'users_partial.parquet';Import from Parquet
Section titled “Import from Parquet”-- Basic importCOPY users FROM 'users.parquet';
-- Explicit formatCOPY analytics FROM 'data.parquet' WITH FORMAT='PARQUET';Export Options
Section titled “Export Options”COPY TO Syntax
Section titled “COPY TO Syntax”COPY table_name [(column_list)] TO 'file.parquet'[WITH option=value [AND option=value ...]]Available Options
Section titled “Available Options”| Option | Default | Description |
|---|---|---|
FORMAT | auto | PARQUET or CSV (auto-detected from extension) |
COMPRESSION | SNAPPY | Compression algorithm |
CHUNKSIZE | 10000 | Rows per row group |
PAGESIZE | 1000 | Rows to fetch per page from Cassandra |
Compression Algorithms
Section titled “Compression Algorithms”| Algorithm | Speed | Ratio | Use Case |
|---|---|---|---|
SNAPPY | Fast | Good | General purpose (default) |
ZSTD | Medium | Best | Archival, best compression |
GZIP | Slow | Great | Compatibility |
LZ4 | Fastest | Moderate | High-speed requirements |
NONE | N/A | None | When compression not needed |
Examples
Section titled “Examples”-- Best compression for archivalCOPY events TO 'events_archive.parquet' WITH COMPRESSION='ZSTD';
-- Fast compression for streamingCOPY metrics TO 'metrics.parquet' WITH COMPRESSION='LZ4';
-- Large table with custom chunk sizeCOPY large_table TO 'data.parquet' WITH CHUNKSIZE=50000;Import Options
Section titled “Import Options”COPY FROM Syntax
Section titled “COPY FROM Syntax”COPY table_name [(column_list)] FROM 'file.parquet'[WITH option=value [AND option=value ...]]Available Options
Section titled “Available Options”| Option | Default | Description |
|---|---|---|
FORMAT | auto | PARQUET or CSV |
MAXROWS | -1 | Maximum rows to import (-1=unlimited) |
MAXINSERTERRORS | 1000 | Max insert errors before stopping |
MAXBATCHSIZE | 20 | Rows per batch insert |
CHUNKSIZE | 5000 | Rows between progress updates |
Examples
Section titled “Examples”-- Import with row limitCOPY users FROM 'users.parquet' WITH MAXROWS=10000;
-- Import with error toleranceCOPY data FROM 'data.parquet' WITH MAXINSERTERRORS=100;Supported Data Types
Section titled “Supported Data Types”CQLAI handles all Cassandra data types in Parquet format:
Primitive Types
Section titled “Primitive Types”| Cassandra Type | Parquet Type | Notes |
|---|---|---|
int | INT32 | |
bigint | INT64 | |
smallint | INT32 | |
tinyint | INT32 | |
float | FLOAT | |
double | DOUBLE | |
decimal | BYTE_ARRAY (string) | Preserves precision |
varint | BYTE_ARRAY (string) | |
boolean | BOOLEAN | |
text | BYTE_ARRAY (UTF8) | |
varchar | BYTE_ARRAY (UTF8) | |
ascii | BYTE_ARRAY (ASCII) | |
blob | BYTE_ARRAY | |
uuid | FIXED_LEN_BYTE_ARRAY[16] | |
timeuuid | FIXED_LEN_BYTE_ARRAY[16] | |
timestamp | INT64 (TIMESTAMP_MILLIS) | |
date | INT32 (DATE) | |
time | INT64 (TIME_MICROS) | |
duration | BYTE_ARRAY (string) | ISO-8601 format |
inet | BYTE_ARRAY (string) | IP address string |
Collection Types
Section titled “Collection Types”| Cassandra Type | Parquet Type |
|---|---|
list<T> | LIST |
set<T> | LIST |
map<K,V> | MAP |
frozen<...> | Same as inner type |
Complex Types
Section titled “Complex Types”| Cassandra Type | Parquet Type |
|---|---|
| User-Defined Type (UDT) | GROUP |
tuple<...> | GROUP |
vector<T, N> | LIST |
Working with Analytics Tools
Section titled “Working with Analytics Tools”Python (pandas / PyArrow)
Section titled “Python (pandas / PyArrow)”import pandas as pd
# Read Parquet exported from CQLAIdf = pd.read_parquet('users.parquet')
# Process dataactive_users = df[df['status'] == 'active']
# Write back to Parquet for CQLAI importactive_users.to_parquet('active_users.parquet', index=False)Apache Spark
Section titled “Apache Spark”from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("CassandraAnalytics").getOrCreate()
# Read Parquetdf = spark.read.parquet("events.parquet")
# Processdf.groupBy("event_type").count().show()
# Write for CQLAI importdf.write.parquet("processed_events.parquet")DuckDB
Section titled “DuckDB”-- Query Parquet directlySELECT * FROM 'users.parquet' WHERE status = 'active';
-- AggregateSELECT date_trunc('month', created_at) as month, COUNT(*)FROM 'events.parquet'GROUP BY 1;Apache Drill
Section titled “Apache Drill”SELECT *FROM dfs.`/path/to/users.parquet`WHERE status = 'active';Best Practices
Section titled “Best Practices”Choosing Compression
Section titled “Choosing Compression”| Scenario | Recommended |
|---|---|
| General purpose | SNAPPY |
| Long-term storage | ZSTD |
| Maximum compatibility | GZIP |
| Real-time streaming | LZ4 or NONE |
Optimizing Chunk Size
Section titled “Optimizing Chunk Size”-- Small tables (< 100K rows)COPY small_table TO 'data.parquet' WITH CHUNKSIZE=5000;
-- Large tables (> 1M rows)COPY large_table TO 'data.parquet' WITH CHUNKSIZE=50000;Larger chunk sizes:
- Better compression ratio
- Faster reads for analytics
- Higher memory usage during export
Handling Large Exports
Section titled “Handling Large Exports”For very large tables:
-- Use larger page size for faster exportCOPY huge_table TO 'data.parquet' WITH PAGESIZE=5000 AND CHUNKSIZE=100000;Data Type Considerations
Section titled “Data Type Considerations”Timestamps: Parquet stores timestamps in milliseconds. CQLAI preserves Cassandra timestamp precision.
Decimals: Stored as strings to preserve arbitrary precision.
UUIDs: Stored as 16-byte fixed-length arrays for efficient storage.
Troubleshooting
Section titled “Troubleshooting”Import Type Mismatches
Section titled “Import Type Mismatches”If column types do not match:
-- Check table schemaDESCRIBE TABLE users;
-- Verify Parquet schema-- (Use external tool like parquet-tools)parquet-tools schema users.parquetMemory Issues with Large Files
Section titled “Memory Issues with Large Files”For large files, adjust CQLAI memory settings:
{ "maxMemoryMB": 100}Null Value Handling
Section titled “Null Value Handling”Parquet preserves null values correctly. However, ensure your table allows nulls for imported columns:
-- Check column definitionsDESCRIBE TABLE my_table;Examples
Section titled “Examples”ETL Workflow
Section titled “ETL Workflow”-- 1. Export from CassandraCOPY events TO 'raw_events.parquet' WITH COMPRESSION='SNAPPY';
-- 2. Process in Python/Spark (external)
-- 3. Import processed dataCOPY processed_events FROM 'enriched_events.parquet';Backup and Restore
Section titled “Backup and Restore”-- BackupCOPY users TO 'backup/users_20240115.parquet' WITH COMPRESSION='ZSTD';COPY orders TO 'backup/orders_20240115.parquet' WITH COMPRESSION='ZSTD';
-- Restore (to new cluster)COPY users FROM 'backup/users_20240115.parquet';COPY orders FROM 'backup/orders_20240115.parquet';Analytics Export
Section titled “Analytics Export”-- Export for analytics teamCOPY events TO 'analytics/events.parquet' WITH COMPRESSION='SNAPPY' AND CHUNKSIZE=100000;Next Steps
Section titled “Next Steps”- Commands Reference - Full COPY command syntax
- Configuration - CQLAI settings
- Troubleshooting - Common issues