-
Notifications
You must be signed in to change notification settings - Fork 6
TABLE statement
#52
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
Merged
Merged
TABLE statement
#52
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from typing import Optional, List, Any | ||
|
|
||
| from mindsdb_sql_parser.ast.base import ASTNode | ||
|
|
||
|
|
||
| class Table(ASTNode): | ||
| """AST node representing a TABLE statement with optional ORDER BY, LIMIT, and OFFSET clauses. | ||
| https://dev.mysql.com/doc/refman/8.4/en/table.html | ||
|
|
||
| Args: | ||
| name: The name of the table (Identifier). | ||
| order_by: Optional list of ORDER BY terms. | ||
| limit: Optional LIMIT value (Constant). | ||
| offset: Optional OFFSET value (Constant). | ||
| *args: Additional positional arguments for ASTNode. | ||
| **kwargs: Additional keyword arguments for ASTNode. | ||
| """ | ||
| def __init__( | ||
| self, | ||
| name: Any, | ||
| order_by: Optional[List[Any]] = None, | ||
| limit: Optional[Any] = None, | ||
| offset: Optional[Any] = None, | ||
| *args, | ||
| **kwargs | ||
| ): | ||
| super().__init__(*args, **kwargs) | ||
| self.name = name | ||
| self.order_by = order_by | ||
| self.limit = limit | ||
| self.offset = offset | ||
|
|
||
| def to_tree(self, *args, level: int = 0, **kwargs) -> str: | ||
| """Returns a string representation of the AST tree for this node. | ||
|
|
||
| Args: | ||
| level: Indentation level for pretty printing. | ||
| *args: Additional positional arguments. | ||
| **kwargs: Additional keyword arguments. | ||
|
|
||
| Returns: | ||
| str: The tree representation of the node. | ||
| """ | ||
| ind = ' ' * level | ||
| out = f'{ind}Table(\n' | ||
| out += f'{ind} name={self.name},\n' | ||
| if self.order_by: | ||
| out += f'{ind} order_by={self.order_by},\n' | ||
| if self.limit: | ||
| out += f'{ind} limit={self.limit},\n' | ||
| if self.offset: | ||
| out += f'{ind} offset={self.offset},\n' | ||
| out += f'{ind})' | ||
| return out | ||
|
|
||
| def to_string(self, *args, **kwargs) -> str: | ||
| """Returns a SQL string representation of the TABLE statement. | ||
|
|
||
| Args: | ||
| *args: Additional positional arguments. | ||
| **kwargs: Additional keyword arguments. | ||
|
|
||
| Returns: | ||
| str: The SQL string representation. | ||
| """ | ||
| s = f'TABLE {self.name}' | ||
| if self.order_by: | ||
| s += ' ORDER BY ' + ', '.join([o.to_string() for o in self.order_by]) | ||
| if self.limit: | ||
| s += f' LIMIT {self.limit.to_string()}' | ||
| if self.offset: | ||
| s += f' OFFSET {self.offset.to_string()}' | ||
| return s | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
table ais the same asselect * from a, why to not parse it as CreateTable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you mean
Select.Indeed,
select aandselect * from aare equivalent. I prefer to have separateTableclass becauseSelectandTableare separate statements. However, it would be much easier to render this statement to different dialects if it will beSelect, so i changed it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I meant Select