Hello,
I have had a little background of the custom formatter. Here is what I know, hope this can help:
The normal output of custom `formatter_in` function is a tuple. As you described that your data contains only one tuple, so when you detect eof in the `if(eof)` bracket, you need to format the data in `formatter->fmt_databuf` into a tuple struct which is stored at `formatter->fmt_tuple`.
So the seudo code may look like:
if(eof)
{
elog(NOTICE, "Reached EOF, total file size = %d", len);
// TODO: implement formatting, return the tuple
FORMATTER_SET_DATACURSOR(fcinfo, len); /* You need to mark this to consume the data */
tuple = heap_form_tuple(tupdesc, values, nulls);/* values and nulls are needed to be filled with the column values which also need to be transformed by conv_functions */
FORMATTER_SET_TUPLE(fcinfo, tuple); /* or you can return null value for testing */
FORMATTER_RETURN_NOTIFICATION(fcinfo, FMT_NONE); FORMATTER_RETURN_TUPLE(tuple);
}
else
{
elog(NOTICE, "Still reading file, current size = %d", len);
FORMATTER_RETURN_NOTIFICATION(fcinfo, FMT_NEED_MORE_DATA);
}
If you are trying to write your own custom formatter, you need to read some of the written formatters. You can read `fixedwidth_in()` which contains the most of the needed function callings as an example.
And also function `externalgettup_custom()` calls the real formatter_in functions, reading how they are called is also helpful to write single row error handling and how to handle the data cursors.