take advantage of a UDF for parameter extraction and write straight to file.
add aliases to query.
fix field alias (hopefully it won't compute twice)