Skip to content

nqdinfer(3)

nqdinfer, nqdschk — infer and check the schema of a CSV file

libnqd, -lnqd -lnoqtis

#include <nqd.h>

typedef struct {
  char delim;   /* 0 for ',' */
  int noheader; /* the first line is data */
  int ranges;   /* pin number and date ranges */
} nqdcsvopt;

int
nqdinfer(const char *dir, const char *path, const nqdcsvopt *o, char *out, size_t cap, size_t *outlen, char *why, size_t wcap);

int
nqdschk(const char *dir, const char *schema, size_t n, nqdrep **rep);

() reads the CSV file path (relative to dir) and writes its schema to out, a ‘schemas’ element (noqtis-data(5)) in canonical JSON, to give to nqdput(3): column names (from the header, or V1, V2, ... with noheader), the narrowest type of each, whether it has missing values (the empty field and ‘NA’), the row count pinned, and with ranges each number or date column's range. noqtis-schema(1) says what each type accepts. o may be NULL for the defaults. On failure a sentence goes to why.

() checks the file named by the ‘schemas’ element schema (n bytes of JSON) against it and reports one ‘schema’ row per problem (the first ten, then a count) or one passing row, and one ‘rule’ row per rule, as nqdchk(3) does for every schema of a record.

nqdinfer(): NQOK; NQEBUF with *outlen set when cap is too small; NQEDEC for a file that is not CSV, rows of different lengths or a column name twice; NQELIM over the reader's limits (a field 1 MiB, a line 16 MiB or 16,384 fields); NQEIO for a file that cannot be read; NQEARG for a bad path or delimiter.

nqdschk(): NQOK when every row passed, NQEVRFY otherwise (an element that is not a schema is a failed row), with *rep set; free it with nqdrepfree(3).

noqtis-schema(1), nqdchk(3), nqdnew(3), noqtis-data(5)

Common Format and MIME Type for Comma-Separated Values (CSV) Files, RFC 4180.