Skip to content

Commit 0f6b9bc

Browse files
authored
Merge pull request #64 from mindsdb/fix-FQE-1511
Fix `CreateTable` dump to string
2 parents c632ea4 + ad8e430 commit 0f6b9bc

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

mindsdb_sql_parser/ast/create.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def get_string(self, *args, **kwargs):
9595
type = 'float'
9696
elif issubclass(col.type, sa_types.Text):
9797
type = 'text'
98+
elif hasattr(col.type, '__visit_name__'):
99+
type = col.type.__visit_name__
98100
else:
99101
type = str(col.type)
100102
if col.length is not None:

requirements_test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest>=5.4.3
2+
sqlalchemy >= 2.0.0, < 3.0.0

tests/test_base_sql/test_create.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from sqlalchemy import types as sa_types
23

34
from mindsdb_sql_parser import parse_sql
45
from mindsdb_sql_parser.ast import *
@@ -178,3 +179,16 @@ def test_create(self):
178179
assert str(ast).lower() == str(expected_ast).lower()
179180
assert ast.to_tree() == expected_ast.to_tree()
180181

182+
# test dump of sqlalchemy types
183+
create_table_ast = CreateTable(
184+
name=Identifier('mydb.Persons'),
185+
columns=[
186+
TableColumn(name='PersonID', type=sa_types.Integer),
187+
TableColumn(name='LastName', type=sa_types.Text),
188+
TableColumn(name='CreatedAt', type=sa_types.Date),
189+
]
190+
)
191+
192+
expected_sql = "CREATE TABLE mydb.Persons (PersonID int, LastName text, CreatedAt date)"
193+
194+
assert ' '.join(create_table_ast.to_string().split()) == expected_sql

0 commit comments

Comments
 (0)