Complete worked example
python
import duckdb
def inspect_example(rows, minimum):
connection = duckdb.connect(config={'threads': 1, 'memory_limit': '64MB',
'autoinstall_known_extensions': 'false', 'autoload_known_extensions': 'false'})
try:
connection.execute('CREATE TABLE stage(id VARCHAR, amount_cents BIGINT)')
if rows:
connection.executemany('INSERT INTO stage VALUES (?, ?)', rows)
connection.execute("COPY stage TO 'batch.parquet' (FORMAT PARQUET)")
schema = [[r[0], r[1]] for r in connection.execute("DESCRIBE SELECT * FROM read_parquet('batch.parquet')").fetchall()]
selected = connection.execute("SELECT id, amount_cents FROM read_parquet('batch.parquet') WHERE amount_cents >= ? ORDER BY id", [minimum]).fetchall()
return {'schema': schema, 'rows': [list(row) for row in selected]}
finally:
connection.close()- Reasoning
- The program creates an in-memory staging table, inserts parameterized values and copies the table to batch.parquet in a fresh directory. DESCRIBE then observes the file schema, and read_parquet executes a real predicate against that file. The report returns measured schema names and filtered rows.