I'm trying to implement a very simple single get call, and the response returns some text with a bunch of ids separated by newline (like a single column csv
). I want to save each one as a row in a dataset.
I understand that in general the Rest connector saves each response as a new row in an avro
file, which works well for json responses which can then be parsed in code.
However in my case I need it to just save the response in a txt
or csv
file, which I can then apply a schema to, getting each id in its own row. How can I achieve this?
By default, the Data Connection Rest connector will place each response from the API as a row in the output dataset. If you know the format type of your response, and it's something that would usually be parsed to be one row per newline (csv
for example), you can try setting the outputFileType
to the correct format (undefined by default).
For example (for more details see the REST API Plugin
documentation):
type: rest-source-adapter2
outputFileType: csv
restCalls:
- type: magritte-rest-call
method: GET
path: '/my/endpoint/file.csv'
If you don't know the format, or the above doesn't work regardless, you'll need to parse the response in transforms to split it into separate rows, this can be done as if the response was a string column, in this case exploding after splitting on newline (\n
) might be useful: F.explode(F.split(F.col("response"), r'\n'))