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: add CI for MySQL #1019

Merged
merged 5 commits into from
Sep 1, 2023
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
68 changes: 68 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ workflows:
- master
- staging
################################
### THIRD PARTY: Staging, Master
################################
################################
- MySQL:
name: Third Party Test - MySQL | v3.10 | Linux
filters:
branches:
only:
- master
- staging
################################
### NOTEBOOKS: Staging, Master
################################
################################
Expand Down Expand Up @@ -274,6 +285,58 @@ jobs:
- test_evadb_doc
- node_modules

MySQL:
parameters:
v:
type: string
default: "3.10"
resource_class: large
docker:
- image: "cimg/python:<< parameters.v >>"
- image: "cimg/mysql:8.0"
environment:
MYSQL_USER: eva
MYSQL_PASSWORD: password
MYSQL_DATABASE: evadb

steps:

- checkout

# Restore pip wheel
- restore_cache:
keys:
- v1-pip-wheel_cache-python<< parameters.v >>-rayDISABLED-{{ checksum "setup.py" }}

- restore_cache:
keys:
- v1-model_cache-{{ checksum "setup.py" }}

- run:
name: Install dockerize
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
environment:
DOCKERIZE_VERSION: v0.6.1

- run:
name: Wait for DB to run
command : dockerize -wait tcp://localhost:3306 -timeout 1m

- run:
name: Install EvaDB package from GitHub repo with all dependencies
command: |
"python<< parameters.v >>" -m venv test_evadb
pip install --upgrade pip
source test_evadb/bin/activate
pip install ".[dev]"
pip install -r evadb/third_party/databases/mysql/requirements.txt

- run:
name: Run integration tests
command: |
source test_evadb/bin/activate
PYTHONPATH="." python -m pytest test/third_party_tests/test_native_executor.py -k test_should_run_query_in_mysql

Postgres:
parameters:
v:
Expand All @@ -292,6 +355,11 @@ jobs:

- checkout

# Restore pip wheel
- restore_cache:
keys:
- v1-pip-wheel_cache-python<< parameters.v >>-rayDISABLED-{{ checksum "setup.py" }}

- restore_cache:
keys:
- v1-model_cache-{{ checksum "setup.py" }}
Expand Down
23 changes: 22 additions & 1 deletion evadb/third_party/databases/mysql/mysql_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def get_columns(self, table_name: str) -> DBHandlerResponse:
return DBHandlerResponse(data=None, error="Not connected to the database.")

try:
query = f"SELECT column_name as 'column_name' FROM information_schema.columns WHERE table_name='{table_name}'"
query = f"SELECT column_name as 'name', data_type as dtype FROM information_schema.columns WHERE table_name='{table_name}'"
columns_df = pd.read_sql_query(query, self.connection)
columns_df["dtype"] = columns_df["dtype"].apply(self._mysql_to_python_types)
return DBHandlerResponse(data=columns_df)
except mysql.connector.Error as e:
return DBHandlerResponse(data=None, error=str(e))
Expand Down Expand Up @@ -109,3 +110,23 @@ def execute_native_query(self, query_string: str) -> DBHandlerResponse:
return DBHandlerResponse(data=self._fetch_results_as_df(cursor))
except mysql.connector.Error as e:
return DBHandlerResponse(data=None, error=str(e))

def _mysql_to_python_types(self, mysql_type: str):
mapping = {
"char": str,
"varchar": str,
"text": str,
"boolean": bool,
"integer": int,
"int": int,
"float": float,
"double": float,
# Add more mappings as needed
}

if mysql_type in mapping:
return mapping[mysql_type]
else:
raise Exception(
f"Unsupported column {mysql_type} encountered in the mysql table. Please raise a feature request!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add the link to our Slack in this message (https://evadb.ai/community)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add self.connection = None in the base class. Else it throws property not found in some cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by the link?

)
1 change: 1 addition & 0 deletions evadb/third_party/databases/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DBHandler:

def __init__(self, name: str, **kwargs):
self.name = name
self.connection = None

def connect(self):
"""
Expand Down
4 changes: 0 additions & 4 deletions test/third_party_tests/test_native_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ def test_should_run_query_in_mysql(self):
self._execute_native_query()
self._execute_evadb_query()

# Test error.
self._raise_error_on_multiple_creation()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is actually invariant on which database engine we use. I currently just test on Postgres, so we should skip here.

self._raise_error_on_invalid_connection()


if __name__ == "__main__":
unittest.main()