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

feat: migrate to sqlalchemy 2.0 #908

Merged
merged 11 commits into from
Jun 28, 2023
17 changes: 9 additions & 8 deletions evadb/storage/sqlite_storage_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def _dict_to_sql_row(self, dict_row: dict, columns: List[ColumnCatalogEntry]):
dict_row[col.name] = dict_row[col.name].tolist()
return dict_row

def _sql_row_to_dict(self, sql_row: tuple, columns: List[ColumnCatalogEntry]):
def _deserialize_sql_row(self, sql_row: dict, columns: List[ColumnCatalogEntry]):
# Deserialize numpy data
dict_row = {}
for idx, col in enumerate(columns):
if col.type == ColumnType.NDARRAY:
dict_row[col.name] = self._serializer.deserialize(sql_row[idx])
dict_row[col.name] = self._serializer.deserialize(sql_row[col.name])
else:
dict_row[col.name] = sql_row[idx]
dict_row[col.name] = sql_row[col.name]
return dict_row

def _try_loading_table_via_reflection(self, table_name: str):
Expand Down Expand Up @@ -177,14 +177,15 @@ def read(
"""
try:
table_to_read = self._try_loading_table_via_reflection(table.name)
result = self._sql_engine.execute(table_to_read.select())
result = self._sql_session.execute(table_to_read.select())
data_batch = []
row_size = None
for row in result:
# Todo: Verify the order of columns in row matches the table.columns
# For table read, we provide row_id so that user can also retrieve
# row_id from the table.
data_batch.append(self._sql_row_to_dict(row, table.columns))
data_batch.append(
self._deserialize_sql_row(row._asdict(), table.columns)
)
if row_size is None:
row_size = 0
row_size = get_size(data_batch)
Expand All @@ -200,7 +201,7 @@ def read(
raise Exception(err_msg)

def delete(
self, table: TableCatalogEntry, sqlalchemy_filter_clause: ColumnElement[bool]
self, table: TableCatalogEntry, sqlalchemy_filter_clause: "ColumnElement[bool]"
):
"""Delete tuples from the table where rows satisfy the where_clause.
The current implementation only handles equality predicates.
Expand All @@ -212,7 +213,7 @@ def delete(
try:
table_to_delete_from = self._try_loading_table_via_reflection(table.name)
d = table_to_delete_from.delete().where(sqlalchemy_filter_clause)
self._sql_engine.execute(d)
self._sql_session.execute(d)
self._sql_session.commit()
except Exception as e:
err_msg = (
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read(path, encoding="utf-8"):
minimal_requirements = [
"numpy>=1.19.5",
"pandas>=1.1.5",
"sqlalchemy>=1.4.0,<2.0.0", # BREAKING CHANGES IN 2.0.0
"sqlalchemy>=2.0.0",
"sqlalchemy-utils>=0.36.6",
"lark>=1.0.0",
"pyyaml>=5.1",
Expand Down
2 changes: 0 additions & 2 deletions test/integration_tests/test_delete_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from test.markers import macos_skip_marker
from test.util import (
file_remove,
get_evadb_for_testing,
Expand Down Expand Up @@ -123,7 +122,6 @@ def test_should_delete_single_image_in_table(self):
)
)

@macos_skip_marker
def test_should_delete_tuple_in_table(self):
delete_query = """DELETE FROM testDeleteOne WHERE
id < 20 OR dummyfloat < 2 AND id < 5 AND 20 > id
Expand Down