09:21目的:将Secretflow通过读取CSV文件获取数据,修改为 传入的CSV文件中包含了数据库的连接串信息,底层通过连接串信息去查询MYSQL,然后返回DF #1315
Unanswered
secretflowcode
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
思路:修改secretflow/data/core/io.py,通过修改_read_csv方法,分析CSV文件得到连接串,然后请求MYSQL获取数据
实现代码:
secretflow/data/core/io.py修改如下
def _read_csv(_filepath, _backend, *_args, **_kwargs):
import select_sql
df = pd.read_csv(_filepath)
url = df.iloc[0, 0]
port = df.iloc[0, 1]
username = df.iloc[0, 2]
password = df.iloc[0, 3]
database = df.iloc[0, 4]
table = df.iloc[0, 5]
columns = list(df.columns)
return select_sql.fetch_data_from_mysql(url, port, username, password, database, table, columns)
select_sql.py实现如下
import pymysql
import pandas as pd
def fetch_data_from_mysql(url, port, username, password, database, table, columns):
connection = pymysql.connect(
host=url,
port=int(port),
user=username,
password=password,
database=database,
charset='utf8mb4'
)
Beta Was this translation helpful? Give feedback.
All reactions