Hi! I am trying to print results to a CSV file, but I can’t make a header.
From the documentation, it says that:
In the query definition, the line
"header"is printed first, followed by theprintlnstatements in theACCUMclause, and"footer"is printed last. The output in the file follows this order because the order of query-body level statements is maintained in the output.
However, this is not what I am observing. The order of query-body level statements is NOT maintained.
Example:
CREATE OR REPLACE DISTRIBUTED QUERY csv_test() {
FILE output_file ("/home/tigergraph/gsql_output/csv_test.csv");
PRINT "header" TO_CSV output_file;
transfers = SELECT t FROM Customer -()- TransferDoc:t
ACCUM output_file.println(t.transfer_id, t.amount);
PRINT "footer" TO_CSV output_file;
}
So there are 3 query-body level statements in the query. I expected that “header” gets printed always first, but in fact it’s random. Sometimes is first, sometimes is at end of file.
Output example:
transfer1,250
transfer2,300
transfer_id,amount
footer
I understand that there is no order guaranteed on the “middle part”, the main content that comes from the SELECT. But I expected the header to be first, as the documentation says. What can I do to guarantee header to be the first line?
I am user TG Cloud. Tested in version 3.8.
Edit: Updated query to use println inside ACCUM instead of PRINT. Same result.