On the GUI Treasure Workflow
+run_query:
td_run>: sample_query
You can execute the query with the query name on Treasure Data. However, it seems that there is no such function on the Python Client side. (Might happen)
** Use run_schedule **
import time
import tdclient
if __name__ == '__main__':
query_name = 'sample_query'
with tdclient.Client(apikey='hogehoge') as td:
# get unix time
unix_time = int(time.time())
run_time = unix_time + 10
# set schedule query
# run now!
res = td.run_schedule(name=query_name, time=run_time, num=1)
return 0
import time
import tdclient
def main():
query_name = 'sample_query'
with tdclient.Client(apikey='hogehoge') as td:
unix_time = int(time.time())
run_time = unix_time + 10
# set schedule query
# run now!
res = td.run_schedule(name=query_name, time=run_time, num=1)
schedule_job = res[0]
# get job_id from ScheduleJob object
job_id = schedule_job._job_id
# get Job object by job_id
job = td.job(job_id=job_id)
# wait until job finished
job.wait()
# get results one by one
for row in job.result():
print(repr(row))
return 0
if __name__ == '__main__':
main()
The reason why I wanted to hit the query on Treasure Data is ... I wanted to use the one set with Connector on the GUI of Treasure Data. Of course, I could set Export on Python, but I wanted to wear it sideways.
Official-Python Client GitHub - Treasure Data API library for Python
Recommended Posts