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

Support double-quoted identifier #405

Merged
merged 3 commits into from
Sep 20, 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
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
Loading