Commit a6f5715
committed
Add CreateTable API with typestate pattern and comprehensive testing
This commit introduces a complete CreateTable API for Delta Kernel Rust,
enabling programmatic creation of Delta tables with proper metadata tracking
and validation.
The API uses a typestate pattern to enforce correct usage at compile time:
1. **CreateTableBuilder** (configuration stage)
- Configure table properties, schema, partition columns
- Builder methods: with_table_properties(), with_partition_columns()
- Validates configuration before transitioning
2. **CreateTableTransaction** (commit stage)
- Commits Protocol, Metadata, and CommitInfo actions
- Returns Transaction for future data operations
- Enforces that metadata is committed before data operations
This pattern is extensible for future table features:
- Add builder methods for clustering, constraints, invariants
- Add table feature flags to Protocol action
- Extend validation in build() method
- Maintain type safety throughout
Example extensibility:
```rust
CreateTableBuilder::new(path, schema, engine_info)
.with_table_properties(props)
.with_partition_columns(vec!["date", "region"]) // ✓ Supported
.with_clustering(vec!["user_id"]) // Future
.with_check_constraints(constraints) // Future
.build(engine)?
```
- test_create_simple_table: Basic table creation with events schema
- test_create_table_with_properties: Financial table with Delta properties
- test_create_table_already_exists: Duplicate creation prevention
- test_create_table_multiple_properties: Builder pattern chaining
**Coverage**: Verifies tables load correctly and schemas are preserved
- test_commit_info_is_written_to_log: Validates all 3 actions present
* Parses actual JSON log file
* Verifies Protocol (minReaderVersion=3, minWriterVersion=7)
* Verifies Metadata (id, schemaString, createdTime)
* Verifies CommitInfo (timestamp, operation, engineInfo, txnId, kernelVersion)
- test_log_action_order: Ensures correct action ordering
**Coverage**: Guarantees Delta protocol compliance and complete audit trail
- test_create_table_empty_schema: Schema validation
- Realistic schemas: DECIMAL types, TIMESTAMP, DATE, BOOLEAN
**Coverage**: Prevents invalid table configurations
```rust
use delta_kernel::table_manager::TableManager;
use delta_kernel::schema::{StructType, StructField, DataType};
use delta_kernel::committer::FileSystemCommitter;
use std::sync::Arc;
use std::collections::HashMap;
// Define schema
let schema = Arc::new(StructType::try_new(vec![
StructField::new("user_id", DataType::LONG, false),
StructField::new("event_type", DataType::STRING, false),
StructField::new("timestamp", DataType::TIMESTAMP, false),
])?);
// Configure table properties
let mut properties = HashMap::new();
properties.insert("delta.appendOnly".to_string(), "true".to_string());
properties.insert("delta.checkpointInterval".to_string(), "10".to_string());
// Create table with typestate pattern
let create_txn = TableManager::create_table(
"/path/to/table",
schema,
"MyApplication/1.0"
)
.with_table_properties(properties)
.build(&engine)?;
// Commit metadata (creates _delta_log/00000000000000000000.json)
let txn = create_txn.commit_metadata(&engine, Box::new(FileSystemCommitter::new()))?;
// Future: Use returned transaction for data operations
// txn.add_files(data);
// txn.commit(&engine)?;
```
- kernel/src/actions/mod.rs: Protocol version constants
- kernel/src/transaction/create_table.rs: CommitInfo generation
- kernel/tests/create_table.rs: Comprehensive test suite (7 tests)
None - this is a new API addition.
- Add support for partition columns in builder
- Add clustering configuration
- Add check constraints and invariants
- Support column mapping modes
- Enable schema evolution from CreateTableTransaction1 parent 4ea0ef6 commit a6f5715
File tree
7 files changed
+876
-63
lines changed- kernel
- examples/write-table/src
- src
- actions
- transaction
- tests
7 files changed
+876
-63
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | | - | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
| |||
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
155 | 154 | | |
156 | 155 | | |
157 | 156 | | |
158 | | - | |
| 157 | + | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
| |||
195 | 194 | | |
196 | 195 | | |
197 | 196 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
205 | 204 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 205 | + | |
| 206 | + | |
258 | 207 | | |
259 | 208 | | |
260 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
71 | 81 | | |
72 | 82 | | |
73 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| 160 | + | |
| 161 | + | |
159 | 162 | | |
160 | 163 | | |
161 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
0 commit comments