Column (type) specifiers

I had a look at XSB’s CSV handling predicates, notably load_csv/2 and load_dsv/3. The idea was to have a look which of this functionality would fit SWI-Prolog’s CSV reader nicely. The obvious candidate that also came up in our discussion on JSON is the column type specifier, which allows for example for

 load_csv('myfile.csv', mypred(atom, integer, float)).

Asking the first column to be stored as atom, the second converted to integer and the last to a floating point number. That looks good. Trying to implement it though, I got less convinced, as we need to specify

  • What to do if the conversion fails?
  • What do to with empty fields? This is a refinement of the first.

XSB prints a warning and stores the failed field as an atom. Printed warnings are hard to handle in programming code though :frowning: Sensible actions I can see are

  • As XSB
  • Raise an exception and stop processing
  • Skip the row as invalid data

Empty fields for typed fields are also problematic. One could use a null-specifier. Does this need to be column-specific, or is that an overkill?

Note that if we do not have column type specifiers, we do not have these problems as CSV fields are strings as far as the CSV standard is concerned.