4paradigm / OpenMLDB

OpenMLDB is an open-source machine learning database that provides a feature platform computing consistent features for training and inference.
https://openmldb.ai
Apache License 2.0
1.59k stars 321 forks source link

Mock commit statement for open-mysql-db by using panda dataframe #3850

Open tobegit3hub opened 7 months ago

tobegit3hub commented 7 months ago

Describe the feature you'd like

Now we are using sqlalchemy and pandas dataframe. The method of "to_sql" is not supported which uses commit statements.

Here is the example code.

import pandas as pd
from sqlalchemy import create_engine

# Create a Pandas DataFrame (replace this with your actual data)
data = {'id': [1, 2, 3],
        'name': ['Alice', 'Bob', 'Charlie'],
        'age': [25, 30, 35]}
df = pd.DataFrame(data)

# Create a MySQL database engine using SQLAlchemy
engine = create_engine('mysql://username:password@host/db_name')

# Replace 'username', 'password', 'host', and 'db_name' with your actual database credentials

# Define the name of the table in the database where you want to write the data
table_name = 'your_table_name'

# Write the DataFrame 'df' into the MySQL table
df.to_sql(table_name, engine, if_exists='replace', index=False)

# 'if_exists' parameter options:
# - 'fail': If the table already exists, an error will be raised.
# - 'replace': If the table already exists, it will be replaced.
# - 'append': If the table already exists, data will be appended to it.

print("Data written to MySQL table successfully!")

And we may get the error like this.

[1002] create logic plan tree failed--Un-support statement type: CommitStatement'

Additional context

Add any other context or screenshots about the feature request here.