From 34c3723ae5a595e4ab6a835f92d9b4ea12b31e9a Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Sun, 7 Jan 2024 15:38:43 +0100 Subject: [PATCH] Release/v0.5.0 (#30) --- CHANGELOG.md | 15 +- docs/_sources/faq.md.txt | 8 +- .../getting_started/installation.md.txt | 6 + docs/_sources/index.rst.txt | 8 +- docs/_sources/sql_mock.redshift.rst.txt | 37 ++ docs/_sources/sql_mock.snowflake.rst.txt | 37 ++ docs/_sources/usage/redshift/examples.md.txt | 61 +++ docs/_sources/usage/redshift/index.rst.txt | 10 + docs/_sources/usage/redshift/settings.md.txt | 14 + docs/_sources/usage/snowflake/examples.md.txt | 63 +++ docs/_sources/usage/snowflake/index.rst.txt | 10 + docs/_sources/usage/snowflake/settings.md.txt | 13 + docs/faq.html | 10 +- docs/genindex.html | 303 ++++++++++++- docs/getting_started/installation.html | 10 +- docs/getting_started/quickstart.html | 3 +- docs/index.html | 12 + docs/modules.html | 8 +- docs/objects.inv | Bin 1340 -> 1986 bytes docs/py-modindex.html | 44 +- docs/robots.html | 3 +- docs/search.html | 2 + docs/searchindex.js | 2 +- docs/sitemap.xml | 2 +- docs/sql_mock.bigquery.html | 4 +- docs/sql_mock.clickhouse.html | 4 +- docs/sql_mock.html | 14 +- docs/sql_mock.redshift.html | 403 ++++++++++++++++++ docs/sql_mock.snowflake.html | 376 ++++++++++++++++ docs/usage/bigquery/examples.html | 3 +- docs/usage/bigquery/index.html | 3 +- docs/usage/bigquery/settings.html | 3 +- docs/usage/clickhouse/examples.html | 7 +- docs/usage/clickhouse/index.html | 3 +- docs/usage/clickhouse/settings.html | 3 +- docs/usage/dbt.html | 1 + docs/usage/default_values.html | 3 +- docs/usage/defining_table_mocks.html | 7 +- docs/usage/examples.html | 3 +- docs/usage/redshift/examples.html | 194 +++++++++ docs/usage/redshift/index.html | 143 +++++++ docs/usage/redshift/settings.html | 147 +++++++ docs/usage/result_assertion.html | 3 +- docs/usage/snowflake/examples.html | 196 +++++++++ docs/usage/snowflake/index.html | 143 +++++++ docs/usage/snowflake/settings.html | 146 +++++++ docs/usage/your_sql_query_to_test.html | 7 +- docsource/sql_mock.snowflake.rst | 37 ++ pyproject.toml | 2 +- 49 files changed, 2480 insertions(+), 56 deletions(-) create mode 100644 docs/_sources/sql_mock.redshift.rst.txt create mode 100644 docs/_sources/sql_mock.snowflake.rst.txt create mode 100644 docs/_sources/usage/redshift/examples.md.txt create mode 100644 docs/_sources/usage/redshift/index.rst.txt create mode 100644 docs/_sources/usage/redshift/settings.md.txt create mode 100644 docs/_sources/usage/snowflake/examples.md.txt create mode 100644 docs/_sources/usage/snowflake/index.rst.txt create mode 100644 docs/_sources/usage/snowflake/settings.md.txt create mode 100644 docs/sql_mock.redshift.html create mode 100644 docs/sql_mock.snowflake.html create mode 100644 docs/usage/redshift/examples.html create mode 100644 docs/usage/redshift/index.html create mode 100644 docs/usage/redshift/settings.html create mode 100644 docs/usage/snowflake/examples.html create mode 100644 docs/usage/snowflake/index.html create mode 100644 docs/usage/snowflake/settings.html create mode 100644 docsource/sql_mock.snowflake.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a744ae..4cbc02d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +### Changed + +### Fixed + +## [0.5.0] + +**Full Changelog**: https://github.com/DeepLcom/sql-mock/compare/v0.4.0...v0.5.0 + +### Added + * Support for Redshift * Support for Snowflake -### Changed - ## [0.4.0] ### Added @@ -71,7 +79,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.1.2] - 2023-10-26 Initial version. -[Unreleased]: https://github.com/DeepLcom/sql-mock/compare/v0.4.0...HEAD +[Unreleased]: https://github.com/DeepLcom/sql-mock/compare/v0.5.0...HEAD +[0.5.0]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.5.0 [0.4.0]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.4.0 [0.3.1]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.3.1 [0.3.0]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.3.0 diff --git a/docs/_sources/faq.md.txt b/docs/_sources/faq.md.txt index 59dd349..095a1a0 100644 --- a/docs/_sources/faq.md.txt +++ b/docs/_sources/faq.md.txt @@ -5,7 +5,7 @@ We are planning to add more and more supported database systems. However, if your system is not supported yet, you can still use SQL Mock. There are only 2 things you need to do: -### Create your `MockTable` class +### Create your `MockTable` class First, you need to create a `MockTable` class for your database system that inherits from `sql_mock.table_mocks.BaseMockTable`. @@ -27,7 +27,7 @@ from sql_mock.column_mocks import ColumnMock class MyFanceDatabaseColumnMock(ColumnMock): # In case you need some specific logic that overwrites the default behavior, you can do so here - pass + pass class Int(MyFanceDatabaseColumnMock): dtype = "Integer" @@ -44,13 +44,13 @@ Feel free to create a PR on this repository that we can start supporting your da ## I am missing a specific ColumnMock type for my model fields -We implementd some basic column types but it could happen that you don't find the one you need. +We implemented some basic column types but it could happen that you don't find the one you need. Luckily, you can easily create those with the tools provided. The only thing you need to do is to inherit from the `ColumnMock` that is specific to your database system (e.g. `BigQueryColumnMock`) and write classes for the column mocks you are missing. Usually you only need to set the correct `dtype`. This would later be used in the `cast(col to )` expression. ```python # Replace the import with the database system you are using -from sql_mock.bigquery.column_mock import BigQueryColumnMock +from sql_mock.bigquery.column_mock import BigQueryColumnMock class MyFancyMissingColType(BigQueryColumnMock): dtype = "FancyMissingColType" diff --git a/docs/_sources/getting_started/installation.md.txt b/docs/_sources/getting_started/installation.md.txt index baa1fba..0a36650 100644 --- a/docs/_sources/getting_started/installation.md.txt +++ b/docs/_sources/getting_started/installation.md.txt @@ -12,6 +12,12 @@ pip install --upgrade "sql-mock[bigquery]" # Clickhouse pip install --upgrade "sql-mock[clickhouse]" + +# Redshift +pip install --upgrade "sql-mock[redshift]" + +# Snowflake +pip install --upgrade "sql-mock[snowflake]" ``` If you need to modify this source code, install the dependencies using poetry: diff --git a/docs/_sources/index.rst.txt b/docs/_sources/index.rst.txt index 2f84192..b78bacb 100644 --- a/docs/_sources/index.rst.txt +++ b/docs/_sources/index.rst.txt @@ -6,7 +6,7 @@ Welcome to SQL Mock's documentation! ==================================== -The primary purpose of this library is to simplify the testing of SQL data models and queries by allowing users to mock input data and create tests for various scenarios. +The primary purpose of this library is to simplify the testing of SQL data models and queries by allowing users to mock input data and create tests for various scenarios. It provides a consistent and convenient way to test the execution of your query without the need to process a massive amount of data. .. meta:: @@ -27,7 +27,7 @@ It provides a consistent and convenient way to test the execution of your query .. toctree:: :maxdepth: 3 - :caption: Basic Usage + :caption: Basic Usage usage/defining_table_mocks usage/dbt @@ -38,10 +38,12 @@ It provides a consistent and convenient way to test the execution of your query .. toctree:: :maxdepth: 3 - :caption: Database Specifics + :caption: Database Specifics usage/bigquery/index usage/clickhouse/index + usage/redshift/index + usage/snowflake/index .. toctree:: :maxdepth: 3 diff --git a/docs/_sources/sql_mock.redshift.rst.txt b/docs/_sources/sql_mock.redshift.rst.txt new file mode 100644 index 0000000..1a3a286 --- /dev/null +++ b/docs/_sources/sql_mock.redshift.rst.txt @@ -0,0 +1,37 @@ +sql\_mock.redshift package +========================== + +Submodules +---------- + +sql\_mock.redshift.column\_mocks module +--------------------------------------- + +.. automodule:: sql_mock.redshift.column_mocks + :members: + :undoc-members: + :show-inheritance: + +sql\_mock.redshift.settings module +---------------------------------- + +.. automodule:: sql_mock.redshift.settings + :members: + :undoc-members: + :show-inheritance: + +sql\_mock.redshift.table\_mocks module +-------------------------------------- + +.. automodule:: sql_mock.redshift.table_mocks + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: sql_mock.redshift + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/_sources/sql_mock.snowflake.rst.txt b/docs/_sources/sql_mock.snowflake.rst.txt new file mode 100644 index 0000000..ba3ca51 --- /dev/null +++ b/docs/_sources/sql_mock.snowflake.rst.txt @@ -0,0 +1,37 @@ +sql\_mock.snowflake package +=========================== + +Submodules +---------- + +sql\_mock.snowflake.column\_mocks module +---------------------------------------- + +.. automodule:: sql_mock.snowflake.column_mocks + :members: + :undoc-members: + :show-inheritance: + +sql\_mock.snowflake.settings module +----------------------------------- + +.. automodule:: sql_mock.snowflake.settings + :members: + :undoc-members: + :show-inheritance: + +sql\_mock.snowflake.table\_mocks module +--------------------------------------- + +.. automodule:: sql_mock.snowflake.table_mocks + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: sql_mock.snowflake + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/_sources/usage/redshift/examples.md.txt b/docs/_sources/usage/redshift/examples.md.txt new file mode 100644 index 0000000..f736773 --- /dev/null +++ b/docs/_sources/usage/redshift/examples.md.txt @@ -0,0 +1,61 @@ +```{toctree} +:maxdepth: 2 +``` + +# Example: Testing Subscription Counts in ClickHouse + +```python +import datetime +from sql_mock.redshift import column_mocks as col +from sql_mock.redshift.table_mocks import RedshiftMockTable +from sql_mock.table_mocks import table_meta + +# Define mock tables for your data model that inherit from RedshiftMockTable +@table_meta(table_ref="data.users") +class UserTable(RedshiftMockTable): + user_id = col.INTEGER(default=1) + user_name = col.VARCHAR(default="Mr. T") + + +@table_meta(table_ref="data.subscriptions") +class SubscriptionTable(RedshiftMockTable): + subscription_id = col.INTEGER(default=1) + period_start_date = col.DATE(default=datetime.date(2023, 9, 5)) + period_end_date = col.DATE(default=datetime.date(2023, 9, 5)) + user_id = col.INTEGER(default=1) + +# Define a mock table for your expected results +class SubscriptionCountTable(RedshiftMockTable): + subscription_count = col.INTEGER(default=1) + user_id = col.INTEGER(default=1) + +# Your original SQL query +query = """ +SELECT + count(*) AS subscription_count, + user_id +FROM data.users +LEFT JOIN data.subscriptions USING(user_id) +GROUP BY user_id +""" + +# Create mock data for the 'data.users' and 'data.subscriptions' tables +users = UserTable.from_dicts([{'user_id': 1}, {'user_id': 2}]) +subscriptions = SubscriptionTable.from_dicts([ + {'subscription_id': 1, 'user_id': 1}, + {'subscription_id': 2, 'user_id': 1}, + {'subscription_id': 2, 'user_id': 2}, +]) + +# Define your expected results +expected = [ + {'user_id': 1, 'subscription_count': 2}, + {'user_id': 2, 'subscription_count': 1} +] + +# Simulate the SQL query using SQL Mock +res = SubscriptionCountTable.from_mocks(query=query, input_data=[users, subscriptions]) + +# Assert the results +res.assert_equal(expected) +``` diff --git a/docs/_sources/usage/redshift/index.rst.txt b/docs/_sources/usage/redshift/index.rst.txt new file mode 100644 index 0000000..b2f7caa --- /dev/null +++ b/docs/_sources/usage/redshift/index.rst.txt @@ -0,0 +1,10 @@ +Redshift +===================== + +This section documents the specifics on how to use SQL Mock with Redshift + +.. toctree:: + :maxdepth: 4 + + ./settings.md + ./examples.md diff --git a/docs/_sources/usage/redshift/settings.md.txt b/docs/_sources/usage/redshift/settings.md.txt new file mode 100644 index 0000000..fdf1ba0 --- /dev/null +++ b/docs/_sources/usage/redshift/settings.md.txt @@ -0,0 +1,14 @@ +```{toctree} +:maxdepth: 2 +``` + +# Settings + +In order to use SQL Mock with Redshift, you need to provide the following environment variables when you run tests: + +* `SQL_MOCK_REDSHIFT_HOST`: The host of your Redshift instance +* `SQL_MOCK_REDSHIFT_USER`: The user of your Redshift instance +* `SQL_MOCK_REDSHIFT_PASSWORD`: The password of your Redshift instance +* `SQL_MOCK_REDSHIFT_PORT`: The port of your Redshift instance + +Having those environment variables enables SQL Mock to connect to your Redshift instance. diff --git a/docs/_sources/usage/snowflake/examples.md.txt b/docs/_sources/usage/snowflake/examples.md.txt new file mode 100644 index 0000000..645621b --- /dev/null +++ b/docs/_sources/usage/snowflake/examples.md.txt @@ -0,0 +1,63 @@ +```{toctree} +:maxdepth: 2 +``` + +# Example: Testing Subscription Counts in Snowflake + +```python +import datetime +from sql_mock.snowflake import column_mocks as col +from sql_mock.snowflake.table_mocks import SnowflakeMockTable +from sql_mock.table_mocks import table_meta + +# Define mock tables for your data model that inherit from SnowflakeMockTable +@table_meta(table_ref="data.users") +class UserTable(SnowflakeMockTable): + user_id = col.INTEGER(default=1) + user_name = col.STRING(default="Mr. T") + + +@table_meta(table_ref="data.subscriptions") +class SubscriptionTable(SnowflakeMockTable): + subscription_id = col.INTEGER(default=1) + period_start_date = col.DATE(default=datetime.date(2023, 9, 5)) + period_end_date = col.DATE(default=datetime.date(2023, 9, 5)) + user_id = col.INTEGER(default=1) + + +# Define a mock table for your expected results +class SubscriptionCountTable(SnowflakeMockTable): + subscription_count = col.INTEGER(default=1) + user_id = col.INTEGER(default=1) + +# Your original SQL query +query = """ +SELECT + count(*) AS subscription_count, + user_id +FROM data.users +LEFT JOIN data.subscriptions USING(user_id) +GROUP BY user_id +""" + +def test_something(): + # Create mock data for the 'data.users' and 'data.subscriptions' tables + users = UserTable.from_dicts([{'user_id': 1}, {'user_id': 2}]) + subscriptions = SubscriptionTable.from_dicts([ + {'subscription_id': 1, 'user_id': 1}, + {'subscription_id': 2, 'user_id': 1}, + {'subscription_id': 2, 'user_id': 2}, + ]) + + # Define your expected results + expected = [ + {"USER_ID": 1, "SUBSCRIPTION_COUNT": 2}, + {"USER_ID": 2, "SUBSCRIPTION_COUNT": 1}, + ] + + # Simulate the SQL query using SQL Mock + res = SubscriptionCountTable.from_mocks(query=query, input_data=[users, subscriptions]) + + # Assert the results + res.assert_equal(expected) +``` diff --git a/docs/_sources/usage/snowflake/index.rst.txt b/docs/_sources/usage/snowflake/index.rst.txt new file mode 100644 index 0000000..6c143df --- /dev/null +++ b/docs/_sources/usage/snowflake/index.rst.txt @@ -0,0 +1,10 @@ +Snowflake +===================== + +This section documents the specifics on how to use SQL Mock with Snowflake + +.. toctree:: + :maxdepth: 4 + + ./settings.md + ./examples.md diff --git a/docs/_sources/usage/snowflake/settings.md.txt b/docs/_sources/usage/snowflake/settings.md.txt new file mode 100644 index 0000000..2c9143d --- /dev/null +++ b/docs/_sources/usage/snowflake/settings.md.txt @@ -0,0 +1,13 @@ +```{toctree} +:maxdepth: 2 +``` + +# Settings + +In order to use SQL Mock with Snowflake, you need to provide the following environment variables when you run tests: + +* `SQL_MOCK_SNOWFLAKE_ACCOUNT`: The name of your Snowflake account +* `SQL_MOCK_SNOWFLAKE_USER`: The name of your Snowflake user +* `SQL_MOCK_SNOWFLAKE_PASSWORD`: The password for your Snowflake user + +Having those environment variables enables SQL Mock to connect to your Snowflake instance. diff --git a/docs/faq.html b/docs/faq.html index 6115b9a..ed6a5aa 100644 --- a/docs/faq.html +++ b/docs/faq.html @@ -61,7 +61,7 @@

Basic Usage