Database
cifflow.database.compact
convert_database — one-way export that casts DuckDB columns to typed storage.
convert_database(src, dst, schema, on_coercion_failure='null')
Copy src into dst, casting columns to typed DuckDB storage.
All columns in the source database are stored as VARCHAR (the ingest
layer never writes typed values). This function creates the destination
tables with proper INTEGER / DOUBLE / VARCHAR types and casts
each value on the way across.
Casting is performed entirely inside DuckDB's SQL engine via TRY_CAST,
regexp_replace, and from_json / to_json for JSON container
columns. Destination tables are created without NOT NULL or
PRIMARY KEY constraints; all SQL joins and queries work normally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
DuckDBPyConnection
|
Source DuckDB connection populated by |
required |
dst
|
DuckDBPyConnection
|
Destination DuckDB connection (must be empty). |
required |
schema
|
'SchemaSpec'
|
|
required |
on_coercion_failure
|
Literal['null', 'keep', 'error']
|
|
'null'
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Warning messages: SU-dropped values and coercion failures (null/keep policy only — error policy raises instead of returning). |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Exception
|
DDL or data-transfer failures propagate directly after rolling back the destination transaction. |
Source code in src/cifflow/database/compact.py
199 200 201 202 203 204 205 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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
cifflow.database.defaults
generate_defaults — fill NULL columns with DDLm-defined defaults.
generate_defaults(connection, schema, max_iterations=32)
Fill NULL columns in an ingested database with DDLm-defined defaults.
Runs a fixed-point loop: each pass fills NULLs using scalar defaults
(_enumeration.default) and keyed defaults (_enumeration_defaults
lookup tables). The loop repeats until no more rows change or
max_iterations is reached, so that a filled index tag can unlock
keyed defaults that were previously unresolvable.
This function operates in-place on connection and adds no tracking
columns. Call it only after :func:~cifflow.ingestion.ingest and before
any round-trip or fidelity work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
DuckDBPyConnection
|
Open DuckDB connection containing the ingested schema tables. |
required |
schema
|
SchemaSpec
|
Schema descriptor produced by
:func: |
required |
max_iterations
|
int
|
Maximum number of fill passes before giving up. |
32
|
Returns:
| Type | Description |
|---|---|
int
|
Total number of cells filled across all passes. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the transaction cannot be started, or if any SQL statement fails (e.g. a schema table is absent from connection). The transaction is rolled back before re-raising. |
Source code in src/cifflow/database/defaults.py
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |