CQL Type System & Schema Handling
БесплатноБез исполняемых скриптовНе проверенImplement and deserialize all CQL types including primitives (int, text, timestamp, uuid, varint, decimal), collections (list, set, map), tuples, UDTs…
от pmcfadin★ 22 звезды на GitHubОб этом скилле
CQL Type System & Schema Handling
This skill provides guidance on implementing Cassandra CQL type system with schema-provided deserialization.
When to Use This Skill
- Implementing CQL type deserializers
- Parsing collection types (list, set, map)
- Handling User-Defined Types (UDTs)
- Working with frozen vs non-frozen types
- Tuple deserialization
- Schema validation
- Type-correct data generation
Core Principles
Schema-Provided Deserialization
Per PRD: schema passed in, not inferred
// Schema provides type information
fn deserialize_cell(
data: &[u8],
column_type: &CqlType, // From schema
) -> Result<CqlValue>
Never try to infer type from data alone - always use schema.
CQL Type Categories
1. Primitive Types
Fixed-Size Primitives
boolean- 1 byte (0x00 or 0x01)tinyint- 1 byte signedsmallint- 2 bytes signed, big-endianint- 4 bytes signed, big-endianbigint- 8 bytes signed, big-endianfloat- 4 bytes IEEE 754double- 8 bytes IEEE 754date- 4 bytes (days since epoch)time- 8 bytes (nanoseconds since midnight)
Variable-Size Primitives
text/varchar- UTF-8 encoded stringblob- raw bytesascii- ASCII-only string
Special Primitives
uuid/timeuuid- 16 bytesinet- 4 bytes (IPv4) or 16 bytes (IPv6)varint- variable-length big integerdecimal- scale (4 bytes) + unscaled varintduration- months, days, nanoseconds (3 VInts)timestamp- 8 bytes (milliseconds since Unix epoch)
2. Collection Types
See collections-and-udts.md for detailed format.
Collection Format:
[4 bytes: element_count (big-endian)]
[for each element:]
[4 bytes: element_size (big-endian)]
[bytes: element_data]
Types:
list<T>- Ordered, allows duplicatesset<T>- Unordered, no duplicatesmap<K,V>- Key-value pairs
3. Tuple Types
Format:
[element_1_data]
[element_2_data]
...
No size prefix - elements serialized back-to-back. Each element uses its type's serialization.
4. User-Defined Types (UDTs)
Format:
[for each field in schema order:]
[4 bytes: field_size (-1 for null, 0 for empty, >0 for data)]
[if size > 0:]
[bytes: field_data]
UDT schema defines field names and types.
5. Frozen vs Non-Frozen
Frozen types:
- Serialized as single blob
- Cannot update individual elements
- Used in primary keys
- Nested collections must be frozen
Non-frozen collections:
- Can update individual elements
- Only allowed at top level (not nested)
- Uses tombstones for deletions
Type Deserialization Patterns
Zero-Copy Pattern
use bytes::Bytes;
fn deserialize_text(data: Bytes) -> Result<String> {
// Zero-copy: validate UTF-8 then wrap
let s = std::str::from_utf8(&data)?;
Ok(s.to_string()) // Only copy if needed
}
fn deserialize_blob(data: Bytes) -> Result<Bytes> {
// Zero-copy: just return the slice
Ok(data)
}
Length-Prefixed Pattern
fn deserialize_length_prefixed(data: &[u8]) -> Result<(Bytes, &[u8])> {
if data.len() < 4 {
return Err(Error::NotEnoughBytes);
}
let size = i32::from_be_bytes([data[0], data[1], data[2], data[3]]);
if size < 0 {
return Ok((Bytes::new(), &data[4..])); // Null
}
let size = size as usize;
if data.len() < 4 + size {
return Err(Error::NotEnoughBytes);
}
let value = Bytes::copy_from_slice(&data[4..4 + size]);
let remaining = &data[4 + size..];
Ok((value, remaining))
}
Collection Pattern
fn deserialize_list(
data: &[u8],
element_type: &CqlType,
) -> Result<Vec<CqlValue>> {
let count = i32::from_be_bytes([data[0], data[1], data[2], data[3]]) as usize;
let mut offset = 4;
let mut elements = Vec::with_capacity(count);
for _ in 0..count {
let (element_data, remaining) = deserialize_length_prefixed(&data[offset..])?;
let element = deserialize_value(&element_data, element_type)?;
elements.push(element);
offset = data.len() - remaining.len();
}
Ok(elements)
}
Schema Handling
Schema Sources
- Statistics.db: Serialization header with column definitions
- System tables:
system_schema.tables,system_schema.columns - CQL schema file: For test data generation
Schema Representation
struct TableSchema {
keyspace: String,
table: String,
partition_keys: Vec<ColumnDef>,
clustering_keys: Vec<ColumnDef>,
regular_columns: Vec<ColumnDef>,
static_columns: Vec<ColumnDef>,
}
struct ColumnDef {
name: String,
cql_type: CqlType,
}
enum CqlType {
// Primitives
Boolean,
Int,
BigInt,
Text,
Uuid,
Timestamp,
// ... more primitives
// Collections
List(Box<CqlType>),
Set(Box<CqlType>),
Map(Box<CqlType>, Box<CqlType>),
Установить CQL Type System & Schema Handling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobВложенные файлы
FAQ
Что делает скилл CQL Type System & Schema Handling?
Implement and deserialize all CQL types including primitives (int, text, timestamp, uuid, varint, decimal), collections (list, set, map), tuples, UDTs (user-defined types), and frozen types. Use when working with CQL type deserialization, schema validation, collection parsing, UDT handling, or type-correct data generation.
Как установить скилл CQL Type System & Schema Handling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл CQL Type System & Schema Handling запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic