spark-data-quality 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. spark_data_quality-1.0.0/LICENSE +21 -0
  2. spark_data_quality-1.0.0/PKG-INFO +123 -0
  3. spark_data_quality-1.0.0/README.md +101 -0
  4. spark_data_quality-1.0.0/pyproject.toml +35 -0
  5. spark_data_quality-1.0.0/setup.cfg +4 -0
  6. spark_data_quality-1.0.0/src/spark_data_quality.egg-info/PKG-INFO +123 -0
  7. spark_data_quality-1.0.0/src/spark_data_quality.egg-info/SOURCES.txt +27 -0
  8. spark_data_quality-1.0.0/src/spark_data_quality.egg-info/dependency_links.txt +1 -0
  9. spark_data_quality-1.0.0/src/spark_data_quality.egg-info/requires.txt +11 -0
  10. spark_data_quality-1.0.0/src/spark_data_quality.egg-info/top_level.txt +1 -0
  11. spark_data_quality-1.0.0/src/spark_dq/__init__.py +3 -0
  12. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/__init__.py +0 -0
  13. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/batch_request.py +23 -0
  14. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/checkpoint_conf.py +30 -0
  15. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/const.py +27 -0
  16. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/datacontext.py +39 -0
  17. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/expectation_suite.py +17 -0
  18. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/ge_utils.py +20 -0
  19. spark_data_quality-1.0.0/src/spark_dq/data_quality_helper/utils.py +50 -0
  20. spark_data_quality-1.0.0/src/spark_dq/helpers/__init__.py +25 -0
  21. spark_data_quality-1.0.0/src/spark_dq/helpers/api_client.py +121 -0
  22. spark_data_quality-1.0.0/src/spark_dq/helpers/exceptions.py +6 -0
  23. spark_data_quality-1.0.0/src/spark_dq/helpers/expectations.py +43 -0
  24. spark_data_quality-1.0.0/src/spark_dq/helpers/ge_executor.py +145 -0
  25. spark_data_quality-1.0.0/src/spark_dq/helpers/sql_utils.py +26 -0
  26. spark_data_quality-1.0.0/src/spark_dq/helpers/trino_executor.py +171 -0
  27. spark_data_quality-1.0.0/src/spark_dq/quality.py +282 -0
  28. spark_data_quality-1.0.0/src/spark_dq/utils.py +32 -0
  29. spark_data_quality-1.0.0/tests/test_imports.py +35 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: spark-data-quality
3
+ Version: 1.0.0
4
+ Summary: SparkDQAgent — Data Quality validation package for K8s Spark pods
5
+ Author-email: khailas <khailas.rangath@saal.ai>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests>=2.28.0
13
+ Requires-Dist: great-expectations==0.18.12
14
+ Requires-Dist: trino>=0.320.0
15
+ Requires-Dist: PyYAML>=6.0
16
+ Provides-Extra: spark
17
+ Requires-Dist: pyspark>=3.1.1; extra == "spark"
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == "dev"
20
+ Requires-Dist: ruff; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # spark-dq
24
+
25
+ Data Quality validation library for K8s Spark pods. Runs Great Expectations + Trino hybrid checks and persists results to the DQ Engine API.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install . # core (GE + Trino)
31
+ pip install ".[spark]" # includes PySpark
32
+ pip install -e ".[dev]" # editable + dev tools
33
+ ```
34
+
35
+ ## Package structure
36
+
37
+ ```
38
+ src/spark_dq/
39
+ ├── quality.py # SparkDQAgent — main orchestrator
40
+ ├── utils.py # JSON serialisation helpers
41
+ ├── helpers/
42
+ │ ├── api_client.py # DQ Engine HTTP client (GET /config, POST /save-results)
43
+ │ ├── expectations.py # Expectation splitting (fast/slow) and result builders
44
+ │ ├── trino_executor.py # Trino fast-path — batched SQL for 5 assertion types
45
+ │ ├── ge_executor.py # GE slow-path — parallel in-memory validators
46
+ │ ├── sql_utils.py # SQL injection prevention utilities
47
+ │ └── exceptions.py # DQEngineAPIError
48
+ └── data_quality_helper/
49
+ ├── const.py # GE datasource config templates
50
+ ├── datacontext.py # In-memory GE DataContext builder
51
+ ├── batch_request.py # RuntimeBatchRequest factory
52
+ ├── expectation_suite.py # Suite builder from assertion dicts
53
+ ├── ge_utils.py # Mapping ID resolution
54
+ └── checkpoint_conf.py # Checkpoint runner (legacy)
55
+ ```
56
+
57
+ ## Usage
58
+
59
+ ### Single table
60
+
61
+ ```python
62
+ from spark_dq.quality import SparkDQAgent
63
+
64
+ agent = SparkDQAgent(
65
+ catalog="my_catalog",
66
+ schema="public",
67
+ table="sales_data",
68
+ data_quality_url="http://dq-engine:8000/api/v1/spark",
69
+ catalog_type="unmanaged",
70
+ table_id=13,
71
+ test_suite_id=37,
72
+ trino_host="trino-host:443",
73
+ trino_user="user",
74
+ trino_pwd="pwd",
75
+ )
76
+
77
+ cfg = agent.get_config() # single GET /config call
78
+ results = agent.validate(df) # hybrid Trino + GE execution
79
+ ```
80
+
81
+ ### Suite run (auto-discover tables)
82
+
83
+ ```python
84
+ agent = SparkDQAgent(
85
+ catalog="", schema="", table="",
86
+ data_quality_url="http://dq-engine:8000/api/v1/spark",
87
+ catalog_type="unmanaged",
88
+ test_suite_id=37,
89
+ )
90
+ table_configs = agent.get_all_table_configs() # returns list of per-table configs
91
+ ```
92
+
93
+ ## Demo
94
+
95
+ ```bash
96
+ # Single table
97
+ python demo.py \
98
+ --catalog khtestpostgresss --schema public --table sales_data_new \
99
+ --dq_url http://localhost:8000/api/v1/spark \
100
+ --trino_host trino-dev.digixt.ae:443 --trino_user datalake --trino_pwd <pwd> \
101
+ --table_id 13 --test_suite_id 37
102
+
103
+ # Suite run (auto-discovers tables)
104
+ python demo.py \
105
+ --test_suite_id 37 \
106
+ --dq_url http://localhost:8000/api/v1/spark \
107
+ --trino_host trino-dev.digixt.ae:443 --trino_user datalake --trino_pwd <pwd>
108
+ ```
109
+
110
+ ## Hybrid execution
111
+
112
+ When Trino credentials are provided, the agent splits expectations into two paths:
113
+
114
+ | Path | Assertion types | How |
115
+ |------|----------------|-----|
116
+ | **Trino fast-path** | `not_be_null`, `be_unique`, `be_between`, `match_regex`, `row_count_to_be_between` | Single batched SQL query |
117
+ | **GE slow-path** | All others | Parallel in-memory GE validators |
118
+
119
+ Both paths run **concurrently**. Results are merged and saved via `POST /save-results`.
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,101 @@
1
+ # spark-dq
2
+
3
+ Data Quality validation library for K8s Spark pods. Runs Great Expectations + Trino hybrid checks and persists results to the DQ Engine API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install . # core (GE + Trino)
9
+ pip install ".[spark]" # includes PySpark
10
+ pip install -e ".[dev]" # editable + dev tools
11
+ ```
12
+
13
+ ## Package structure
14
+
15
+ ```
16
+ src/spark_dq/
17
+ ├── quality.py # SparkDQAgent — main orchestrator
18
+ ├── utils.py # JSON serialisation helpers
19
+ ├── helpers/
20
+ │ ├── api_client.py # DQ Engine HTTP client (GET /config, POST /save-results)
21
+ │ ├── expectations.py # Expectation splitting (fast/slow) and result builders
22
+ │ ├── trino_executor.py # Trino fast-path — batched SQL for 5 assertion types
23
+ │ ├── ge_executor.py # GE slow-path — parallel in-memory validators
24
+ │ ├── sql_utils.py # SQL injection prevention utilities
25
+ │ └── exceptions.py # DQEngineAPIError
26
+ └── data_quality_helper/
27
+ ├── const.py # GE datasource config templates
28
+ ├── datacontext.py # In-memory GE DataContext builder
29
+ ├── batch_request.py # RuntimeBatchRequest factory
30
+ ├── expectation_suite.py # Suite builder from assertion dicts
31
+ ├── ge_utils.py # Mapping ID resolution
32
+ └── checkpoint_conf.py # Checkpoint runner (legacy)
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Single table
38
+
39
+ ```python
40
+ from spark_dq.quality import SparkDQAgent
41
+
42
+ agent = SparkDQAgent(
43
+ catalog="my_catalog",
44
+ schema="public",
45
+ table="sales_data",
46
+ data_quality_url="http://dq-engine:8000/api/v1/spark",
47
+ catalog_type="unmanaged",
48
+ table_id=13,
49
+ test_suite_id=37,
50
+ trino_host="trino-host:443",
51
+ trino_user="user",
52
+ trino_pwd="pwd",
53
+ )
54
+
55
+ cfg = agent.get_config() # single GET /config call
56
+ results = agent.validate(df) # hybrid Trino + GE execution
57
+ ```
58
+
59
+ ### Suite run (auto-discover tables)
60
+
61
+ ```python
62
+ agent = SparkDQAgent(
63
+ catalog="", schema="", table="",
64
+ data_quality_url="http://dq-engine:8000/api/v1/spark",
65
+ catalog_type="unmanaged",
66
+ test_suite_id=37,
67
+ )
68
+ table_configs = agent.get_all_table_configs() # returns list of per-table configs
69
+ ```
70
+
71
+ ## Demo
72
+
73
+ ```bash
74
+ # Single table
75
+ python demo.py \
76
+ --catalog khtestpostgresss --schema public --table sales_data_new \
77
+ --dq_url http://localhost:8000/api/v1/spark \
78
+ --trino_host trino-dev.digixt.ae:443 --trino_user datalake --trino_pwd <pwd> \
79
+ --table_id 13 --test_suite_id 37
80
+
81
+ # Suite run (auto-discovers tables)
82
+ python demo.py \
83
+ --test_suite_id 37 \
84
+ --dq_url http://localhost:8000/api/v1/spark \
85
+ --trino_host trino-dev.digixt.ae:443 --trino_user datalake --trino_pwd <pwd>
86
+ ```
87
+
88
+ ## Hybrid execution
89
+
90
+ When Trino credentials are provided, the agent splits expectations into two paths:
91
+
92
+ | Path | Assertion types | How |
93
+ |------|----------------|-----|
94
+ | **Trino fast-path** | `not_be_null`, `be_unique`, `be_between`, `match_regex`, `row_count_to_be_between` | Single batched SQL query |
95
+ | **GE slow-path** | All others | Parallel in-memory GE validators |
96
+
97
+ Both paths run **concurrently**. Results are merged and saved via `POST /save-results`.
98
+
99
+ ## License
100
+
101
+ MIT
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "spark-data-quality"
7
+ version = "1.0.0"
8
+ description = "SparkDQAgent — Data Quality validation package for K8s Spark pods"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.8"
12
+ authors = [
13
+ { name = "khailas", email = "khailas.rangath@saal.ai" },
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "requests>=2.28.0",
21
+ "great-expectations==0.18.12",
22
+ "trino>=0.320.0",
23
+ "PyYAML>=6.0",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ spark = ["pyspark>=3.1.1"]
28
+ dev = ["pytest", "ruff"]
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
32
+
33
+ [tool.ruff]
34
+ line-length = 100
35
+ target-version = "py38"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: spark-data-quality
3
+ Version: 1.0.0
4
+ Summary: SparkDQAgent — Data Quality validation package for K8s Spark pods
5
+ Author-email: khailas <khailas.rangath@saal.ai>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests>=2.28.0
13
+ Requires-Dist: great-expectations==0.18.12
14
+ Requires-Dist: trino>=0.320.0
15
+ Requires-Dist: PyYAML>=6.0
16
+ Provides-Extra: spark
17
+ Requires-Dist: pyspark>=3.1.1; extra == "spark"
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == "dev"
20
+ Requires-Dist: ruff; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # spark-dq
24
+
25
+ Data Quality validation library for K8s Spark pods. Runs Great Expectations + Trino hybrid checks and persists results to the DQ Engine API.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install . # core (GE + Trino)
31
+ pip install ".[spark]" # includes PySpark
32
+ pip install -e ".[dev]" # editable + dev tools
33
+ ```
34
+
35
+ ## Package structure
36
+
37
+ ```
38
+ src/spark_dq/
39
+ ├── quality.py # SparkDQAgent — main orchestrator
40
+ ├── utils.py # JSON serialisation helpers
41
+ ├── helpers/
42
+ │ ├── api_client.py # DQ Engine HTTP client (GET /config, POST /save-results)
43
+ │ ├── expectations.py # Expectation splitting (fast/slow) and result builders
44
+ │ ├── trino_executor.py # Trino fast-path — batched SQL for 5 assertion types
45
+ │ ├── ge_executor.py # GE slow-path — parallel in-memory validators
46
+ │ ├── sql_utils.py # SQL injection prevention utilities
47
+ │ └── exceptions.py # DQEngineAPIError
48
+ └── data_quality_helper/
49
+ ├── const.py # GE datasource config templates
50
+ ├── datacontext.py # In-memory GE DataContext builder
51
+ ├── batch_request.py # RuntimeBatchRequest factory
52
+ ├── expectation_suite.py # Suite builder from assertion dicts
53
+ ├── ge_utils.py # Mapping ID resolution
54
+ └── checkpoint_conf.py # Checkpoint runner (legacy)
55
+ ```
56
+
57
+ ## Usage
58
+
59
+ ### Single table
60
+
61
+ ```python
62
+ from spark_dq.quality import SparkDQAgent
63
+
64
+ agent = SparkDQAgent(
65
+ catalog="my_catalog",
66
+ schema="public",
67
+ table="sales_data",
68
+ data_quality_url="http://dq-engine:8000/api/v1/spark",
69
+ catalog_type="unmanaged",
70
+ table_id=13,
71
+ test_suite_id=37,
72
+ trino_host="trino-host:443",
73
+ trino_user="user",
74
+ trino_pwd="pwd",
75
+ )
76
+
77
+ cfg = agent.get_config() # single GET /config call
78
+ results = agent.validate(df) # hybrid Trino + GE execution
79
+ ```
80
+
81
+ ### Suite run (auto-discover tables)
82
+
83
+ ```python
84
+ agent = SparkDQAgent(
85
+ catalog="", schema="", table="",
86
+ data_quality_url="http://dq-engine:8000/api/v1/spark",
87
+ catalog_type="unmanaged",
88
+ test_suite_id=37,
89
+ )
90
+ table_configs = agent.get_all_table_configs() # returns list of per-table configs
91
+ ```
92
+
93
+ ## Demo
94
+
95
+ ```bash
96
+ # Single table
97
+ python demo.py \
98
+ --catalog khtestpostgresss --schema public --table sales_data_new \
99
+ --dq_url http://localhost:8000/api/v1/spark \
100
+ --trino_host trino-dev.digixt.ae:443 --trino_user datalake --trino_pwd <pwd> \
101
+ --table_id 13 --test_suite_id 37
102
+
103
+ # Suite run (auto-discovers tables)
104
+ python demo.py \
105
+ --test_suite_id 37 \
106
+ --dq_url http://localhost:8000/api/v1/spark \
107
+ --trino_host trino-dev.digixt.ae:443 --trino_user datalake --trino_pwd <pwd>
108
+ ```
109
+
110
+ ## Hybrid execution
111
+
112
+ When Trino credentials are provided, the agent splits expectations into two paths:
113
+
114
+ | Path | Assertion types | How |
115
+ |------|----------------|-----|
116
+ | **Trino fast-path** | `not_be_null`, `be_unique`, `be_between`, `match_regex`, `row_count_to_be_between` | Single batched SQL query |
117
+ | **GE slow-path** | All others | Parallel in-memory GE validators |
118
+
119
+ Both paths run **concurrently**. Results are merged and saved via `POST /save-results`.
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,27 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/spark_data_quality.egg-info/PKG-INFO
5
+ src/spark_data_quality.egg-info/SOURCES.txt
6
+ src/spark_data_quality.egg-info/dependency_links.txt
7
+ src/spark_data_quality.egg-info/requires.txt
8
+ src/spark_data_quality.egg-info/top_level.txt
9
+ src/spark_dq/__init__.py
10
+ src/spark_dq/quality.py
11
+ src/spark_dq/utils.py
12
+ src/spark_dq/data_quality_helper/__init__.py
13
+ src/spark_dq/data_quality_helper/batch_request.py
14
+ src/spark_dq/data_quality_helper/checkpoint_conf.py
15
+ src/spark_dq/data_quality_helper/const.py
16
+ src/spark_dq/data_quality_helper/datacontext.py
17
+ src/spark_dq/data_quality_helper/expectation_suite.py
18
+ src/spark_dq/data_quality_helper/ge_utils.py
19
+ src/spark_dq/data_quality_helper/utils.py
20
+ src/spark_dq/helpers/__init__.py
21
+ src/spark_dq/helpers/api_client.py
22
+ src/spark_dq/helpers/exceptions.py
23
+ src/spark_dq/helpers/expectations.py
24
+ src/spark_dq/helpers/ge_executor.py
25
+ src/spark_dq/helpers/sql_utils.py
26
+ src/spark_dq/helpers/trino_executor.py
27
+ tests/test_imports.py
@@ -0,0 +1,11 @@
1
+ requests>=2.28.0
2
+ great-expectations==0.18.12
3
+ trino>=0.320.0
4
+ PyYAML>=6.0
5
+
6
+ [dev]
7
+ pytest
8
+ ruff
9
+
10
+ [spark]
11
+ pyspark>=3.1.1
@@ -0,0 +1,3 @@
1
+ """SparkDQAgent — Data Quality validation package for K8s Spark pods."""
2
+
3
+ __version__ = "1.0.0"
@@ -0,0 +1,23 @@
1
+ import logging
2
+ from great_expectations.core.batch import RuntimeBatchRequest
3
+
4
+ logger = logging.getLogger(__name__)
5
+
6
+
7
+ def create_batchrequest(df, datasource_name: str, data_asset_name: str):
8
+ """
9
+ Wrap a pre-loaded Spark DataFrame in a GE RuntimeBatchRequest.
10
+
11
+ The DataFrame is already loaded by ``quality_spark.py`` (either via
12
+ ``spark.sql`` for Iceberg or Trino JDBC for external catalogs).
13
+ No data fetching happens here.
14
+ """
15
+ batch = RuntimeBatchRequest(
16
+ datasource_name=datasource_name,
17
+ data_connector_name="default_runtime_data_connector_name",
18
+ data_asset_name=data_asset_name,
19
+ runtime_parameters={"batch_data": df},
20
+ batch_identifiers={"default_identifier_name": "default_identifier"},
21
+ )
22
+ logger.info("Batch request created from Spark DataFrame")
23
+ return batch
@@ -0,0 +1,30 @@
1
+ from datetime import datetime
2
+
3
+ from spark_dq.data_quality_helper.const import ACTION_LIST, DATETIME_FORMAT
4
+
5
+ # BOOLEAN_ONLY: GE only computes pass/fail per expectation — no unexpected
6
+ # value collection, no data movement back to the driver. This eliminates the
7
+ # hidden per-expectation Spark action that makes validation slow at scale.
8
+ RESULT_FORMAT = {
9
+ "result_format": "BOOLEAN_ONLY",
10
+ "include_unexpected_rows": False,
11
+ "partial_unexpected_count": 0,
12
+ }
13
+
14
+
15
+ def run_checkpoint(context, data_asset_name, expectation_suite_name, batch_request):
16
+ checkpoint = context.add_or_update_checkpoint(
17
+ name=f"{data_asset_name}.{expectation_suite_name}.chk",
18
+ module_name="great_expectations.checkpoint",
19
+ class_name="Checkpoint",
20
+ run_name_template=f'{datetime.now().strftime(DATETIME_FORMAT)}-my-run-name-template',
21
+ )
22
+
23
+ checkpoint_run_result = checkpoint.run(
24
+ run_name=f'{datetime.now().strftime(DATETIME_FORMAT)}-my-run-name-template',
25
+ batch_request=batch_request,
26
+ expectation_suite_name=expectation_suite_name,
27
+ action_list=ACTION_LIST,
28
+ runtime_configuration={"result_format": RESULT_FORMAT},
29
+ )
30
+ return checkpoint_run_result
@@ -0,0 +1,27 @@
1
+ DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
2
+
3
+ DATASOURCE_CONFIG = """
4
+ name: {datasource_name}
5
+ class_name: Datasource
6
+ module_name: great_expectations.datasource
7
+ execution_engine:
8
+ class_name: SparkDFExecutionEngine
9
+ module_name: great_expectations.execution_engine
10
+
11
+ data_connectors:
12
+ default_runtime_data_connector_name:
13
+ class_name: RuntimeDataConnector
14
+ batch_identifiers:
15
+ - default_identifier_name
16
+ """
17
+
18
+ ACTION_LIST = [
19
+ {
20
+ "name": "store_validation_result",
21
+ "action": {"class_name": "StoreValidationResultAction"},
22
+ },
23
+ {
24
+ "name": "store_evaluation_params",
25
+ "action": {"class_name": "StoreEvaluationParametersAction"},
26
+ },
27
+ ]
@@ -0,0 +1,39 @@
1
+ from great_expectations.data_context.types.base import DataContextConfig
2
+
3
+
4
+ def create_datacontext():
5
+ """Build a GE DataContextConfig backed entirely by in-memory stores."""
6
+ return DataContextConfig(
7
+ **{
8
+ "config_version": 1.0,
9
+ "stores": {
10
+ "expectations_store": {
11
+ "class_name": "ExpectationsStore",
12
+ "store_backend": {
13
+ "class_name": "InMemoryStoreBackend",
14
+ },
15
+ },
16
+ "validations_store": {
17
+ "class_name": "ValidationsStore",
18
+ "store_backend": {
19
+ "class_name": "InMemoryStoreBackend",
20
+ },
21
+ },
22
+ "evaluation_parameter_store": {
23
+ "class_name": "EvaluationParameterStore",
24
+ },
25
+ "checkpoint_store": {
26
+ "class_name": "CheckpointStore",
27
+ "store_backend": {
28
+ "class_name": "InMemoryStoreBackend",
29
+ },
30
+ },
31
+ },
32
+ "expectations_store_name": "expectations_store",
33
+ "validations_store_name": "validations_store",
34
+ "evaluation_parameter_store_name": "evaluation_parameter_store",
35
+ "checkpoint_store_name": "checkpoint_store",
36
+ "data_docs_sites": {},
37
+ "anonymous_usage_statistics": {"enabled": False},
38
+ }
39
+ )
@@ -0,0 +1,17 @@
1
+ from great_expectations.core.expectation_configuration import ExpectationConfiguration
2
+
3
+
4
+ def create_expectation_function(expectation_list, suite):
5
+ # print(f"###inside create_expectation_function, expectation_list:{expectation_list}")
6
+ for expectation in expectation_list:
7
+ expectation = expectation["assertion_info"]
8
+
9
+ expectation = ExpectationConfiguration(
10
+ expectation_type=list(expectation.keys())[0],
11
+ kwargs=list(expectation.values())[0],
12
+ )
13
+ # while adding, GE will overwrite the assertion arguments, if the assertion already exists .
14
+
15
+ suite.add_expectation(expectation_configuration=expectation)
16
+
17
+ return suite
@@ -0,0 +1,20 @@
1
+ def get_mapping_id(actions_result: dict, expectations_list: list):
2
+ """Match a GE validation result back to its assertion_mapping_id."""
3
+ expectation_type_action = actions_result["expectation_config"]["expectation_type"]
4
+ expectation_type_kwargs = dict(actions_result["expectation_config"]["kwargs"])
5
+ expectation_type_kwargs.pop("batch_id", None)
6
+ expectation_type_kwargs.pop("catch_exceptions", None)
7
+
8
+ for expectation in expectations_list:
9
+ expectation_info = expectation["assertion_info"]
10
+ expectation_type_key = list(expectation_info.keys())[0]
11
+ expectations_type_value = dict(list(expectation_info.values())[0])
12
+ expectations_type_value.pop("catch_exceptions", None)
13
+
14
+ if (
15
+ expectation_type_key == expectation_type_action
16
+ and expectations_type_value == expectation_type_kwargs
17
+ ):
18
+ return expectation["assertion_mapping_id"]
19
+
20
+ return None
@@ -0,0 +1,50 @@
1
+ import base64
2
+ import os
3
+ import shutil
4
+ import urllib.parse
5
+
6
+
7
+ def convert_quality_report_to_binary(quality_report_lctn):
8
+ quality_report_lctn = quality_report_lctn.split("file:")[1]
9
+
10
+ with open(rf"{urllib.parse.unquote(quality_report_lctn)}", "rb") as f:
11
+ file_content = f.read()
12
+
13
+ # Encode the file content as base64
14
+ html_binary = base64.b64encode(file_content)
15
+
16
+ return html_binary
17
+
18
+
19
+ def delete_quality_files(table_id: int, suite_id: int, quality_path: str):
20
+ # to delete the folder and its contents
21
+ folder_paths = [
22
+ os.path.join(
23
+ quality_path,
24
+ "expectations",
25
+ f"{table_id}_{suite_id}",
26
+ ),
27
+ os.path.join(
28
+ quality_path,
29
+ "uncommitted",
30
+ "validations",
31
+ f"{table_id}_{suite_id}",
32
+ ),
33
+ os.path.join(
34
+ quality_path,
35
+ "checkpoints",
36
+ f"{table_id}_{suite_id}",
37
+ ),
38
+ os.path.join(
39
+ quality_path,
40
+ "uncommitted",
41
+ "data_docs",
42
+ "local_site",
43
+ f"{table_id}_{suite_id}",
44
+ ),
45
+ ]
46
+
47
+ for folder_path in folder_paths:
48
+ if os.path.exists(folder_path):
49
+ shutil.rmtree(folder_path)
50
+ print(f"Folder '{folder_path}' and its contents have been deleted.")