Skip to content

Commit 793f90a

Browse files
committed
fix wrong 'is_quoted' count
1 parent 1244483 commit 793f90a

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

mindsdb_sql_parser/parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,17 +1823,21 @@ def json_value(self, p):
18231823
'identifier DOT star')
18241824
def identifier(self, p):
18251825
node = p[0]
1826-
is_quoted = False
18271826
if isinstance(p[2], Star):
18281827
node.parts.append(p[2])
1828+
node.is_quoted.append(False)
18291829
elif isinstance(p[2], int):
18301830
node.parts.append(str(p[2]))
1831+
node.is_quoted.append(False)
18311832
elif isinstance(p[2], str):
18321833
node.parts.append(p[2])
1834+
node.is_quoted.append(False)
1835+
elif isinstance(p[2], Identifier):
1836+
node.append(p[2])
18331837
else:
1834-
node.parts += p[2].parts
1835-
is_quoted = p[2].is_quoted[0]
1836-
node.is_quoted.append(is_quoted)
1838+
# fallback, shouldn't happen
1839+
node.parts.append(str(p[2]))
1840+
node.is_quoted.append(False)
18371841
return node
18381842

18391843
@_('quote_string',

tests/test_base_sql/test_select_structure.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,10 @@ def test_backticks(self):
714714
sql = "SELECT `name`, `status` FROM `mindsdb`.`wow stuff predictors`.`even-dashes-work`.`nice`"
715715
ast = parse_sql(sql)
716716

717-
expected_ast = Select(targets=[Identifier(parts=['name']), Identifier(parts=['status'])],
718-
from_table=Identifier(parts=['mindsdb', 'wow stuff predictors', 'even-dashes-work', 'nice']),
719-
)
717+
expected_ast = Select(
718+
targets=[Identifier('`name`'), Identifier('`status`')],
719+
from_table=Identifier('`mindsdb`.`wow stuff predictors`.`even-dashes-work`.`nice`'),
720+
)
720721

721722
assert ast.to_tree() == expected_ast.to_tree()
722723
assert str(ast) == str(expected_ast)

tests/test_mindsdb/test_create_predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_create_predictor_quotes(self):
124124
ast = parse_sql(sql)
125125
expected_ast = CreatePredictor(
126126
name=Identifier('xxx'),
127-
integration_name=Identifier('yyy'),
127+
integration_name=Identifier('`yyy`'),
128128
query_str="SELECT * FROM zzz",
129129
targets=[Identifier('sss')],
130130
)

0 commit comments

Comments
 (0)