python-3.x - 有没有办法将 python 脚本转换为一个类或一个包?
问题描述
我分三个阶段将数据从 IBM 迁移到 Snowflake - 提取、转换和加载。
下面是连接源 IBM 和执行 ETL 的目标 Snowflake 的 python 代码。有什么办法可以从下面的整个代码中创建一个类/包?
import snowflake.connector
tableName='F58001'
ctx = snowflake.connector.connect(
user='*',
password='*',
account='*.azure'
)
cs = ctx.cursor()
ctx.cursor().execute("USE DATABASE STORE_PROFILE")
ctx.cursor().execute("USE SCHEMA LANDING")
try:
ctx.cursor().execute("PUT file:///temp/data/{tableName}/* @%{tableName}".format(tableName=tableName))
except Exception:
pass
ctx.cursor().execute("truncate table {tableName}".format(tableName=tableName))
ctx.cursor().execute("COPY INTO {tableName} ON_ERROR = 'CONTINUE' ".format(tableName=tableName,
FIELD_OPTIONALLY_ENCLOSED_BY = '""', sometimes=',', ERROR_ON_COLUMN_COUNT_MISMATCH = 'TRUE'))
last_query_id= ctx.cursor().execute("select last_query_id()")
for res in last_query_id:
query_id = res[0]
ctx.cursor().execute(f"create or replace table save_copy_errors as select * from
table(validate("+tableName+", job_id=> "+"'"+query_id+"'"+"))")
ax = ctx.cursor().execute("select * from save_copy_errors")
for errors in ax:
error = errors
print(error)
ctx.close()
解决方案
请查看以下存储库。它可能已经回答了你的问题。我目前正在努力将其移至 PYPI,以便可以使用 PIP 安装它
https://github.com/Infosys/Snowflake-Python-Development-Framework
推荐阅读
- android - 在 Android 问题中插入动态视图
- javascript - 如何获取鼠标单击的位置并在图像上添加标记(标记)?
- azure - 使用 Azure CNI 和站点到站点 VPN VNet 时如何从 pod 子网中拆分 AKS 群集子网
- kubernetes - 将 Kubernetes 中的各个点联系起来的良好做法是什么?
- amazon-web-services - 如何防止 Terraform 模块创建重复的 API 网关资源?
- javascript - 如何在一个导入的对象中组合 CSS 类
- javascript - 每个 React 类方法的“函数缺少返回类型”
- vue.js - Vuetify 进度条不同步值
- android - RxJava 和 Observable 改造 API 调用
- firebase - Firebase - 从域 A 重定向到域 B