@zimezone/z-command 1.1.0 → 1.1.1

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 (182) hide show
  1. package/package.json +4 -1
  2. package/templates/agents/api-documenter.agent.md +161 -0
  3. package/templates/agents/architect-review.agent.md +146 -0
  4. package/templates/agents/arm-cortex-expert.agent.md +288 -0
  5. package/templates/agents/backend-architect.agent.md +309 -0
  6. package/templates/agents/backend-security-coder.agent.md +152 -0
  7. package/templates/agents/bash-pro.agent.md +285 -0
  8. package/templates/agents/c-pro.agent.md +35 -0
  9. package/templates/agents/c4-code.agent.md +320 -0
  10. package/templates/agents/c4-component.agent.md +227 -0
  11. package/templates/agents/c4-container.agent.md +248 -0
  12. package/templates/agents/c4-context.agent.md +235 -0
  13. package/templates/agents/conductor-validator.agent.md +245 -0
  14. package/templates/agents/csharp-pro.agent.md +38 -0
  15. package/templates/agents/customer-support.agent.md +148 -0
  16. package/templates/agents/database-admin.agent.md +142 -0
  17. package/templates/agents/database-architect.agent.md +238 -0
  18. package/templates/agents/database-optimizer.agent.md +144 -0
  19. package/templates/agents/debugger.agent.md +30 -0
  20. package/templates/agents/deployment-engineer.agent.md +0 -0
  21. package/templates/agents/devops-troubleshooter.agent.md +138 -0
  22. package/templates/agents/django-pro.agent.md +159 -0
  23. package/templates/agents/docs-architect.agent.md +77 -0
  24. package/templates/agents/dotnet-architect.agent.md +175 -0
  25. package/templates/agents/dx-optimizer.agent.md +63 -0
  26. package/templates/agents/elixir-pro.agent.md +38 -0
  27. package/templates/agents/error-detective.agent.md +32 -0
  28. package/templates/agents/event-sourcing-architect.agent.md +42 -0
  29. package/templates/agents/fastapi-pro.agent.md +171 -0
  30. package/templates/agents/firmware-analyst.agent.md +330 -0
  31. package/templates/agents/frontend-security-coder.agent.md +149 -0
  32. package/templates/agents/haskell-pro.agent.md +37 -0
  33. package/templates/agents/hr-pro.agent.md +105 -0
  34. package/templates/agents/incident-responder.agent.md +190 -0
  35. package/templates/agents/ios-developer.agent.md +198 -0
  36. package/templates/agents/java-pro.agent.md +156 -0
  37. package/templates/agents/javascript-pro.agent.md +35 -0
  38. package/templates/agents/julia-pro.agent.md +187 -0
  39. package/templates/agents/legal-advisor.agent.md +49 -0
  40. package/templates/agents/malware-analyst.agent.md +272 -0
  41. package/templates/agents/mermaid-expert.agent.md +39 -0
  42. package/templates/agents/minecraft-bukkit-pro.agent.md +104 -0
  43. package/templates/agents/mobile-security-coder.agent.md +163 -0
  44. package/templates/agents/monorepo-architect.agent.md +44 -0
  45. package/templates/agents/observability-engineer.agent.md +228 -0
  46. package/templates/agents/performance-engineer.agent.md +167 -0
  47. package/templates/agents/php-pro.agent.md +43 -0
  48. package/templates/agents/posix-shell-pro.agent.md +284 -0
  49. package/templates/agents/quant-analyst.agent.md +32 -0
  50. package/templates/agents/reference-builder.agent.md +167 -0
  51. package/templates/agents/reverse-engineer.agent.md +202 -0
  52. package/templates/agents/risk-manager.agent.md +41 -0
  53. package/templates/agents/ruby-pro.agent.md +35 -0
  54. package/templates/agents/rust-pro.agent.md +156 -0
  55. package/templates/agents/sales-automator.agent.md +35 -0
  56. package/templates/agents/scala-pro.agent.md +60 -0
  57. package/templates/agents/search-specialist.agent.md +59 -0
  58. package/templates/agents/security-auditor.agent.md +138 -0
  59. package/templates/agents/seo-authority-builder.agent.md +116 -0
  60. package/templates/agents/seo-cannibalization-detector.agent.md +103 -0
  61. package/templates/agents/seo-content-auditor.agent.md +63 -0
  62. package/templates/agents/seo-content-planner.agent.md +88 -0
  63. package/templates/agents/seo-content-refresher.agent.md +98 -0
  64. package/templates/agents/seo-content-writer.agent.md +76 -0
  65. package/templates/agents/seo-keyword-strategist.agent.md +75 -0
  66. package/templates/agents/seo-meta-optimizer.agent.md +72 -0
  67. package/templates/agents/seo-snippet-hunter.agent.md +94 -0
  68. package/templates/agents/seo-structure-architect.agent.md +88 -0
  69. package/templates/agents/service-mesh-expert.agent.md +41 -0
  70. package/templates/agents/sql-pro.agent.md +146 -0
  71. package/templates/agents/tdd-orchestrator.agent.md +183 -0
  72. package/templates/agents/temporal-python-pro.agent.md +349 -0
  73. package/templates/agents/terraform-specialist.agent.md +137 -0
  74. package/templates/agents/test-automator.agent.md +203 -0
  75. package/templates/agents/threat-modeling-expert.agent.md +44 -0
  76. package/templates/agents/tutorial-engineer.agent.md +118 -0
  77. package/templates/agents/ui-ux-designer.agent.md +188 -0
  78. package/templates/agents/ui-visual-validator.agent.md +192 -0
  79. package/templates/agents/vector-database-engineer.agent.md +43 -0
  80. package/templates/skills/angular-migration/SKILL.md +410 -0
  81. package/templates/skills/api-design-principles/SKILL.md +528 -0
  82. package/templates/skills/api-design-principles/assets/api-design-checklist.md +155 -0
  83. package/templates/skills/api-design-principles/assets/rest-api-template.py +182 -0
  84. package/templates/skills/api-design-principles/references/graphql-schema-design.md +583 -0
  85. package/templates/skills/api-design-principles/references/rest-best-practices.md +408 -0
  86. package/templates/skills/architecture-decision-records/SKILL.md +428 -0
  87. package/templates/skills/architecture-patterns/SKILL.md +494 -0
  88. package/templates/skills/async-python-patterns/SKILL.md +694 -0
  89. package/templates/skills/auth-implementation-patterns/SKILL.md +634 -0
  90. package/templates/skills/changelog-automation/SKILL.md +552 -0
  91. package/templates/skills/code-review-excellence/SKILL.md +520 -0
  92. package/templates/skills/competitive-landscape/SKILL.md +479 -0
  93. package/templates/skills/context-driven-development/SKILL.md +385 -0
  94. package/templates/skills/cost-optimization/SKILL.md +274 -0
  95. package/templates/skills/cqrs-implementation/SKILL.md +554 -0
  96. package/templates/skills/data-quality-frameworks/SKILL.md +587 -0
  97. package/templates/skills/data-storytelling/SKILL.md +453 -0
  98. package/templates/skills/database-migration/SKILL.md +424 -0
  99. package/templates/skills/dbt-transformation-patterns/SKILL.md +561 -0
  100. package/templates/skills/debugging-strategies/SKILL.md +527 -0
  101. package/templates/skills/defi-protocol-templates/SKILL.md +454 -0
  102. package/templates/skills/dependency-upgrade/SKILL.md +409 -0
  103. package/templates/skills/deployment-pipeline-design/SKILL.md +359 -0
  104. package/templates/skills/distributed-tracing/SKILL.md +438 -0
  105. package/templates/skills/dotnet-backend-patterns/SKILL.md +815 -0
  106. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
  107. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
  108. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
  109. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
  110. package/templates/skills/e2e-testing-patterns/SKILL.md +547 -0
  111. package/templates/skills/employment-contract-templates/SKILL.md +507 -0
  112. package/templates/skills/error-handling-patterns/SKILL.md +636 -0
  113. package/templates/skills/event-store-design/SKILL.md +437 -0
  114. package/templates/skills/fastapi-templates/SKILL.md +567 -0
  115. package/templates/skills/git-advanced-workflows/SKILL.md +400 -0
  116. package/templates/skills/github-actions-templates/SKILL.md +333 -0
  117. package/templates/skills/go-concurrency-patterns/SKILL.md +655 -0
  118. package/templates/skills/grafana-dashboards/SKILL.md +369 -0
  119. package/templates/skills/helm-chart-scaffolding/SKILL.md +544 -0
  120. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
  121. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
  122. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
  123. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
  124. package/templates/skills/javascript-testing-patterns/SKILL.md +1025 -0
  125. package/templates/skills/langchain-architecture/SKILL.md +338 -0
  126. package/templates/skills/llm-evaluation/SKILL.md +471 -0
  127. package/templates/skills/microservices-patterns/SKILL.md +595 -0
  128. package/templates/skills/modern-javascript-patterns/SKILL.md +911 -0
  129. package/templates/skills/monorepo-management/SKILL.md +622 -0
  130. package/templates/skills/nextjs-app-router-patterns/SKILL.md +544 -0
  131. package/templates/skills/nodejs-backend-patterns/SKILL.md +1020 -0
  132. package/templates/skills/nx-workspace-patterns/SKILL.md +452 -0
  133. package/templates/skills/openapi-spec-generation/SKILL.md +1028 -0
  134. package/templates/skills/paypal-integration/SKILL.md +467 -0
  135. package/templates/skills/pci-compliance/SKILL.md +466 -0
  136. package/templates/skills/postgresql/SKILL.md +204 -0
  137. package/templates/skills/projection-patterns/SKILL.md +490 -0
  138. package/templates/skills/prometheus-configuration/SKILL.md +392 -0
  139. package/templates/skills/prompt-engineering-patterns/SKILL.md +201 -0
  140. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
  141. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
  142. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
  143. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
  144. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
  145. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
  146. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
  147. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
  148. package/templates/skills/python-packaging/SKILL.md +870 -0
  149. package/templates/skills/python-performance-optimization/SKILL.md +869 -0
  150. package/templates/skills/python-testing-patterns/SKILL.md +907 -0
  151. package/templates/skills/rag-implementation/SKILL.md +403 -0
  152. package/templates/skills/react-modernization/SKILL.md +513 -0
  153. package/templates/skills/react-native-architecture/SKILL.md +671 -0
  154. package/templates/skills/react-state-management/SKILL.md +429 -0
  155. package/templates/skills/risk-metrics-calculation/SKILL.md +555 -0
  156. package/templates/skills/rust-async-patterns/SKILL.md +517 -0
  157. package/templates/skills/secrets-management/SKILL.md +346 -0
  158. package/templates/skills/security-requirement-extraction/SKILL.md +677 -0
  159. package/templates/skills/shellcheck-configuration/SKILL.md +454 -0
  160. package/templates/skills/similarity-search-patterns/SKILL.md +558 -0
  161. package/templates/skills/slo-implementation/SKILL.md +329 -0
  162. package/templates/skills/sql-optimization-patterns/SKILL.md +493 -0
  163. package/templates/skills/stripe-integration/SKILL.md +442 -0
  164. package/templates/skills/tailwind-design-system/SKILL.md +666 -0
  165. package/templates/skills/temporal-python-testing/SKILL.md +158 -0
  166. package/templates/skills/temporal-python-testing/resources/integration-testing.md +455 -0
  167. package/templates/skills/temporal-python-testing/resources/local-setup.md +553 -0
  168. package/templates/skills/temporal-python-testing/resources/replay-testing.md +462 -0
  169. package/templates/skills/temporal-python-testing/resources/unit-testing.md +328 -0
  170. package/templates/skills/terraform-module-library/SKILL.md +249 -0
  171. package/templates/skills/terraform-module-library/references/aws-modules.md +63 -0
  172. package/templates/skills/threat-mitigation-mapping/SKILL.md +745 -0
  173. package/templates/skills/track-management/SKILL.md +593 -0
  174. package/templates/skills/typescript-advanced-types/SKILL.md +717 -0
  175. package/templates/skills/uv-package-manager/SKILL.md +831 -0
  176. package/templates/skills/vector-index-tuning/SKILL.md +521 -0
  177. package/templates/skills/wcag-audit-patterns/SKILL.md +555 -0
  178. package/templates/skills/workflow-orchestration-patterns/SKILL.md +316 -0
  179. package/templates/skills/workflow-patterns/SKILL.md +623 -0
  180. package/templates/agents/game-developer.agent.md +0 -57
  181. package/templates/agents/kubernetes-specialist.agent.md +0 -56
  182. package/templates/agents/market-researcher.agent.md +0 -47
@@ -0,0 +1,587 @@
1
+ ---
2
+ name: data-quality-frameworks
3
+ description: Implement data quality validation with Great Expectations, dbt tests, and data contracts. Use when building data quality pipelines, implementing validation rules, or establishing data contracts.
4
+ ---
5
+
6
+ # Data Quality Frameworks
7
+
8
+ Production patterns for implementing data quality with Great Expectations, dbt tests, and data contracts to ensure reliable data pipelines.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Implementing data quality checks in pipelines
13
+ - Setting up Great Expectations validation
14
+ - Building comprehensive dbt test suites
15
+ - Establishing data contracts between teams
16
+ - Monitoring data quality metrics
17
+ - Automating data validation in CI/CD
18
+
19
+ ## Core Concepts
20
+
21
+ ### 1. Data Quality Dimensions
22
+
23
+ | Dimension | Description | Example Check |
24
+ |-----------|-------------|---------------|
25
+ | **Completeness** | No missing values | `expect_column_values_to_not_be_null` |
26
+ | **Uniqueness** | No duplicates | `expect_column_values_to_be_unique` |
27
+ | **Validity** | Values in expected range | `expect_column_values_to_be_in_set` |
28
+ | **Accuracy** | Data matches reality | Cross-reference validation |
29
+ | **Consistency** | No contradictions | `expect_column_pair_values_A_to_be_greater_than_B` |
30
+ | **Timeliness** | Data is recent | `expect_column_max_to_be_between` |
31
+
32
+ ### 2. Testing Pyramid for Data
33
+
34
+ ```
35
+ /\
36
+ / \ Integration Tests (cross-table)
37
+ /────\
38
+ / \ Unit Tests (single column)
39
+ /────────\
40
+ / \ Schema Tests (structure)
41
+ /────────────\
42
+ ```
43
+
44
+ ## Quick Start
45
+
46
+ ### Great Expectations Setup
47
+
48
+ ```bash
49
+ # Install
50
+ pip install great_expectations
51
+
52
+ # Initialize project
53
+ great_expectations init
54
+
55
+ # Create datasource
56
+ great_expectations datasource new
57
+ ```
58
+
59
+ ```python
60
+ # great_expectations/checkpoints/daily_validation.yml
61
+ import great_expectations as gx
62
+
63
+ # Create context
64
+ context = gx.get_context()
65
+
66
+ # Create expectation suite
67
+ suite = context.add_expectation_suite("orders_suite")
68
+
69
+ # Add expectations
70
+ suite.add_expectation(
71
+ gx.expectations.ExpectColumnValuesToNotBeNull(column="order_id")
72
+ )
73
+ suite.add_expectation(
74
+ gx.expectations.ExpectColumnValuesToBeUnique(column="order_id")
75
+ )
76
+
77
+ # Validate
78
+ results = context.run_checkpoint(checkpoint_name="daily_orders")
79
+ ```
80
+
81
+ ## Patterns
82
+
83
+ ### Pattern 1: Great Expectations Suite
84
+
85
+ ```python
86
+ # expectations/orders_suite.py
87
+ import great_expectations as gx
88
+ from great_expectations.core import ExpectationSuite
89
+ from great_expectations.core.expectation_configuration import ExpectationConfiguration
90
+
91
+ def build_orders_suite() -> ExpectationSuite:
92
+ """Build comprehensive orders expectation suite"""
93
+
94
+ suite = ExpectationSuite(expectation_suite_name="orders_suite")
95
+
96
+ # Schema expectations
97
+ suite.add_expectation(ExpectationConfiguration(
98
+ expectation_type="expect_table_columns_to_match_set",
99
+ kwargs={
100
+ "column_set": ["order_id", "customer_id", "amount", "status", "created_at"],
101
+ "exact_match": False # Allow additional columns
102
+ }
103
+ ))
104
+
105
+ # Primary key
106
+ suite.add_expectation(ExpectationConfiguration(
107
+ expectation_type="expect_column_values_to_not_be_null",
108
+ kwargs={"column": "order_id"}
109
+ ))
110
+ suite.add_expectation(ExpectationConfiguration(
111
+ expectation_type="expect_column_values_to_be_unique",
112
+ kwargs={"column": "order_id"}
113
+ ))
114
+
115
+ # Foreign key
116
+ suite.add_expectation(ExpectationConfiguration(
117
+ expectation_type="expect_column_values_to_not_be_null",
118
+ kwargs={"column": "customer_id"}
119
+ ))
120
+
121
+ # Categorical values
122
+ suite.add_expectation(ExpectationConfiguration(
123
+ expectation_type="expect_column_values_to_be_in_set",
124
+ kwargs={
125
+ "column": "status",
126
+ "value_set": ["pending", "processing", "shipped", "delivered", "cancelled"]
127
+ }
128
+ ))
129
+
130
+ # Numeric ranges
131
+ suite.add_expectation(ExpectationConfiguration(
132
+ expectation_type="expect_column_values_to_be_between",
133
+ kwargs={
134
+ "column": "amount",
135
+ "min_value": 0,
136
+ "max_value": 100000,
137
+ "strict_min": True # amount > 0
138
+ }
139
+ ))
140
+
141
+ # Date validity
142
+ suite.add_expectation(ExpectationConfiguration(
143
+ expectation_type="expect_column_values_to_be_dateutil_parseable",
144
+ kwargs={"column": "created_at"}
145
+ ))
146
+
147
+ # Freshness - data should be recent
148
+ suite.add_expectation(ExpectationConfiguration(
149
+ expectation_type="expect_column_max_to_be_between",
150
+ kwargs={
151
+ "column": "created_at",
152
+ "min_value": {"$PARAMETER": "now - timedelta(days=1)"},
153
+ "max_value": {"$PARAMETER": "now"}
154
+ }
155
+ ))
156
+
157
+ # Row count sanity
158
+ suite.add_expectation(ExpectationConfiguration(
159
+ expectation_type="expect_table_row_count_to_be_between",
160
+ kwargs={
161
+ "min_value": 1000, # Expect at least 1000 rows
162
+ "max_value": 10000000
163
+ }
164
+ ))
165
+
166
+ # Statistical expectations
167
+ suite.add_expectation(ExpectationConfiguration(
168
+ expectation_type="expect_column_mean_to_be_between",
169
+ kwargs={
170
+ "column": "amount",
171
+ "min_value": 50,
172
+ "max_value": 500
173
+ }
174
+ ))
175
+
176
+ return suite
177
+ ```
178
+
179
+ ### Pattern 2: Great Expectations Checkpoint
180
+
181
+ ```yaml
182
+ # great_expectations/checkpoints/orders_checkpoint.yml
183
+ name: orders_checkpoint
184
+ config_version: 1.0
185
+ class_name: Checkpoint
186
+ run_name_template: "%Y%m%d-%H%M%S-orders-validation"
187
+
188
+ validations:
189
+ - batch_request:
190
+ datasource_name: warehouse
191
+ data_connector_name: default_inferred_data_connector_name
192
+ data_asset_name: orders
193
+ data_connector_query:
194
+ index: -1 # Latest batch
195
+ expectation_suite_name: orders_suite
196
+
197
+ action_list:
198
+ - name: store_validation_result
199
+ action:
200
+ class_name: StoreValidationResultAction
201
+
202
+ - name: store_evaluation_parameters
203
+ action:
204
+ class_name: StoreEvaluationParametersAction
205
+
206
+ - name: update_data_docs
207
+ action:
208
+ class_name: UpdateDataDocsAction
209
+
210
+ # Slack notification on failure
211
+ - name: send_slack_notification
212
+ action:
213
+ class_name: SlackNotificationAction
214
+ slack_webhook: ${SLACK_WEBHOOK}
215
+ notify_on: failure
216
+ renderer:
217
+ module_name: great_expectations.render.renderer.slack_renderer
218
+ class_name: SlackRenderer
219
+ ```
220
+
221
+ ```python
222
+ # Run checkpoint
223
+ import great_expectations as gx
224
+
225
+ context = gx.get_context()
226
+ result = context.run_checkpoint(checkpoint_name="orders_checkpoint")
227
+
228
+ if not result.success:
229
+ failed_expectations = [
230
+ r for r in result.run_results.values()
231
+ if not r.success
232
+ ]
233
+ raise ValueError(f"Data quality check failed: {failed_expectations}")
234
+ ```
235
+
236
+ ### Pattern 3: dbt Data Tests
237
+
238
+ ```yaml
239
+ # models/marts/core/_core__models.yml
240
+ version: 2
241
+
242
+ models:
243
+ - name: fct_orders
244
+ description: Order fact table
245
+ tests:
246
+ # Table-level tests
247
+ - dbt_utils.recency:
248
+ datepart: day
249
+ field: created_at
250
+ interval: 1
251
+ - dbt_utils.at_least_one
252
+ - dbt_utils.expression_is_true:
253
+ expression: "total_amount >= 0"
254
+
255
+ columns:
256
+ - name: order_id
257
+ description: Primary key
258
+ tests:
259
+ - unique
260
+ - not_null
261
+
262
+ - name: customer_id
263
+ description: Foreign key to dim_customers
264
+ tests:
265
+ - not_null
266
+ - relationships:
267
+ to: ref('dim_customers')
268
+ field: customer_id
269
+
270
+ - name: order_status
271
+ tests:
272
+ - accepted_values:
273
+ values: ['pending', 'processing', 'shipped', 'delivered', 'cancelled']
274
+
275
+ - name: total_amount
276
+ tests:
277
+ - not_null
278
+ - dbt_utils.expression_is_true:
279
+ expression: ">= 0"
280
+
281
+ - name: created_at
282
+ tests:
283
+ - not_null
284
+ - dbt_utils.expression_is_true:
285
+ expression: "<= current_timestamp"
286
+
287
+ - name: dim_customers
288
+ columns:
289
+ - name: customer_id
290
+ tests:
291
+ - unique
292
+ - not_null
293
+
294
+ - name: email
295
+ tests:
296
+ - unique
297
+ - not_null
298
+ # Custom regex test
299
+ - dbt_utils.expression_is_true:
300
+ expression: "email ~ '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$'"
301
+ ```
302
+
303
+ ### Pattern 4: Custom dbt Tests
304
+
305
+ ```sql
306
+ -- tests/generic/test_row_count_in_range.sql
307
+ {% test row_count_in_range(model, min_count, max_count) %}
308
+
309
+ with row_count as (
310
+ select count(*) as cnt from {{ model }}
311
+ )
312
+
313
+ select cnt
314
+ from row_count
315
+ where cnt < {{ min_count }} or cnt > {{ max_count }}
316
+
317
+ {% endtest %}
318
+
319
+ -- Usage in schema.yml:
320
+ -- tests:
321
+ -- - row_count_in_range:
322
+ -- min_count: 1000
323
+ -- max_count: 10000000
324
+ ```
325
+
326
+ ```sql
327
+ -- tests/generic/test_sequential_values.sql
328
+ {% test sequential_values(model, column_name, interval=1) %}
329
+
330
+ with lagged as (
331
+ select
332
+ {{ column_name }},
333
+ lag({{ column_name }}) over (order by {{ column_name }}) as prev_value
334
+ from {{ model }}
335
+ )
336
+
337
+ select *
338
+ from lagged
339
+ where {{ column_name }} - prev_value != {{ interval }}
340
+ and prev_value is not null
341
+
342
+ {% endtest %}
343
+ ```
344
+
345
+ ```sql
346
+ -- tests/singular/assert_orders_customers_match.sql
347
+ -- Singular test: specific business rule
348
+
349
+ with orders_customers as (
350
+ select distinct customer_id from {{ ref('fct_orders') }}
351
+ ),
352
+
353
+ dim_customers as (
354
+ select customer_id from {{ ref('dim_customers') }}
355
+ ),
356
+
357
+ orphaned_orders as (
358
+ select o.customer_id
359
+ from orders_customers o
360
+ left join dim_customers c using (customer_id)
361
+ where c.customer_id is null
362
+ )
363
+
364
+ select * from orphaned_orders
365
+ -- Test passes if this returns 0 rows
366
+ ```
367
+
368
+ ### Pattern 5: Data Contracts
369
+
370
+ ```yaml
371
+ # contracts/orders_contract.yaml
372
+ apiVersion: datacontract.com/v1.0.0
373
+ kind: DataContract
374
+ metadata:
375
+ name: orders
376
+ version: 1.0.0
377
+ owner: data-platform-team
378
+ contact: data-team@company.com
379
+
380
+ info:
381
+ title: Orders Data Contract
382
+ description: Contract for order event data from the ecommerce platform
383
+ purpose: Analytics, reporting, and ML features
384
+
385
+ servers:
386
+ production:
387
+ type: snowflake
388
+ account: company.us-east-1
389
+ database: ANALYTICS
390
+ schema: CORE
391
+
392
+ terms:
393
+ usage: Internal analytics only
394
+ limitations: PII must not be exposed in downstream marts
395
+ billing: Charged per query TB scanned
396
+
397
+ schema:
398
+ type: object
399
+ properties:
400
+ order_id:
401
+ type: string
402
+ format: uuid
403
+ description: Unique order identifier
404
+ required: true
405
+ unique: true
406
+ pii: false
407
+
408
+ customer_id:
409
+ type: string
410
+ format: uuid
411
+ description: Customer identifier
412
+ required: true
413
+ pii: true
414
+ piiClassification: indirect
415
+
416
+ total_amount:
417
+ type: number
418
+ minimum: 0
419
+ maximum: 100000
420
+ description: Order total in USD
421
+
422
+ created_at:
423
+ type: string
424
+ format: date-time
425
+ description: Order creation timestamp
426
+ required: true
427
+
428
+ status:
429
+ type: string
430
+ enum: [pending, processing, shipped, delivered, cancelled]
431
+ description: Current order status
432
+
433
+ quality:
434
+ type: SodaCL
435
+ specification:
436
+ checks for orders:
437
+ - row_count > 0
438
+ - missing_count(order_id) = 0
439
+ - duplicate_count(order_id) = 0
440
+ - invalid_count(status) = 0:
441
+ valid values: [pending, processing, shipped, delivered, cancelled]
442
+ - freshness(created_at) < 24h
443
+
444
+ sla:
445
+ availability: 99.9%
446
+ freshness: 1 hour
447
+ latency: 5 minutes
448
+ ```
449
+
450
+ ### Pattern 6: Automated Quality Pipeline
451
+
452
+ ```python
453
+ # quality_pipeline.py
454
+ from dataclasses import dataclass
455
+ from typing import List, Dict, Any
456
+ import great_expectations as gx
457
+ from datetime import datetime
458
+
459
+ @dataclass
460
+ class QualityResult:
461
+ table: str
462
+ passed: bool
463
+ total_expectations: int
464
+ failed_expectations: int
465
+ details: List[Dict[str, Any]]
466
+ timestamp: datetime
467
+
468
+ class DataQualityPipeline:
469
+ """Orchestrate data quality checks across tables"""
470
+
471
+ def __init__(self, context: gx.DataContext):
472
+ self.context = context
473
+ self.results: List[QualityResult] = []
474
+
475
+ def validate_table(self, table: str, suite: str) -> QualityResult:
476
+ """Validate a single table against expectation suite"""
477
+
478
+ checkpoint_config = {
479
+ "name": f"{table}_validation",
480
+ "config_version": 1.0,
481
+ "class_name": "Checkpoint",
482
+ "validations": [{
483
+ "batch_request": {
484
+ "datasource_name": "warehouse",
485
+ "data_asset_name": table,
486
+ },
487
+ "expectation_suite_name": suite,
488
+ }],
489
+ }
490
+
491
+ result = self.context.run_checkpoint(**checkpoint_config)
492
+
493
+ # Parse results
494
+ validation_result = list(result.run_results.values())[0]
495
+ results = validation_result.results
496
+
497
+ failed = [r for r in results if not r.success]
498
+
499
+ return QualityResult(
500
+ table=table,
501
+ passed=result.success,
502
+ total_expectations=len(results),
503
+ failed_expectations=len(failed),
504
+ details=[{
505
+ "expectation": r.expectation_config.expectation_type,
506
+ "success": r.success,
507
+ "observed_value": r.result.get("observed_value"),
508
+ } for r in results],
509
+ timestamp=datetime.now()
510
+ )
511
+
512
+ def run_all(self, tables: Dict[str, str]) -> Dict[str, QualityResult]:
513
+ """Run validation for all tables"""
514
+ results = {}
515
+
516
+ for table, suite in tables.items():
517
+ print(f"Validating {table}...")
518
+ results[table] = self.validate_table(table, suite)
519
+
520
+ return results
521
+
522
+ def generate_report(self, results: Dict[str, QualityResult]) -> str:
523
+ """Generate quality report"""
524
+ report = ["# Data Quality Report", f"Generated: {datetime.now()}", ""]
525
+
526
+ total_passed = sum(1 for r in results.values() if r.passed)
527
+ total_tables = len(results)
528
+
529
+ report.append(f"## Summary: {total_passed}/{total_tables} tables passed")
530
+ report.append("")
531
+
532
+ for table, result in results.items():
533
+ status = "✅" if result.passed else "❌"
534
+ report.append(f"### {status} {table}")
535
+ report.append(f"- Expectations: {result.total_expectations}")
536
+ report.append(f"- Failed: {result.failed_expectations}")
537
+
538
+ if not result.passed:
539
+ report.append("- Failed checks:")
540
+ for detail in result.details:
541
+ if not detail["success"]:
542
+ report.append(f" - {detail['expectation']}: {detail['observed_value']}")
543
+ report.append("")
544
+
545
+ return "\n".join(report)
546
+
547
+ # Usage
548
+ context = gx.get_context()
549
+ pipeline = DataQualityPipeline(context)
550
+
551
+ tables_to_validate = {
552
+ "orders": "orders_suite",
553
+ "customers": "customers_suite",
554
+ "products": "products_suite",
555
+ }
556
+
557
+ results = pipeline.run_all(tables_to_validate)
558
+ report = pipeline.generate_report(results)
559
+
560
+ # Fail pipeline if any table failed
561
+ if not all(r.passed for r in results.values()):
562
+ print(report)
563
+ raise ValueError("Data quality checks failed!")
564
+ ```
565
+
566
+ ## Best Practices
567
+
568
+ ### Do's
569
+ - **Test early** - Validate source data before transformations
570
+ - **Test incrementally** - Add tests as you find issues
571
+ - **Document expectations** - Clear descriptions for each test
572
+ - **Alert on failures** - Integrate with monitoring
573
+ - **Version contracts** - Track schema changes
574
+
575
+ ### Don'ts
576
+ - **Don't test everything** - Focus on critical columns
577
+ - **Don't ignore warnings** - They often precede failures
578
+ - **Don't skip freshness** - Stale data is bad data
579
+ - **Don't hardcode thresholds** - Use dynamic baselines
580
+ - **Don't test in isolation** - Test relationships too
581
+
582
+ ## Resources
583
+
584
+ - [Great Expectations Documentation](https://docs.greatexpectations.io/)
585
+ - [dbt Testing Documentation](https://docs.getdbt.com/docs/build/tests)
586
+ - [Data Contract Specification](https://datacontract.com/)
587
+ - [Soda Core](https://docs.soda.io/soda-core/overview.html)