Skip to content

Commit

Permalink
Merge pull request #284 from mindsdb/staging
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
ea-rus authored Aug 4, 2023
2 parents c5520b0 + ae16515 commit 0a8d55b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Only one renderer is available at the moment: SqlalchemyRender.
It uses [imperative](https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#orm-imperative-mapping) mapping for this
- Then created sqlalchemy object is compiled inside sqlalchemy using chosen dialect

Supported dialects at the moment: mysql, postgresql, sqlite, mssql, firebird, oracle, sybase
Supported dialects at the moment: mysql, postgresql, sqlite, mssql, oracle

Notes:
- it is not possible to use more than 2 part in table name
Expand Down
2 changes: 1 addition & 1 deletion mindsdb_sql/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'mindsdb_sql'
__package_name__ = 'mindsdb_sql'
__version__ = '0.6.7'
__version__ = '0.7.0'
__description__ = "Pure python SQL parser"
__email__ = "[email protected]"
__author__ = 'MindsDB Inc'
Expand Down
3 changes: 2 additions & 1 deletion mindsdb_sql/parser/dialects/mindsdb/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MindsDBLexer(Lexer):
GLOBAL, PROCEDURE, FUNCTION, INDEX, WARNINGS,
ENGINES, CHARSET, COLLATION, PLUGINS, CHARACTER,
PERSIST, PERSIST_ONLY, DEFAULT,
IF_EXISTS, COLUMNS, FIELDS, COLLATE,
IF_EXISTS, COLUMNS, FIELDS, COLLATE, SEARCH_PATH,
# SELECT Keywords
WITH, SELECT, DISTINCT, FROM, WHERE, AS,
LIMIT, OFFSET, ASC, DESC, NULLS_FIRST, NULLS_LAST,
Expand Down Expand Up @@ -182,6 +182,7 @@ class MindsDBLexer(Lexer):
INDEXES = r'\bINDEXES\b'
REPLACE = r'\bREPLACE\b'
COLLATE = r'\bCOLLATE\b'
SEARCH_PATH = r'\bSEARCH_PATH\b'

# SELECT

Expand Down
1 change: 1 addition & 0 deletions mindsdb_sql/parser/dialects/mindsdb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ def show(self, p):
'MODELS',
'ML_ENGINES',
'HANDLERS',
'SEARCH_PATH',
'ALL')
def show_category(self, p):
return ' '.join([x for x in p])
Expand Down
18 changes: 11 additions & 7 deletions mindsdb_sql/render/sqlalchemy_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import sqlalchemy as sa
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm.query import aliased
from sqlalchemy.dialects import mysql, postgresql, sqlite, mssql, firebird, oracle, sybase
from sqlalchemy.orm import aliased
from sqlalchemy.dialects import mysql, postgresql, sqlite, mssql, oracle
from sqlalchemy.schema import CreateTable, DropTable

from mindsdb_sql.parser import ast


sa_type_names = [
key for key, val in sa.types.__dict__.items() if hasattr(val, '__module__')
and val.__module__ in ('sqlalchemy.sql.sqltypes', 'sqlalchemy.sql.type_api')
]


class RenderError(Exception):
...

Expand All @@ -22,9 +28,7 @@ def __init__(self, dialect_name):
'postgres': postgresql,
'sqlite': sqlite,
'mssql': mssql,
'firebird': firebird,
'oracle': oracle,
'sybase': sybase,
'Snowflake': oracle,
}

Expand All @@ -46,7 +50,7 @@ def __init__(self, dialect_name):
self.dialect.server_version_info = (8, 0, 17)

self.types_map = {}
for type_name in sa.types.__all__:
for type_name in sa_type_names:
self.types_map[type_name.upper()] = getattr(sa.types, type_name)

def to_column(self, parts):
Expand Down Expand Up @@ -129,7 +133,7 @@ def to_expression(self, t):
methods = {
"+": "__add__",
"-": "__sub__",
"/": "__div__",
"/": "__truediv__",
"*": "__mul__",
"%": "__mod__",
"=": "__eq__",
Expand Down Expand Up @@ -330,7 +334,7 @@ def prepare_select(self, node):
col = self.to_expression(t)
cols.append(col)

query = sa.select(cols)
query = sa.select(*cols)

if node.cte is not None:
for cte in node.cte:
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
sly>=0.4
pytest>=5.4.3
sqlalchemy >= 1.4.29, < 2.0.0
sqlalchemy >= 2.0.0, < 3.0.0
7 changes: 2 additions & 5 deletions tests/test_render/test_sqlalchemyrender.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,20 @@ def clear_target_aliases(node, **args):
assert query2.to_tree() == query_.to_tree()

# step 2: render to different dialects
dialects = ('postgresql', 'sqlite', 'mssql',
'firebird', 'oracle', 'sybase')
dialects = ('postgresql', 'sqlite', 'mssql', 'oracle')

for dialect2 in dialects:

try:
SqlalchemyRender(dialect2).get_string(query, with_failback=False)
except Exception as e:
# skips for dialects
if dialect2 in ('firebird', 'oracle', 'sybase') \
if dialect2 == 'oracle' \
and 'does not support in-place multirow inserts' in str(e):
pass
elif dialect2 == 'mssql' \
and 'requires an order_by when using an OFFSET or a non-simple LIMIT clause' in str(e):
pass
elif dialect2 == 'sybase' and 'for update' in sql.lower():
pass
elif dialect2 == 'sqlite' and 'extract(MONTH' in sql:
pass
else:
Expand Down

0 comments on commit 0a8d55b

Please sign in to comment.