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

Add ci for mysql #1021

Closed
Closed
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
63 changes: 63 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ workflows:
- master
- staging
################################
### THIRD PARTY: Staging, Master
################################
################################
- MySQL:
name: Third Party Test - MySQL | v3.10 | Linux
################################
### NOTEBOOKS: Staging, Master
################################
################################
Expand Down Expand Up @@ -274,6 +280,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 +350,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!"
)