我正在尝试在Python中创建以下类
到目前为止,我所拥有的几乎都可以使用,但是它不会更新第二个文件中的电子邮件。当我在Pycharm中运行调试器时,我得到了正确的更新行数,但似乎没有提交给表。根据我在网上看到的内容,我无法选择提交任何内容。我还提取了传递给python的查询,它在Oracle中正确运行。我不确定这是Oracle问题还是在Python中做错了。任何帮助将不胜感激
这是代码
class OracleETL:
def __init__(self):
self.engine = create_engine(config.ORACLE)
def __enter__(self):
self.conn = self.engine.connect()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.conn.close()
def upload_to_oracle(self, direct):
for f in os.listdir(direct):
df = pd.read_csv(os.path.join(direct,f), sep=',', index_col=None, dtype=str)
db_types = {c: types.VARCHAR(255)
for c in df.columns[df.dtypes == 'object'].tolist()}
df.to_sql(name=os.path.splitext(f)[0],con=self.conn, if_exists='replace',
dtype=db_types, index=False)
def add_email_column(self, tablename, email_col='EMAIL'):
query = q.add_email_column % (tablename, email_col)
self.conn.execute(query)
def match_emails_to_file(self, tablename, email_col='EMD5'):
query = q.merge_emails % (tablename.upper(), email_col)
self.conn.execute(query)
这是合并查询:
MERGE /*+ PARALLEL(T1,32) PARALLEL(T2,32) USE_HASH(T1,T2)*/
INTO "%s" T1
USING (
SELECT * FROM "MASTER"
) T2
ON (lower(T1.%s) = lower(T2.EMD5))
WHEN MATCHED THEN
UPDATE
SET T1."EMAIL"=T2."EMAIL