Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use statement #936

Merged
merged 5 commits into from
Aug 18, 2023
Merged

Use statement #936

merged 5 commits into from
Aug 18, 2023

Conversation

jiashenC
Copy link
Member

Working example

USE postgres {
    CREATE TABLE (...)
}

@jiashenC
Copy link
Member Author

@xzdandy @gaurav274 You can give read about the design. I will add more implementations to check in binder/catalog.

@xzdandy
Copy link
Collaborator

xzdandy commented Aug 17, 2023

For use query, we have the option to skip the binder and optimizer using SKIP_BINDER_AND_OPTIMIZER_STATEMENTS. This can simplify the implementation.

@jiashenC
Copy link
Member Author

For use query, we have the option to skip the binder and optimizer using SKIP_BINDER_AND_OPTIMIZER_STATEMENTS. This can simplify the implementation.

I meant just checking if the data source is valid. Not gonna check anything for the native query.

@@ -172,11 +174,19 @@ explain_statement: EXPLAIN explainable_statement

explainable_statement : select_statement | insert_statement | update_statement | delete_statement | create_table

// Context Statements

use_statement: USE database_name "{" query_string "}" // One shortcoming that query string cannot have parenthesis
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the limitation of the lark or ? Why we can not have parenthesis?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this comment. The native query can have parenthesis after I change to use curly bracket if that makes sense

// now
USE postgres {
   // some query
}

// before
USE postgres (
    // some query
)

If I use the parenthesis and the native query has arbitrary parentheses as well, I have some trouble of coming up with a grammar that works for all cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me take care of it

@@ -1239,3 +1240,37 @@ def __hash__(self) -> int:
self.search_query_expr,
)
)


class LogicalUse(Operator):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also bypass optimizer for use? Just to simplify the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will push the code to take care of this

engine = create_engine(conn_str)

with engine.connect() as con:
if "SELECT" in self._query_string or "select" in self._query_string:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make this robust for cases where select is used for creating tables etc. Also, if query contains Select etc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the output for CREATE TABLE from sqlalchemy? Is it possible to simply execute the query and yield whatever output sqlalchemy yields in dataframe type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlalchemy/sqlalchemy#5433 (comment)

Based on what I see, it is still true for this API for latest SQLAlchemy. There is no rows returned besides SELECT.

@gaurav274 gaurav274 merged commit 045db67 into master Aug 18, 2023
@gaurav274 gaurav274 deleted the use-statement branch August 18, 2023 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants