Module pl.data

Reading and querying simple tabular data.
This provides a way of creating basic SQL-like queries.

Functions

filter (Q, file, dont_fail) Filter input using a query.
new (data, fieldnames) create a new dataset from a table of rows.
query (data, condn, context, return_row) create a query iterator from a select string.
read (file, cnfg, cnfig) read a delimited file in a Lua table.


Functions

filter (Q, file, dont_fail)
Filter input using a query.

Parameters:

  • Q: a query string
  • file: a file-like object
  • dont_fail: true if you want to return an error, not just fail
new (data, fieldnames)
create a new dataset from a table of rows.
Can specify the fieldnames, else the table must have a field called 'fieldnames', which is either a string of comma-separated names, or a table of names.

Parameters:

  • data: the table.
  • fieldnames: optional fieldnames

Return value:

    the table.
query (data, condn, context, return_row)
create a query iterator from a select string. Select string has this format:
FIELDLIST [ where LUA-CONDN [ sort by FIELD] ]
FIELDLISt is a comma-separated list of valid fields, or '*'.

The condition can also be a table, with fields 'fields' (comma-sep string or table), 'sort_by' (string) and 'where' (Lua expression string or function)

Parameters:

  • data: table produced by read
  • condn: select string or table
  • context: a list of tables to be searched when resolving functions
  • return_row: if true, wrap the results in a row table

Return value:

    an iterator over the specified fields
read (file, cnfg, cnfig)
read a delimited file in a Lua table. By default, attempts to treat first line as separated list of fieldnames.

Parameters:

  • file: a filename or a file-like object (default stdin)
  • cnfg:
  • cnfig: options: can override delim (a string pattern), fieldnames (a list), specify no_convert (default is to convert), numfields (indices of columns known to be numbers) and thousands_dot (thousands separator in Excel CSV is '.')

Valid XHTML 1.0!