Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Batch Script for Presto query

Tags:

bash

presto

I am running a bash script to extract data from a table via presto...

./presto --server myprestoserver:8889 --catalog mycatalog --schema myschema --execute "select * from TABLEResultsAuditLog;" > /mydirectory/audit.dat

This command will successfully and extract the table results and send them to the audit.dat file. What I am looking for is to replace the --execute "select * from TABLEResultsAuditLog;" section and have a file located in /mydirectory/audit.sql which would then contain the sql statement which I need executed. I have tried using

./presto --server myprestoserver:8889 --catalog mycatalog --schema myschema < /mydirectory/audit.sql > /mydirectory/audit.dat

where the audit.sql contains the select statement only, but this only populates the audit.dat file with the query statement and not the results. I'm not familiar with bash scripting, so its probably an easy fix for someone!!

like image 424
Jason Coleman Avatar asked Aug 20 '18 13:08

Jason Coleman


1 Answers

Presto CLI has --file option for this purpose:

presto-cli --server ... --file input.sql > output-file
like image 194
Piotr Findeisen Avatar answered Oct 20 '22 11:10

Piotr Findeisen