forked from georgia-tech-db/evadb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'georgia-tech-db:staging' into staging
- Loading branch information
Showing
102 changed files
with
1,148 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
Unit Testing UDFs in EvaDB | ||
=========================== | ||
|
||
Introduction | ||
------------ | ||
|
||
Unit testing is a crucial aspect of software development. When working with User Defined Functions (UDFs) in EvaDB, it's essential to ensure that they work correctly. This guide will walk you through the process of writing unit tests for UDFs and using mocking to simulate external dependencies. | ||
|
||
Setting Up Test Environment | ||
--------------------------- | ||
|
||
Before writing tests, set up a test environment. This often involves creating a test database or table and populating it with sample data. | ||
|
||
.. code-block:: python | ||
def setUp(self) -> None: | ||
self.evadb = get_evadb_for_testing() | ||
self.evadb.catalog().reset() | ||
create_table_query = """CREATE TABLE IF NOT EXISTS TestTable ( | ||
prompt TEXT(100)); | ||
""" | ||
execute_query_fetch_all(self.evadb, create_table_query) | ||
test_prompts = ["sample prompt"] | ||
for prompt in test_prompts: | ||
insert_query = f"""INSERT INTO TestTable (prompt) VALUES ('{prompt}')""" | ||
execute_query_fetch_all(self.evadb, insert_query) | ||
Mocking External Dependencies | ||
----------------------------- | ||
|
||
When testing UDFs that rely on external services or APIs, use mocking to simulate these dependencies. | ||
|
||
.. code-block:: python | ||
@patch("requests.get") | ||
@patch("external_library.Method", return_value={"data": [{"url": "mocked_url"}]}) | ||
def test_udf(self, mock_method, mock_requests_get): | ||
# Mock the response from the external service | ||
mock_response = MagicMock() | ||
mock_response.content = "mocked content" | ||
mock_requests_get.return_value = mock_response | ||
# Rest of the test code... | ||
Writing the Test | ||
---------------- | ||
|
||
After setting up the environment and mocking dependencies, write the test for the UDF. | ||
|
||
.. code-block:: python | ||
function_name = "ImageDownloadUDF" | ||
query = f"SELECT {function_name}(prompt) FROM TestTable;" | ||
output = execute_query_fetch_all(self.evadb, query) | ||
expected_output = [...] # Expected output | ||
self.assertEqual(output, expected_output) | ||
Cleaning Up After Tests | ||
----------------------- | ||
|
||
Clean up any resources used during testing, such as database tables. | ||
|
||
.. code-block:: python | ||
def tearDown(self) -> None: | ||
execute_query_fetch_all(self.evadb, "DROP TABLE IF EXISTS TestTable;") | ||
Running the Tests | ||
----------------- | ||
|
||
Run the tests using a test runner like `unittest`. | ||
|
||
.. code-block:: bash | ||
python -m unittest path_to_your_test_module.py | ||
Conclusion | ||
---------- | ||
|
||
Unit testing UDFs in EvaDB ensures their correctness and robustness. Mocking allows for simulating external dependencies, making tests faster and more deterministic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.. _xgboost: | ||
|
||
Model Training with XGBoost | ||
============================ | ||
|
||
1. Installation | ||
--------------- | ||
|
||
To use the `Flaml XGBoost AutoML framework <https://microsoft.github.io/FLAML/docs/Examples/AutoML-for-XGBoost/>`_, we need to install the extra Flaml dependency in your EvaDB virtual environment. | ||
|
||
.. code-block:: bash | ||
pip install "flaml[automl]" | ||
2. Example Query | ||
---------------- | ||
|
||
.. code-block:: sql | ||
CREATE FUNCTION IF NOT EXISTS PredictRent FROM | ||
( SELECT number_of_rooms, number_of_bathrooms, days_on_market, rental_price FROM HomeRentals ) | ||
TYPE XGBoost | ||
PREDICT 'rental_price'; | ||
In the above query, you are creating a new customized function by training a model from the ``HomeRentals`` table using the ``Flaml XGBoost`` framework. | ||
The ``rental_price`` column will be the target column for predication, while the rest columns from the ``SELET`` query are the inputs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.