1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python snowflake connector fetch_pandas_all() fails with larger record count

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I am attempting to export snowflake data to a csv but I am finding that the code below only works for a few records. I am unable to ascertain what the maximum number of records that it works for is because it seems to change as I re-run the script. What I know is that I can successfully run the script and get an output csv file if I set the limit in the sql query to 100. When I set the limit in the query to more than 2000 or so, the code fails to run the df = cur.fetch_pandas_all() line. Sometimes I get the error screen below but most times the code just exits. What could be the cause of the issue?

    import pandas as pd
    import snowflake.connector
    import time
    import csv

    # Calculate the start time
    start = time.time()

    credentials = {
    'account' : 'my account',
    'user' : 'my user',
    'authenticator' : 'externalbrowser',
    'database' : ' my database',
    'schema' : 'my schema',
    'warehouse' : 'my warehouse',
    'role' : 'my role'
    }

    query = "fake query limit 2500"
    p = r"out csv path"
    with snowflake.connector.connect(**credentials) as cnx:
    print("Running...")
    cur = cnx.cursor()
    print("Executing query...")
    cur.execute(query)
    print("Fetch...")
    df = cur.fetch_pandas_all()
    print(len(df))
    df.to_csv(p, sep=',', header=True,index=False)
    end = time.time()
    length = end - start
    print("It took", round(length/60), "minutes!")
    print("Done!!")


    [​IMG]

    Continue reading...

Compartilhe esta Página