使用Python从Oracle以数据帧形式读取大量数据的最快方法

使用Python从Oracle以数据帧形式读取大量数据的最快方法,python,oracle,postgresql,greenplum,bulk-load,Python,Oracle,Postgresql,Greenplum,Bulk Load,我需要从Oracle读取大量数据(大约100万和450列),并在Greenplum中进行批量加载。我采用以下方法: import pandas as pd from psycopg2 import * from sqlalchemy import create_engine import cx_Oracle import sqlalchemy import psycopg2 as pg import io engineor = create_engine('oracle+cx_oracle:/

我需要从Oracle读取大量数据(大约100万和450列),并在Greenplum中进行批量加载。我采用以下方法:

import pandas as pd
from psycopg2 import *
from sqlalchemy import create_engine
import cx_Oracle
import sqlalchemy
import psycopg2 as pg
import io

engineor = create_engine('oracle+cx_oracle://xxxx:xxxx@xxxxx:xxxx/?service_name=xxxxx')
sql = "select * from xxxxxx"
enginegp = create_engine('xxxxx@xxxxx:xxxx/xxxx')
connection = enginegp.raw_connection()
output = io.StringIO()
for df in pd.read_sql(sql, engineor, chunksize=10000):
df.to_csv(output, header=False, index=False,mode='a')
output.seek(0)
cur = connection.cursor()
cur.copy_expert("COPY test FROM STDIN WITH CSV NULL '' ", output)
connection.commit()
cur.close()
我一直在分块阅读数据:

for df in pd.read_sql(sql, engineor, chunksize=10000):
    df.to_csv(output, header=False, index=False,mode='a')

有没有一种更快、更无缝的方法可以将Oracle中的大表作为数据帧读取?这种方法只能工作,而且似乎并不无缝,因为与Oracle的连接有时会超时或被DBA终止,并且有时会成功运行。考虑到表的大小,似乎不太可靠。我需要将其作为一个数据帧,因为我需要稍后使用复制方法将其加载到Greenplum中。

Outsourcer是专门创建的,用于执行您试图执行的操作,但它是用Java编写的


Greenplum是否支持数据库链接,然后您可以直接连接Oracle和Greenplum,并绕过Python加载数据?我可以获得一台服务器进行安装。为SQL Server提供的链接不再工作。此外,微软似乎只支持SQLJDBC4.1或更高版本。外包商寻找4.0。有办法克服这个问题吗?在os_路径文件中,jar文件4.0到4.1或反之亦然是否有效?或者,因为我只需要Oracle,我可以通过某种方式取消对SQL server的要求吗?您可以将较新的4.1 SQL server驱动程序与Outsourcer一起使用,但如果您只使用Oracle,则根本不需要SQL server jar文件。谢谢,我已经完成了它并生成了UI页面。但是,我从gpfdist得到了这个错误-error:http响应代码400(gpfdist://xxxxxxx:8010/foo#transform=sessions):HTTP/1.0 400无效请求(不支持的输入#转换)(url#u curl.c:454)(seg5 slice1 sdw1.gphd.local:1030 pid=419546)(cdbdisp.c:1322)您使用的Greenplum版本是什么?gpfdist上的转换选项已经存在了相当长的时间。Greenplum 4.3.15.0 build 1。