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

Update SHOW command #355

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 23 additions & 61 deletions mindsdb_sql/parser/dialects/mindsdb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ def set_item(self, p):
'CHARSET',
)
def charset(self, p):
if hasattr(p, 'SET'):
return f'{p[0]} {p[1]}'
return p[0]

# set transaction
Expand Down Expand Up @@ -523,57 +525,14 @@ def show(self, p):
modes=modes
)

@_('SCHEMAS',
'DATABASES',
'TABLES',
'OPEN TABLES',
'TRIGGERS',
'COLUMNS',
'FIELDS',
'PLUGINS',
'VARIABLES',
'INDEXES',
'KEYS',
'SESSION VARIABLES',
'GLOBAL VARIABLES',
'GLOBAL STATUS',
'SESSION STATUS',
'PROCEDURE STATUS',
'FUNCTION STATUS',
'TABLE STATUS',
'MASTER STATUS',
'STATUS',
'STORAGE ENGINES',
'PROCESSLIST',
'INDEX',
'CREATE TABLE',
'WARNINGS',
'ENGINES',
'CHARSET',
'CHARACTER SET',
'COLLATION',
'BINARY LOGS',
'MASTER LOGS',
'PRIVILEGES',
'PROFILES',
'REPLICAS',
'SLAVE HOSTS',
# Mindsdb specific
'VIEWS',
'STREAMS',
'PREDICTORS',
'INTEGRATIONS',
'DATASOURCES',
'PUBLICATIONS',
'DATASETS',
'MODELS',
'ML_ENGINES',
'HANDLERS',
'SEARCH_PATH',
'KNOWLEDGE_BASES',
'ALL')
@_(
'id',
'id id',
)
def show_category(self, p):
return ' '.join([x for x in p])
if hasattr(p, 'id'):
return p.id
return f"{p.id0} {p.id1}"

# custom show commands
@_('SHOW ENGINE identifier STATUS',
Expand All @@ -585,8 +544,7 @@ def show(self, p):
modes=[p[3]]
)

@_('SHOW FUNCTION CODE identifier',
'SHOW PROCEDURE CODE identifier')
@_('SHOW id id identifier')
def show(self, p):
category = p[1] + ' ' + p[2]
return Show(
Expand Down Expand Up @@ -1135,14 +1093,6 @@ def select(self, p):
select.where = where_expr
return select

# Special cases for keyword-like identifiers
@_('select FROM TABLES')
def select(self, p):
select = p.select
ensure_select_keyword_order(select, 'FROM')
select.from_table = Identifier(p.TABLES)
return select

@_('select FROM from_table_aliased',
'select FROM join_tables_implicit',
'select FROM join_tables')
Expand Down Expand Up @@ -1645,6 +1595,7 @@ def parameter(self, p):
'HORIZON',
'HOSTS',
'INDEXES',
'INDEX',
'INTEGRATION',
'INTEGRATIONS',
'ISOLATION',
Expand Down Expand Up @@ -1686,6 +1637,7 @@ def parameter(self, p):
'STREAM',
'STREAMS',
'TABLES',
'TABLE',
'TRAIN',
'TRANSACTION',
'TRIGGERS',
Expand All @@ -1696,7 +1648,17 @@ def parameter(self, p):
'WARNINGS',
'MODEL',
'MODELS',
'AGENT'
'AGENT',
'SCHEMAS',
'FUNCTION',
'charset',
'PROCEDURE',
'ML_ENGINES',
'HANDLERS',
'BINARY',
'KNOWLEDGE_BASES',
'ALL',
'CREATE',
)
def id(self, p):
return p[0]
Expand Down
8 changes: 0 additions & 8 deletions mindsdb_sql/parser/dialects/mysql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,6 @@ def select(self, p):
select.where = where_expr
return select

# Special cases for keyword-like identifiers
@_('select FROM TABLES')
def select(self, p):
select = p.select
ensure_select_keyword_order(select, 'FROM')
select.from_table = Identifier(p.TABLES)
return select

@_('select FROM from_table_aliased',
'select FROM join_tables_implicit',
'select FROM join_tables')
Expand Down
6 changes: 0 additions & 6 deletions tests/test_parser/test_base_sql/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ def test_show_category(self, dialect):
assert str(ast) == str(expected_ast)
assert ast.to_tree() == expected_ast.to_tree()

def test_show_unknown_category_error(self, dialect):
sql = "SHOW abracadabra"

with pytest.raises(ParsingException):
parse_sql(sql, dialect=dialect)

def test_show_unknown_condition_error(self, dialect):
sql = "SHOW databases WITH"
with pytest.raises(ParsingException):
Expand Down
Loading