// packages/dataframe_parquet/examples/demo.vk // Self-contained runnable verification suite for `dataframe_parquet` (`1.0.0`): // Typed columns (dictionary-encoded `.str_col` + validity bitmaps), homoiconic `filter-rows`, // `with-col`, `inner-join`, `left-join`, `group-agg`, `sort-by`, `describe`, `format-table`, // CSV/JSONL codecs, Arrow IPC (`VKAR`), and Zstd Columnar Zone-Map (`VKZP`) roundtrip + pushdown. use [ fs df = dataframe_parquet arrow = dataframe_parquet/arrow ] assert-eq = fn [label str, got any, want any] any [ if got != want [ println `[FAIL] {label}: got {mold got}, expected {mold want}` return (err `assert-eq failed: {label}`) ] println `[PASS] {label}` .ok ] assert-true = fn [label str, cond bool] any [ if not cond [ println `[FAIL] {label}` return (err `assert-true failed: {label}`) ] println `[PASS] {label}` .ok ] main = fn [] any [ println '=== dataframe_parquet 1.0.0 Verification Suite ===' // 1. Build Sales & Customer DataFrames (testing dictionary encoding + `.null` validity bitmaps) customers = df/from-rows [ { cust_id = 1, name = 'Ada Lovelace', region = 'eu-west', tier = 'enterprise' } { cust_id = 2, name = 'Grace Hopper', region = 'us-east', tier = 'enterprise' } { cust_id = 3, name = 'Ken Thompson', region = 'us-east', tier = 'pro' } { cust_id = 4, name = 'Linus Torvalds', region = 'eu-west', tier = 'pro' } ] sales = df/from-rows [ { id = 101, cust_id = 1, amount = 450, status = 'paid', coupon = 'LAUNCH10' } { id = 102, cust_id = 2, amount = 280, status = 'paid', coupon = .null } { id = 103, cust_id = 3, amount = 75, status = 'paid', coupon = .null } { id = 104, cust_id = 1, amount = 620, status = 'paid', coupon = 'VIP' } { id = 105, cust_id = 2, amount = 500, status = 'refunded', coupon = .null } { id = 106, cust_id = 4, amount = 190, status = 'paid', coupon = .null } { id = 107, cust_id = 2, amount = 320, status = 'paid', coupon = 'Q4' } ] status_col = df/get-col sales 'status' coupon_col = df/get-col sales 'coupon' _ = assert-eq/or 'Dictionary-encoded status column stores 2 unique entries for 7 rows' (len status_col.str_dict) 2 [e -> return e] _ = assert-eq/or 'Validity bitmap tracks 4 .null entries in coupon column' coupon_col.null_count 4 [e -> return e] // 2. Pipe-friendly homoiconic `filter-rows` + `inner-join` + `with-col` + `group-agg` + `sort-by` regional_summary = sales \ df/filter-rows (quote [amount > 100 and status == 'paid']) \ df/inner-join customers 'cust_id' 'cust_id' \ df/with-col 'net_cents' (quote [amount * 100]) \ df/group-agg (quote [region]) (quote [total = sum amount, orders = count id, avg_amt = avg amount, top = max amount]) \ df/sort-by/desc 'total' true _ = assert-eq/or 'Grouped summary has 2 regions (eu-west, us-east)' (df/row-count regional_summary) 2 [e -> return e] sum_rows = df/to-rows regional_summary // eu-west paid > 100: 450 + 620 + 190 = 1260 (3 orders, avg 420.0, top 620) // us-east paid > 100: 280 + 320 = 600 (2 orders, avg 300.0, top 320) _ = assert-eq/or 'Top region is eu-west' (map/get sum_rows[0] 'region') 'eu-west' [e -> return e] _ = assert-eq/or 'eu-west sum(amount) == 1260' (map/get sum_rows[0] 'total') 1260 [e -> return e] _ = assert-eq/or 'eu-west count(id) == 3' (map/get sum_rows[0] 'orders') 3 [e -> return e] _ = assert-eq/or 'eu-west avg(amount) == 420.0' (map/get sum_rows[0] 'avg_amt') 420.0 [e -> return e] _ = assert-eq/or 'eu-west max(amount) == 620' (map/get sum_rows[0] 'top') 620 [e -> return e] _ = assert-eq/or 'us-east sum(amount) == 600' (map/get sum_rows[1] 'total') 600 [e -> return e] // Closure-based `filter-rows`, `left-join`, `describe`, and ASCII `format-table` ascii_tbl = df/format-table regional_summary _ = assert-true/or 'ASCII format-table renders aligned header & rows' ((str/contains? ascii_tbl 'eu-west') and (str/contains? ascii_tbl '1260') and (str/contains? ascii_tbl '+--')) [e -> return e] println ascii_tbl desc_df = df/describe sales _ = assert-eq/or 'describe produces 1 summary row per column (5)' (df/row-count desc_df) 5 [e -> return e] // 3. CSV & JSONL import/export roundtrip csv_txt = df/to-csv sales csv_rt = df/from-csv/or csv_txt [e -> return e] _ = assert-eq/or 'CSV roundtrip preserves row count (7) & nulls' (df/row-count csv_rt) 7 [e -> return e] jsonl_txt = df/to-jsonl regional_summary _ = assert-eq/or 'JSONL export emits 2 newline-delimited JSON objects' (len (str/split jsonl_txt '\n')) 2 [e -> return e] // 4. Arrow-style Binary Columnar IPC (`VKAR`) roundtrip + CRC32 tamper detection ipc_bytes = arrow/encode-ipc sales ipc_rt = arrow/decode-ipc/or ipc_bytes [e -> return e] _ = assert-eq/or 'Arrow IPC roundtrip preserves 7 rows & null count' (df/row-count ipc_rt) 7 [e -> return e] rt_rows = df/to-rows ipc_rt _ = assert-eq/or 'Arrow IPC preserves .null cell on row 1 coupon' (map/get rt_rows[1] 'coupon') .null [e -> return e] _ = assert-eq/or 'Arrow IPC preserves dictionary string on row 3 coupon' (map/get rt_rows[3] 'coupon') 'VIP' [e -> return e] mut tampered_ipc = ipc_bytes _ = bytes/set mut tampered_ipc 12 (tampered_ipc[12] ^ 0xff) bad_ipc = arrow/decode-ipc/or tampered_ipc [e -> _ = e df/from-rows [] ] _ = assert-eq/or 'Arrow IPC CRC32 rejects bit-flipped frame' (df/row-count bad_ipc) 0 [e -> return e] // 5. Zstd-compressed Parquet-lite Columnar Container (`VKZP`) + Zone-Map Predicate Pushdown tmp_vkzp = str/join [(os/temp-dir) '/veko_df_parquet_demo_' (mold (time/unix)) '.vkzp'] '' defer [ _ = os/remove/or tmp_vkzp [ .ok ] ] sorted_sales = df/sort-by sales 'id' // Write with `row_group_size = 2` -> 4 row groups: [101,102], [103,104], [105,106], [107] w_rc = df/write-columnar-zstd/row_group_size sorted_sales tmp_vkzp 2 if err? w_rc [ return w_rc ] _ = assert-true/or 'VKZP Zstd columnar file written to disk' (fs/file? tmp_vkzp) [e -> return e] zfooter = df/inspect-zone-maps/or tmp_vkzp [e -> return e] _ = assert-eq/or 'VKZP container partitioned into 4 row groups of <= 2 rows' (len (map/get zfooter 'row_groups')) 4 [e -> return e] // Full read roundtrip full_rt = df/read-columnar-zstd/or tmp_vkzp [e -> return e] _ = assert-eq/or 'VKZP full read roundtrip preserves all 7 rows' (df/row-count full_rt) 7 [e -> return e] // Zone-map predicate pushdown (`id >= 105` -> skips row groups 0 [101..102] and 1 [103..104]!) pushdown = arrow/read-columnar-zstd-stats/where/or tmp_vkzp (quote [id >= 105 and status == 'paid']) [e -> return e] _ = assert-eq/or 'Zone-map pushdown skipped 2 out-of-range row groups without decompressing' (map/get pushdown 'skipped_row_groups') 2 [e -> return e] _ = assert-eq/or 'Zone-map pushdown scanned only 2 candidate row groups' (map/get pushdown 'scanned_row_groups') 2 [e -> return e] pd_df = map/get pushdown 'df' _ = assert-eq/or 'Pushdown + row filter returns exact 2 matching rows (106, 107)' (df/row-count pd_df) 2 [e -> return e] println 'ALL dataframe_parquet 1.0.0 TESTS PASSED' .ok ] res = main if err? res [ println (mold res) os/exit 1 ]