mindsdb / mindsdb_sql

SQL parser and planner used by MindsDB
https://mindsdb.com
GNU General Public License v3.0
55 stars 21 forks source link

New syntax for creating model from view #379

Open StpMax opened 4 months ago

StpMax commented 4 months ago

At the moment creating model from view require a query to the view:

CREATE or replace MODEL model_name
FROM mindsdb (select * from  view)
PREDICT field_name

will be good to be able use mindsdb.view in the query:

CREATE or replace MODEL model_name
FROM mindsdb.view
PREDICT field_name
NikhilDesai27 commented 3 months ago

Hi @StpMax , I have just started using MindsDB and am eager to help with this. strategy: Add a new syntax rule to MindsDBParser.create_predictor method, so that it can parse .view segment, expand it to (select * from view) and pass it down to CreatePredictor. Please advice on the same. Thanks.

ea-rus commented 3 months ago

Yes I think it should create query from table name and then use it as it uses now For example this query

CREATE my_model FROM mindsdb.my_view PREDICT field_name

Should be converted to

CREATE my_model FROM (select * from mindsdb.my_view) PREDICT field_name

and this

CREATE my_model FROM `my.view` PREDICT field_name

to

CREATE my_model FROM (select * from `my.view`) PREDICT field_name
NikhilDesai27 commented 3 months ago

Hi @ea-rus, Thanks for clarifying this. I would like to work on it. Please assign it to me. Thanks, Nikhil.

NikhilDesai27 commented 3 months ago

Hi @ea-rus, I need one clarification though. Which of the following SQL statements is right?

  1. CREATE MODEL model_name FROM mindsdb (select * from view) PREDICT field_name or,
  2. CREATE MODEL my_model FROM (select * from mindsdb.my_view) PREDICT field_name

I have examined the parsed output of 1, and mindsdb gets passed in as the integration_name and select * from view gets passed in as query_str(raw_query tokens but stringified). I was planning to go by this, which would result in the following query being parsed in the following way, query: CREATE MODEL my_model FROM mindsdb.my_view PREDICT field_name parsed_output: integration_name -> mindsdb, query_str -> "select * from my_view"

Thanks.

ea-rus commented 3 months ago

Both statements (1 and 2) are correct (should be parsed and executed) Yes, I think think it is ok:

query: CREATE MODEL my_model FROM mindsdb.my_view PREDICT field_name parsed_output: integration_name -> mindsdb, query_str -> "select * from my_view"`