maxcompute 数据导出到本地Mysql
用PyODPS可以写成这样,mysql那边使用sqlalchemyimport itertools
from sqlalchemy import create_engine, MetaData, Table
from odps.df import DataFrame
DB_CONNECT_STR = 'mysql+mysqldb://root:@localhost/mydb?charset=utf8'
engine = create_engine(DB_CONNECT_STR, echo=True)
conn = engine.connect()
metadata = MetaData(engine)
table = Table('mysql_table', metadata, autoload=True)
df = DataFrame(odps.get_table('my_demo_table', project='my_project'))
selected = df.filter(df.pdate == '')['imei', 'time_in', 'ntotalvote', 'ntotalcurr']
records = []
for i, record in zip(itertools.count(1), selected.execute()):
if i % 100:
conn.execute(conn.insert(), [dict(r) for r in records])
records = []
records.append(record)
if records:
conn.execute(conn.insert(), [dict(r) for r in records])
赞0
踩0