Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从熊猫到雪花回滚的数据加载_Python_Pandas_Sqlalchemy_Snowflake Cloud Data Platform - Fatal编程技术网

Python 从熊猫到雪花回滚的数据加载

Python 从熊猫到雪花回滚的数据加载,python,pandas,sqlalchemy,snowflake-cloud-data-platform,Python,Pandas,Sqlalchemy,Snowflake Cloud Data Platform,我试图用熊猫将数据推送到雪花表中,但奇怪的事情发生了。数据加载到雪花表中(我可以看到),几秒钟后(比如2秒钟),我就看不到任何记录。我不知道这里发生了什么 这是我的代码块。如果我能得到一些帮助,我将非常感激 connection = create_engine( 'snowflake://{user}:{password}@{account}/{database}/{schema}?warehouse={warehouse}'.format( user=''xxxxx,

我试图用熊猫将数据推送到雪花表中,但奇怪的事情发生了。数据加载到雪花表中(我可以看到),几秒钟后(比如2秒钟),我就看不到任何记录。我不知道这里发生了什么

这是我的代码块。如果我能得到一些帮助,我将非常感激

connection = create_engine(
    'snowflake://{user}:{password}@{account}/{database}/{schema}?warehouse={warehouse}'.format(
        user=''xxxxx,
        password='xxxxx',
        account='xxxx.xxxx-xxxxxxxx-1',
        warehouse='xxxx',
        database='xxxxx',
        schema='xxxxxx'
    )
)

Transformation

with connection.connect().execution_options(autocommit=True) as conn:
  check_sql = "select * from subscription_changes_new"
  check_df = pd.read_sql(check_sql, conn)
  if len(check_df) > 0:
    conn.execute(text("delete from subscription_changes_new'"))
    subscription_changes.to_sql('subscription_changes_new', conn, if_exists='append', index=False, index_label=None)
  elif len(check_df) == 0:
    subscription_changes.to_sql('subscription_changes_new', conn, if_exists='append', index=False, index_label=None)  
  else:
    None

我使用的是Python3.7

我无法使用Python3.7.9重现这个问题,而且我认为您的代码没有任何问题。您的程序中是否有其他未显示的代码可能会产生影响

要进行故障排除,我建议检查Snowflake中的History选项卡,查看是否有其他进程导致删除。我还建议您更改逻辑以使用以下内容:

with connection.connect().execution_options(autocommit=True) as conn:
    check_sql = "select count(*) as cnt from subscription_changes_new"
    check_df = pd.read_sql(check_sql, conn)

    if check_df.iloc[0, 0] > 0:
        conn.execute(text("delete from subscription_changes_new"))
        subscription_changes.to_sql('subscription_changes_new', conn, if_exists='append', index=False, index_label=None)
        print('I deleted and inserted')
    elif check_df.iloc[0, 0] == 0:
        subscription_changes.to_sql('subscription_changes_new', conn, if_exists='append', index=False, index_label=None)
        print('I just inserted')
    else:
        print('I did nothing')
这将具有相同的效果,但不需要对检查查询进行计算,并且根据表的大小,只需在Snowflake中命中元数据缓存即可提高性能