# Split rows into training and test sets

Shape / rows

A variant of [Sample rows](https://meridian.online/operations/sample-rows).

Partition every row at random into two or more sets, such as training, validation and holdout.

Page: <https://meridian.online/operations/sample-rows/split-rows-into-training-and-test-sets>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

split every row at random into training, validation and test sets

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
-- rank the rows by a seeded hash of the key, so the split is random-looking and the same on every run
CREATE TEMP TABLE shuffled AS
SELECT *, row_number() OVER (ORDER BY hash(order_id::VARCHAR || '-split-42')) AS rn FROM orders;
CREATE TEMP TABLE train AS SELECT order_id FROM shuffled WHERE rn <= 6;
CREATE TEMP TABLE validation AS SELECT order_id FROM shuffled WHERE rn > 6 AND rn <= 8;
CREATE TEMP TABLE test AS SELECT order_id FROM shuffled WHERE rn > 8;
SELECT 'train' AS split, count(*) AS n FROM train UNION ALL SELECT 'validation', count(*) FROM validation UNION ALL SELECT 'test', count(*) FROM test;
SELECT CASE WHEN ((SELECT count(*) FROM train) = 6 AND (SELECT count(*) FROM validation) = 2 AND (SELECT count(*) FROM test) = 2 AND (SELECT list(order_id ORDER BY order_id) FROM train) = [2, 3, 4, 7, 8, 9] AND (SELECT list(order_id ORDER BY order_id) FROM validation) = [1, 10] AND (SELECT list(order_id ORDER BY order_id) FROM test) = [5, 6] AND (SELECT count(DISTINCT order_id) FROM (SELECT * FROM train UNION ALL SELECT * FROM validation UNION ALL SELECT * FROM test)) = 10 AND (SELECT sum(order_id) FROM (SELECT * FROM train UNION ALL SELECT * FROM validation UNION ALL SELECT * FROM test)) = 55) THEN 'as expected' ELSE error('the three sets were not orders 2, 3, 4, 7, 8, 9 and 1, 10 and 5, 6 under the seeded hash') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Alteryx Designer: [`Create Samples`](https://help.alteryx.com/current/en/designer/tools/preparation/create-samples-tool.html) (read 2026-09-27)
- KNIME Analytics Platform: [`DB Table Partitioner`](https://api.hub.knime.com/nodes/*NKuW-RponmBdKGHF?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Table Partitioner`](https://api.hub.knime.com/nodes/*T0AhxSe0Yi42rQK8?details=full) (read 2026-09-27)
- mlpack: [`Dataset splitting`](https://www.mlpack.org/doc/user/preprocessing.html) (read 2026-09-27)
- RapidMiner Studio: [`Split Data`](https://docs.rapidminer.com/latest/studio/operators/blending/examples/sampling/split_data.html) (read 2026-09-27)
