簡體   English   中英

使用Python從Oracle以數據幀的形式讀取海量數據的最快方法

[英]Fastest way to read huge volume of data as dataframe from Oracle using Python

我需要從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編寫的。

http://www.pivotalguru.com/?page_id=20

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM