sql-machine-learning / sqlflow

Brings SQL and AI together.
https://sqlflow.org
Apache License 2.0
5.09k stars 698 forks source link

The sqlflow client should not execute SQL statement like USE #2295

Open wangkuiyi opened 4 years ago

wangkuiyi commented 4 years ago

I noticed the following code snippet in sqlflow client

https://github.com/sql-machine-learning/sqlflow/blob/94153c2b5c1133de7184b36df0663ad545d4ad09/cmd/sqlflow/main.go#L275-L287

If the sqlflow client directs the DBMS to run the USE statement, and the generated workflow directs the DMBS to run the rest statements, how could we make sure that all statements run in the order they appear in the SQL program?

shendiaomo commented 4 years ago

I noticed the following code snippet in sqlflow client

https://github.com/sql-machine-learning/sqlflow/blob/94153c2b5c1133de7184b36df0663ad545d4ad09/cmd/sqlflow/main.go#L275-L287

If the sqlflow client directs the DBMS to run the USE statement, and the generated workflow directs the DMBS to run the rest statements, how could we make sure that all statements run in the order they appear in the SQL program?

sqlflow_server is stateless, it connects to Request.session.db_conn_str defined in pkg/proto/sqlflow.proto. Request is assembled by the sqlflow client and passed to sqlflow_server though an RPC call.

USE db is a client-side command, after a successful call to switchDatabase, the Request.session.db_conn_str in the client code will point to the new database, thus making sure all successive RPC calls to sqlflow_server carrying the switched database in Request.session.db_conn_str. As a result, the SQL statements after a successful USE db will use the correct database before another USE db statement.