Skip to content

Commit

Permalink
Merge pull request #355 from mindsdb/fix-show
Browse files Browse the repository at this point in the history
Update SHOW command
  • Loading branch information
ea-rus authored Feb 28, 2024
2 parents 9285aa7 + 3cf5cbe commit f3ce0a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 75 deletions.
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

0 comments on commit f3ce0a1

Please sign in to comment.