Skip to content

Commit

Permalink
Merge pull request #405 from mindsdb/table-dqoted
Browse files Browse the repository at this point in the history
Support double-quoted identifier
  • Loading branch information
ea-rus authored Sep 20, 2024
2 parents 0f7a688 + 53a402f commit 6e39d2e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
10 changes: 5 additions & 5 deletions mindsdb_sql/parser/dialects/mindsdb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,16 +1691,16 @@ def identifier(self, p):
node.parts += p[2].parts
return node

@_('id')
def identifier(self, p):
value = p[0]
return Identifier.from_path_str(value)

@_('quote_string',
'dquote_string')
def string(self, p):
return p[0]

@_('id', 'dquote_string')
def identifier(self, p):
value = p[0]
return Identifier.from_path_str(value)

@_('PARAMETER')
def parameter(self, p):
return Parameter(value=p.PARAMETER)
Expand Down
5 changes: 2 additions & 3 deletions mindsdb_sql/render/sqlalchemy_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ def prepare_case(self, t: ast.Case):
conditions.append(
(self.to_expression(condition), self.to_expression(result))
)
else_ = None
if t.default is not None:
else_ = self.to_expression(t.default)
conditions.append(self.to_expression(t.default))

return sa.case(conditions, else_=else_)
return sa.case(*conditions)

def to_function(self, t):
op = getattr(sa.func, t.op)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_parser/test_base_sql/test_select_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,3 +1124,13 @@ def test_alternative_casting(self):
ast = parse_sql(sql)
assert str(ast) == str(expected_ast)

def test_table_double_quote(self):
expected_ast = Select(
targets=[Identifier('account_id')],
from_table=Identifier(parts=['order'])
)

sql = 'select account_id from "order"'

ast = parse_sql(sql)
assert str(ast) == str(expected_ast)
1 change: 1 addition & 0 deletions tests/test_render/test_sqlalchemyrender.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def parse_sql2(sql, dialect='mindsdb'):
or 'current_user()' in sql # replaced to CURRENT_USER
or 'user()' in sql # replaced to USER
or 'not exists' in sql # replaced to not(exits(
or "WHEN R.DELETE_RULE = 'CASCADE'" in sql # wrapped in parens by sqlalchemy
):

# sqlalchemy could add own aliases for constant
Expand Down

0 comments on commit 6e39d2e

Please sign in to comment.