首页 > 解决方案 > 使用 Snowflake 的 Python 连接器调用存储过程时,名称“EmptyArrowIterator”未定义错误

问题描述

问题:当我使用 Python 连接器在 Snowflake 中调用存储过程时,会引发异常,内容为:“未定义名称‘EmptyArrowIterator’”。

我的目标:使用 Snowflake 的 Python 连接器调用存储过程并将返回值保存到变量中。

我尝试了什么: 我按照此 Stack Exchange 帖子中的说明进行操作,但未能成功解决错误。

我的代码:


import pandas as pd
#my code is long...a dataframe called credentials is defined elsewhere in my code and is not shown below

def logging_sproc(credentials):
    try:
        #import snowflake module and binding method
        import snowflake.connector
        #necesary for passing python variables to statements; note this method is server side
        #so there is no concern about SQL injection attacks
        snowflake.connector.paramstyle='qmark'

        #etl logging variables
        etl_name = credentials.iloc[0]['etl_name']
        etl_guid = credentials.iloc[0]['etl_guid']
        etl_taskname = credentials.iloc[0]['etl_task_name']
        etl_record_count = credentials.iloc[0]['record_count']

        #snowflake variables
        snowflake_warehouse = credentials.iloc[0]['snowflake_warehouse']
        snowflake_account = credentials.iloc[0]['snowflake_account']
        snowflake_role = credentials.iloc[0]['snowflake_role']
        snowflake_username = credentials.iloc[0]['Username']
        snowflake_password = credentials.iloc[0]['Password']
        snowflake_connection = ''
        cs = ''#snowflake connection cursor
        call_logging_sproc = ''

        #call the logging stored procedure
        snowflake_connection = snowflake.connector.connect(
        user = snowflake_username,
        password = snowflake_password,
        account = snowflake_account,
        warehouse = snowflake_warehouse,
        role = snowflake_role)
        cs = snowflake_connection.cursor()
        call_logging_sproc = cs.execute("CALL EDW_DEV.LOGGING.LOGGING_SP(?,?,?,?)",(etl_name,etl_guid,etl_taskname,etl_record_count))
    except Exception as error:
        return error
    finally:
        snowflake_connection.close()
    return  call_logging_sproc

logging_sp = logging_sproc(credentials)

谢谢您的帮助!

标签: snowflake-cloud-data-platform

解决方案


我添加了 call_logging_sproc.fetchmany(1) 并且错误消失了。


推荐阅读