Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

snowflake: using query id, how to get the details of the

I am using python connector and ingesting some big data into a table.

Now i want to get the query history details like

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading