I am using python connector and ingesting some big data into a table.
Now i want to get the query history details like
How can i get the bytes scanned and total duration form the history knowing the query id of the query.
the below is the python code
import snowflake
import snowflake.connector
con = snowflake.connector.connect(
account=eeeeeeeeee,
user=xxxxxxxxxxxx,
password=yyyyyyyyyyy,
warehouse=zzzzzzzzzzzzz,
database=dddddddddddddd,
)
try:
cmd=f"""
copy into "DB1"."SCH1"."TB1"
from s3://bucket1/folder1/ credentials=(aws_key_id='xxxxxxxxxx' aws_secret_key='yyyyyyyyyyyyyyyy')
file_format = (type = csv field_delimiter = '|'skip_header = 1)
on_error = 'continue';
"""
res = con.execute_string(cmd)
query_id = x._sfqid[0]
# I am getting the query id here.
# Using this how to get the details.
# (bytes scanned, total time take as shown in history)
con.commit()
return res
except Exception as e:
raise e
finally:
con.close()
>Solution :
You can use a query like this to get this information from the account_usage schema:
select bytes_scanned, total_elapsed_time, query_id from snowflake.account_usage.query_history
where query_id = 'YOUR_QUERY_ID'
