nqdsyn(3)
NAME
nqdsyn — write a
synthetic CSV file from its schema, marked synthetic
LIBRARY
libnqd, -lnqd -lnoqtis
SYNOPSIS
#include
<nqd.h>
int
nqdsyn(nqdrec *r,
const char *dir, const char
*path, uint64_t seed, uint64_t
rows, char *why, size_t
wcap);
DESCRIPTION
nqdsyn()
writes a synthetic stand-in for the CSV file path to
dir/path, made from the record's
schema of path
(noqtis-data(5)), its
recipe, and records it in the sources of
r with its SHA-256, size and
synthetic true, so that every check of it says
‘[synthetic]’. Save the record with
nqdsave(3). It never
replaces real data: a path whose source is not marked
synthetic, or a file there that the record does not mark synthetic, is
refused.
The file has the schema's delimiter, a header of the column names
unless header is false, and
rows rows (0: the schema's
rows.min, else 100), each line ended by a line feed;
a field that holds the delimiter, a quote or a line break is quoted. The
values are the same for the same seed on every
platform: they are drawn from the 64-bit big-endian words of
SHA-256("noqtis-syn-1" || 0x00 || seed ||
j), j = 0, 1, ..., each 8 bytes big-endian, four words a block, and a whole
number from 0 to k - 1 is a word
x taken when x < 2^64 - (2^64
mod k), as x mod
k (a word not taken is skipped). Row by row, column by
column: when the column's nulls is true, a draw from
0 to 9 of 0 makes the value missing (the schema's first
na code, else empty); otherwise
- ‘
int’ min+ a draw from 0 tomax-min(defaults 0 and 1,000; at most 2^53 values)- ‘
real’ min+ (max-min) × (x >> 11) / 2^53 (defaults 0 and 1), written as nqdjson(3) writes numbers- ‘
date’ min+ a draw of days tomax(defaults 2000-01-01 and 2025-12-31)- ‘
bool’ - ‘
true’ for a draw from 0 to 1 of 1, else ‘false’ - ‘
text with a set’ - the element of
setat a draw from 0 to its size - 1 - ‘
text’ - eight letters ‘
a’ to ‘z’, a draw from 0 to 25 each
Every value fits its column's type, range and set, so the file
passes the schema's columns; rules (‘unique,
‘’) are not part of
the recipe.incr,
...’
RETURN VALUES
NQOK, or with a sentence in
why: NQEARG for no schema with
columns, path not a capsule path, a source or file not
marked synthetic, or an ‘int’ range
with no whole number or more than 2^53; NQEIO when
the file cannot be written (its folder must exist);
NQELIM over 1 GiB;
NQEMEM.