@cloudstreamsoftware/claude-tools 1.0.0 → 1.2.0
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.
- package/README.md +152 -37
- package/agents/INDEX.md +183 -0
- package/agents/architect.md +247 -0
- package/agents/build-error-resolver.md +555 -0
- package/agents/catalyst-deployer.md +132 -0
- package/agents/code-reviewer.md +121 -0
- package/agents/compliance-auditor.md +148 -0
- package/agents/creator-architect.md +395 -0
- package/agents/deluge-reviewer.md +98 -0
- package/agents/doc-updater.md +471 -0
- package/agents/e2e-runner.md +711 -0
- package/agents/planner.md +122 -0
- package/agents/refactor-cleaner.md +309 -0
- package/agents/security-reviewer.md +582 -0
- package/agents/tdd-guide.md +302 -0
- package/bin/cloudstream-setup.js +16 -6
- package/config/versions.json +63 -0
- package/dist/hooks/hooks.json +209 -0
- package/dist/index.js +47 -0
- package/dist/lib/asset-value.js +609 -0
- package/dist/lib/client-manager.js +300 -0
- package/dist/lib/command-matcher.js +242 -0
- package/dist/lib/cross-session-patterns.js +754 -0
- package/dist/lib/intent-classifier.js +1075 -0
- package/dist/lib/package-manager.js +374 -0
- package/dist/lib/recommendation-engine.js +597 -0
- package/dist/lib/session-memory.js +489 -0
- package/dist/lib/skill-effectiveness.js +486 -0
- package/dist/lib/skill-matcher.js +595 -0
- package/dist/lib/tutorial-metrics.js +242 -0
- package/dist/lib/tutorial-progress.js +209 -0
- package/dist/lib/tutorial-renderer.js +431 -0
- package/dist/lib/utils.js +380 -0
- package/dist/lib/verify-formatter.js +143 -0
- package/dist/lib/workflow-state.js +249 -0
- package/hooks/hooks.json +209 -0
- package/package.json +5 -1
- package/scripts/aggregate-sessions.js +290 -0
- package/scripts/branch-name-validator.js +291 -0
- package/scripts/build.js +101 -0
- package/scripts/commands/client-switch.js +231 -0
- package/scripts/deprecate-skill.js +610 -0
- package/scripts/diagnose.js +324 -0
- package/scripts/doc-freshness.js +168 -0
- package/scripts/generate-weekly-digest.js +393 -0
- package/scripts/health-check.js +270 -0
- package/scripts/hooks/credential-check.js +101 -0
- package/scripts/hooks/evaluate-session.js +81 -0
- package/scripts/hooks/pre-compact.js +66 -0
- package/scripts/hooks/prompt-analyzer.js +276 -0
- package/scripts/hooks/prompt-router.js +422 -0
- package/scripts/hooks/quality-gate-enforcer.js +371 -0
- package/scripts/hooks/session-end.js +156 -0
- package/scripts/hooks/session-start.js +195 -0
- package/scripts/hooks/skill-injector.js +333 -0
- package/scripts/hooks/suggest-compact.js +58 -0
- package/scripts/lib/asset-value.js +609 -0
- package/scripts/lib/client-manager.js +300 -0
- package/scripts/lib/command-matcher.js +242 -0
- package/scripts/lib/cross-session-patterns.js +754 -0
- package/scripts/lib/intent-classifier.js +1075 -0
- package/scripts/lib/package-manager.js +374 -0
- package/scripts/lib/recommendation-engine.js +597 -0
- package/scripts/lib/session-memory.js +489 -0
- package/scripts/lib/skill-effectiveness.js +486 -0
- package/scripts/lib/skill-matcher.js +595 -0
- package/scripts/lib/tutorial-metrics.js +242 -0
- package/scripts/lib/tutorial-progress.js +209 -0
- package/scripts/lib/tutorial-renderer.js +431 -0
- package/scripts/lib/utils.js +380 -0
- package/scripts/lib/verify-formatter.js +143 -0
- package/scripts/lib/workflow-state.js +249 -0
- package/scripts/onboard.js +363 -0
- package/scripts/quarterly-report.js +692 -0
- package/scripts/setup-package-manager.js +204 -0
- package/scripts/sync-upstream.js +391 -0
- package/scripts/test.js +108 -0
- package/scripts/tutorial-runner.js +351 -0
- package/scripts/validate-all.js +201 -0
- package/scripts/verifiers/agents.js +245 -0
- package/scripts/verifiers/config.js +186 -0
- package/scripts/verifiers/environment.js +123 -0
- package/scripts/verifiers/hooks.js +188 -0
- package/scripts/verifiers/index.js +38 -0
- package/scripts/verifiers/persistence.js +140 -0
- package/scripts/verifiers/plugin.js +215 -0
- package/scripts/verifiers/skills.js +209 -0
- package/scripts/verify-setup.js +164 -0
- package/skills/INDEX.md +157 -0
- package/skills/backend-patterns/SKILL.md +586 -0
- package/skills/backend-patterns/catalyst-patterns.md +128 -0
- package/skills/bigquery-patterns/SKILL.md +27 -0
- package/skills/bigquery-patterns/performance-optimization.md +518 -0
- package/skills/bigquery-patterns/query-patterns.md +372 -0
- package/skills/bigquery-patterns/schema-design.md +78 -0
- package/skills/cloudstream-project-template/SKILL.md +20 -0
- package/skills/cloudstream-project-template/structure.md +65 -0
- package/skills/coding-standards/SKILL.md +524 -0
- package/skills/coding-standards/deluge-standards.md +83 -0
- package/skills/compliance-patterns/SKILL.md +28 -0
- package/skills/compliance-patterns/hipaa/audit-requirements.md +251 -0
- package/skills/compliance-patterns/hipaa/baa-process.md +298 -0
- package/skills/compliance-patterns/hipaa/data-archival-strategy.md +387 -0
- package/skills/compliance-patterns/hipaa/phi-handling.md +52 -0
- package/skills/compliance-patterns/pci-dss/saq-a-requirements.md +307 -0
- package/skills/compliance-patterns/pci-dss/tokenization-patterns.md +382 -0
- package/skills/compliance-patterns/pci-dss/zoho-checkout-patterns.md +56 -0
- package/skills/compliance-patterns/soc2/access-controls.md +344 -0
- package/skills/compliance-patterns/soc2/audit-logging.md +458 -0
- package/skills/compliance-patterns/soc2/change-management.md +403 -0
- package/skills/compliance-patterns/soc2/deluge-execution-logging.md +407 -0
- package/skills/consultancy-workflows/SKILL.md +19 -0
- package/skills/consultancy-workflows/client-isolation.md +21 -0
- package/skills/consultancy-workflows/documentation-automation.md +454 -0
- package/skills/consultancy-workflows/handoff-procedures.md +257 -0
- package/skills/consultancy-workflows/knowledge-capture.md +513 -0
- package/skills/consultancy-workflows/time-tracking.md +26 -0
- package/skills/continuous-learning/SKILL.md +84 -0
- package/skills/continuous-learning/config.json +18 -0
- package/skills/continuous-learning/evaluate-session.sh +60 -0
- package/skills/continuous-learning-v2/SKILL.md +126 -0
- package/skills/continuous-learning-v2/config.json +61 -0
- package/skills/frontend-patterns/SKILL.md +635 -0
- package/skills/frontend-patterns/zoho-widget-patterns.md +103 -0
- package/skills/gcp-data-engineering/SKILL.md +36 -0
- package/skills/gcp-data-engineering/bigquery/performance-optimization.md +337 -0
- package/skills/gcp-data-engineering/dataflow/error-handling.md +496 -0
- package/skills/gcp-data-engineering/dataflow/pipeline-patterns.md +444 -0
- package/skills/gcp-data-engineering/dbt/model-organization.md +63 -0
- package/skills/gcp-data-engineering/dbt/testing-patterns.md +503 -0
- package/skills/gcp-data-engineering/medallion-architecture/bronze-layer.md +60 -0
- package/skills/gcp-data-engineering/medallion-architecture/gold-layer.md +311 -0
- package/skills/gcp-data-engineering/medallion-architecture/layer-transitions.md +517 -0
- package/skills/gcp-data-engineering/medallion-architecture/silver-layer.md +305 -0
- package/skills/gcp-data-engineering/zoho-to-gcp/data-extraction.md +543 -0
- package/skills/gcp-data-engineering/zoho-to-gcp/real-time-vs-batch.md +337 -0
- package/skills/security-review/SKILL.md +498 -0
- package/skills/security-review/compliance-checklist.md +53 -0
- package/skills/strategic-compact/SKILL.md +67 -0
- package/skills/tdd-workflow/SKILL.md +413 -0
- package/skills/tdd-workflow/zoho-testing.md +124 -0
- package/skills/tutorial/SKILL.md +249 -0
- package/skills/tutorial/docs/ACCESSIBILITY.md +169 -0
- package/skills/tutorial/lessons/00-philosophy-and-workflow.md +198 -0
- package/skills/tutorial/lessons/01-basics.md +81 -0
- package/skills/tutorial/lessons/02-training.md +86 -0
- package/skills/tutorial/lessons/03-commands.md +109 -0
- package/skills/tutorial/lessons/04-workflows.md +115 -0
- package/skills/tutorial/lessons/05-compliance.md +116 -0
- package/skills/tutorial/lessons/06-zoho.md +121 -0
- package/skills/tutorial/lessons/07-hooks-system.md +277 -0
- package/skills/tutorial/lessons/08-mcp-servers.md +316 -0
- package/skills/tutorial/lessons/09-client-management.md +215 -0
- package/skills/tutorial/lessons/10-testing-e2e.md +260 -0
- package/skills/tutorial/lessons/11-skills-deep-dive.md +272 -0
- package/skills/tutorial/lessons/12-rules-system.md +326 -0
- package/skills/tutorial/lessons/13-golden-standard-graduation.md +213 -0
- package/skills/tutorial/lessons/14-fork-setup-and-sync.md +312 -0
- package/skills/tutorial/lessons/15-living-examples-system.md +221 -0
- package/skills/tutorial/tracks/accelerated/README.md +134 -0
- package/skills/tutorial/tracks/accelerated/assessment/checkpoint-1.md +161 -0
- package/skills/tutorial/tracks/accelerated/assessment/checkpoint-2.md +175 -0
- package/skills/tutorial/tracks/accelerated/day-1-core-concepts.md +234 -0
- package/skills/tutorial/tracks/accelerated/day-2-essential-commands.md +270 -0
- package/skills/tutorial/tracks/accelerated/day-3-workflow-mastery.md +305 -0
- package/skills/tutorial/tracks/accelerated/day-4-compliance-zoho.md +304 -0
- package/skills/tutorial/tracks/accelerated/day-5-hooks-skills.md +344 -0
- package/skills/tutorial/tracks/accelerated/day-6-client-testing.md +386 -0
- package/skills/tutorial/tracks/accelerated/day-7-graduation.md +369 -0
- package/skills/zoho-patterns/CHANGELOG.md +108 -0
- package/skills/zoho-patterns/SKILL.md +446 -0
- package/skills/zoho-patterns/analytics/dashboard-patterns.md +352 -0
- package/skills/zoho-patterns/analytics/zoho-to-bigquery-pipeline.md +427 -0
- package/skills/zoho-patterns/catalyst/appsail-deployment.md +349 -0
- package/skills/zoho-patterns/catalyst/context-close-patterns.md +354 -0
- package/skills/zoho-patterns/catalyst/cron-batch-processing.md +374 -0
- package/skills/zoho-patterns/catalyst/function-patterns.md +439 -0
- package/skills/zoho-patterns/creator/form-design.md +304 -0
- package/skills/zoho-patterns/creator/publish-api-patterns.md +313 -0
- package/skills/zoho-patterns/creator/widget-integration.md +306 -0
- package/skills/zoho-patterns/creator/workflow-automation.md +253 -0
- package/skills/zoho-patterns/deluge/api-patterns.md +468 -0
- package/skills/zoho-patterns/deluge/batch-processing.md +403 -0
- package/skills/zoho-patterns/deluge/cross-app-integration.md +356 -0
- package/skills/zoho-patterns/deluge/error-handling.md +423 -0
- package/skills/zoho-patterns/deluge/syntax-reference.md +65 -0
- package/skills/zoho-patterns/integration/cors-proxy-architecture.md +426 -0
- package/skills/zoho-patterns/integration/crm-books-native-sync.md +277 -0
- package/skills/zoho-patterns/integration/oauth-token-management.md +461 -0
- package/skills/zoho-patterns/integration/zoho-flow-patterns.md +334 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# BigQuery Query Patterns
|
|
2
|
+
|
|
3
|
+
## Common Table Expressions (CTEs)
|
|
4
|
+
|
|
5
|
+
### Chaining Transformations
|
|
6
|
+
|
|
7
|
+
```sql
|
|
8
|
+
-- Multi-step transformation using CTEs
|
|
9
|
+
WITH raw_orders AS (
|
|
10
|
+
SELECT *
|
|
11
|
+
FROM `project.bronze.zoho_orders`
|
|
12
|
+
WHERE DATE(ingestion_timestamp) = CURRENT_DATE()
|
|
13
|
+
),
|
|
14
|
+
cleaned_orders AS (
|
|
15
|
+
SELECT
|
|
16
|
+
CAST(JSON_VALUE(raw_payload, '$.id') AS STRING) AS order_id,
|
|
17
|
+
CAST(JSON_VALUE(raw_payload, '$.customer_id') AS STRING) AS customer_id,
|
|
18
|
+
CAST(JSON_VALUE(raw_payload, '$.amount') AS NUMERIC) AS amount,
|
|
19
|
+
PARSE_TIMESTAMP('%Y-%m-%dT%H:%M:%S', JSON_VALUE(raw_payload, '$.created_time')) AS created_at,
|
|
20
|
+
JSON_VALUE(raw_payload, '$.status') AS status
|
|
21
|
+
FROM raw_orders
|
|
22
|
+
WHERE JSON_VALUE(raw_payload, '$.id') IS NOT NULL
|
|
23
|
+
),
|
|
24
|
+
enriched_orders AS (
|
|
25
|
+
SELECT
|
|
26
|
+
o.*,
|
|
27
|
+
c.company_name,
|
|
28
|
+
c.segment,
|
|
29
|
+
c.account_manager
|
|
30
|
+
FROM cleaned_orders o
|
|
31
|
+
LEFT JOIN `project.silver.customers` c ON o.customer_id = c.customer_id
|
|
32
|
+
)
|
|
33
|
+
SELECT * FROM enriched_orders
|
|
34
|
+
WHERE status = 'completed';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Window Functions
|
|
40
|
+
|
|
41
|
+
### ROW_NUMBER (Deduplication)
|
|
42
|
+
|
|
43
|
+
```sql
|
|
44
|
+
-- Remove duplicates keeping latest version
|
|
45
|
+
WITH ranked AS (
|
|
46
|
+
SELECT *,
|
|
47
|
+
ROW_NUMBER() OVER (
|
|
48
|
+
PARTITION BY record_id
|
|
49
|
+
ORDER BY ingestion_timestamp DESC
|
|
50
|
+
) AS rn
|
|
51
|
+
FROM `project.bronze.raw_records`
|
|
52
|
+
)
|
|
53
|
+
SELECT * EXCEPT(rn)
|
|
54
|
+
FROM ranked
|
|
55
|
+
WHERE rn = 1;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Running Totals and Moving Averages
|
|
59
|
+
|
|
60
|
+
```sql
|
|
61
|
+
SELECT
|
|
62
|
+
customer_id,
|
|
63
|
+
order_date,
|
|
64
|
+
order_total,
|
|
65
|
+
-- Running total
|
|
66
|
+
SUM(order_total) OVER (
|
|
67
|
+
PARTITION BY customer_id
|
|
68
|
+
ORDER BY order_date
|
|
69
|
+
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
|
|
70
|
+
) AS running_total,
|
|
71
|
+
-- 7-day moving average
|
|
72
|
+
AVG(order_total) OVER (
|
|
73
|
+
PARTITION BY customer_id
|
|
74
|
+
ORDER BY order_date
|
|
75
|
+
ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
|
|
76
|
+
) AS rolling_7day_avg,
|
|
77
|
+
-- Rank within customer
|
|
78
|
+
RANK() OVER (
|
|
79
|
+
PARTITION BY customer_id
|
|
80
|
+
ORDER BY order_total DESC
|
|
81
|
+
) AS order_rank
|
|
82
|
+
FROM `project.silver.orders`;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### LAG/LEAD (Period-over-Period)
|
|
86
|
+
|
|
87
|
+
```sql
|
|
88
|
+
-- Month-over-month revenue comparison
|
|
89
|
+
WITH monthly_revenue AS (
|
|
90
|
+
SELECT
|
|
91
|
+
DATE_TRUNC(order_date, MONTH) AS month,
|
|
92
|
+
SUM(amount) AS revenue
|
|
93
|
+
FROM `project.silver.orders`
|
|
94
|
+
WHERE order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 12 MONTH)
|
|
95
|
+
GROUP BY 1
|
|
96
|
+
)
|
|
97
|
+
SELECT
|
|
98
|
+
month,
|
|
99
|
+
revenue,
|
|
100
|
+
LAG(revenue, 1) OVER (ORDER BY month) AS prev_month_revenue,
|
|
101
|
+
LAG(revenue, 12) OVER (ORDER BY month) AS same_month_last_year,
|
|
102
|
+
ROUND((revenue - LAG(revenue, 1) OVER (ORDER BY month))
|
|
103
|
+
/ LAG(revenue, 1) OVER (ORDER BY month) * 100, 2) AS mom_growth_pct
|
|
104
|
+
FROM monthly_revenue
|
|
105
|
+
ORDER BY month DESC;
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### NTILE (Segmentation)
|
|
109
|
+
|
|
110
|
+
```sql
|
|
111
|
+
-- Customer value segmentation into quartiles
|
|
112
|
+
SELECT
|
|
113
|
+
customer_id,
|
|
114
|
+
total_revenue,
|
|
115
|
+
NTILE(4) OVER (ORDER BY total_revenue DESC) AS revenue_quartile,
|
|
116
|
+
CASE NTILE(4) OVER (ORDER BY total_revenue DESC)
|
|
117
|
+
WHEN 1 THEN 'Platinum'
|
|
118
|
+
WHEN 2 THEN 'Gold'
|
|
119
|
+
WHEN 3 THEN 'Silver'
|
|
120
|
+
WHEN 4 THEN 'Bronze'
|
|
121
|
+
END AS segment
|
|
122
|
+
FROM `project.gold.customer_lifetime_value`;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## UNNEST and Arrays
|
|
128
|
+
|
|
129
|
+
### Working with Repeated Fields
|
|
130
|
+
|
|
131
|
+
```sql
|
|
132
|
+
-- Explode array of tags into rows
|
|
133
|
+
SELECT
|
|
134
|
+
record_id,
|
|
135
|
+
tag
|
|
136
|
+
FROM `project.silver.deals`,
|
|
137
|
+
UNNEST(SPLIT(tags, ',')) AS tag;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Aggregating into Arrays
|
|
141
|
+
|
|
142
|
+
```sql
|
|
143
|
+
-- Collect unique products per customer
|
|
144
|
+
SELECT
|
|
145
|
+
customer_id,
|
|
146
|
+
ARRAY_AGG(DISTINCT product_name ORDER BY product_name) AS products_purchased,
|
|
147
|
+
ARRAY_LENGTH(ARRAY_AGG(DISTINCT product_name)) AS unique_products_count
|
|
148
|
+
FROM `project.silver.order_items`
|
|
149
|
+
GROUP BY customer_id;
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## STRUCT Handling
|
|
155
|
+
|
|
156
|
+
### Accessing Nested Fields
|
|
157
|
+
|
|
158
|
+
```sql
|
|
159
|
+
-- Access struct fields
|
|
160
|
+
SELECT
|
|
161
|
+
contact_id,
|
|
162
|
+
address.street,
|
|
163
|
+
address.city,
|
|
164
|
+
address.state,
|
|
165
|
+
address.zip,
|
|
166
|
+
_quality.is_valid_email,
|
|
167
|
+
_quality.quality_score
|
|
168
|
+
FROM `project.silver.contacts`
|
|
169
|
+
WHERE _quality.quality_score > 0.8;
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Creating Structs
|
|
173
|
+
|
|
174
|
+
```sql
|
|
175
|
+
-- Build quality metadata struct
|
|
176
|
+
SELECT
|
|
177
|
+
customer_id,
|
|
178
|
+
STRUCT(
|
|
179
|
+
email IS NOT NULL AND REGEXP_CONTAINS(email, r'^[^@]+@[^@]+\.[^@]+$') AS is_valid_email,
|
|
180
|
+
phone IS NOT NULL AS has_phone,
|
|
181
|
+
CASE
|
|
182
|
+
WHEN email IS NOT NULL AND phone IS NOT NULL THEN 1.0
|
|
183
|
+
WHEN email IS NOT NULL OR phone IS NOT NULL THEN 0.5
|
|
184
|
+
ELSE 0.0
|
|
185
|
+
END AS quality_score
|
|
186
|
+
) AS _quality
|
|
187
|
+
FROM `project.bronze.raw_contacts`;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Approximate Aggregations (Cost Optimization)
|
|
193
|
+
|
|
194
|
+
```sql
|
|
195
|
+
-- Use approximate functions for large datasets
|
|
196
|
+
SELECT
|
|
197
|
+
DATE(order_date) AS day,
|
|
198
|
+
APPROX_COUNT_DISTINCT(customer_id) AS approx_unique_customers,
|
|
199
|
+
APPROX_QUANTILES(order_total, 100)[OFFSET(50)] AS approx_median_order,
|
|
200
|
+
APPROX_QUANTILES(order_total, 100)[OFFSET(95)] AS approx_p95_order,
|
|
201
|
+
APPROX_TOP_COUNT(product_category, 5) AS top_5_categories
|
|
202
|
+
FROM `project.silver.orders`
|
|
203
|
+
WHERE order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
|
|
204
|
+
GROUP BY 1
|
|
205
|
+
ORDER BY 1 DESC;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Data Quality Checks (Silver Layer)
|
|
211
|
+
|
|
212
|
+
```sql
|
|
213
|
+
-- Comprehensive quality validation
|
|
214
|
+
WITH quality_results AS (
|
|
215
|
+
SELECT
|
|
216
|
+
'Null customer_id' AS check_name,
|
|
217
|
+
COUNTIF(customer_id IS NULL) AS failures,
|
|
218
|
+
COUNT(*) AS total
|
|
219
|
+
FROM `project.silver.orders`
|
|
220
|
+
UNION ALL
|
|
221
|
+
SELECT
|
|
222
|
+
'Negative amounts',
|
|
223
|
+
COUNTIF(amount < 0),
|
|
224
|
+
COUNT(*)
|
|
225
|
+
FROM `project.silver.orders`
|
|
226
|
+
UNION ALL
|
|
227
|
+
SELECT
|
|
228
|
+
'Future dates',
|
|
229
|
+
COUNTIF(order_date > CURRENT_DATE()),
|
|
230
|
+
COUNT(*)
|
|
231
|
+
FROM `project.silver.orders`
|
|
232
|
+
UNION ALL
|
|
233
|
+
SELECT
|
|
234
|
+
'Orphaned records',
|
|
235
|
+
COUNTIF(c.customer_id IS NULL),
|
|
236
|
+
COUNT(*)
|
|
237
|
+
FROM `project.silver.orders` o
|
|
238
|
+
LEFT JOIN `project.silver.customers` c ON o.customer_id = c.customer_id
|
|
239
|
+
)
|
|
240
|
+
SELECT
|
|
241
|
+
check_name,
|
|
242
|
+
failures,
|
|
243
|
+
total,
|
|
244
|
+
ROUND(failures / total * 100, 4) AS failure_rate_pct,
|
|
245
|
+
CASE
|
|
246
|
+
WHEN failures / total > 0.05 THEN 'FAIL'
|
|
247
|
+
WHEN failures / total > 0.01 THEN 'WARN'
|
|
248
|
+
ELSE 'PASS'
|
|
249
|
+
END AS status
|
|
250
|
+
FROM quality_results;
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Query Cost Estimation
|
|
256
|
+
|
|
257
|
+
```sql
|
|
258
|
+
-- Check bytes scanned BEFORE running expensive queries
|
|
259
|
+
-- Use dry_run = true in BigQuery API or:
|
|
260
|
+
SELECT
|
|
261
|
+
total_bytes_processed,
|
|
262
|
+
total_bytes_billed,
|
|
263
|
+
ROUND(total_bytes_billed / POW(1024, 4) * 5, 2) AS estimated_cost_usd
|
|
264
|
+
FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
|
|
265
|
+
WHERE creation_time > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR)
|
|
266
|
+
ORDER BY total_bytes_billed DESC
|
|
267
|
+
LIMIT 10;
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Cost-Saving Patterns
|
|
271
|
+
|
|
272
|
+
```sql
|
|
273
|
+
-- GOOD: Partition pruning (scans only matching partitions)
|
|
274
|
+
SELECT * FROM `project.silver.orders`
|
|
275
|
+
WHERE order_date BETWEEN '2025-01-01' AND '2025-01-31';
|
|
276
|
+
|
|
277
|
+
-- BAD: No partition filter (full table scan)
|
|
278
|
+
SELECT * FROM `project.silver.orders`
|
|
279
|
+
WHERE EXTRACT(MONTH FROM order_date) = 1;
|
|
280
|
+
|
|
281
|
+
-- GOOD: Select specific columns
|
|
282
|
+
SELECT customer_id, order_total, status
|
|
283
|
+
FROM `project.silver.orders`;
|
|
284
|
+
|
|
285
|
+
-- BAD: SELECT * (scans all columns)
|
|
286
|
+
SELECT * FROM `project.silver.orders`;
|
|
287
|
+
|
|
288
|
+
-- GOOD: Approximate distinct for dashboards
|
|
289
|
+
SELECT APPROX_COUNT_DISTINCT(customer_id) FROM `project.silver.orders`;
|
|
290
|
+
|
|
291
|
+
-- BAD: Exact distinct on massive tables
|
|
292
|
+
SELECT COUNT(DISTINCT customer_id) FROM `project.silver.orders`;
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Common Anti-Patterns
|
|
298
|
+
|
|
299
|
+
| Anti-Pattern | Problem | Fix |
|
|
300
|
+
|-------------|---------|-----|
|
|
301
|
+
| `SELECT *` | Scans all columns (cost) | List needed columns |
|
|
302
|
+
| No partition filter | Full table scan | Always filter partition column |
|
|
303
|
+
| `ORDER BY` without `LIMIT` | Sorts entire result set | Add `LIMIT` or remove sort |
|
|
304
|
+
| Correlated subquery | Executes per row (slow) | Use JOIN or window function |
|
|
305
|
+
| `COUNT(DISTINCT x)` on >100M rows | Expensive exact count | Use `APPROX_COUNT_DISTINCT` |
|
|
306
|
+
| Cross join without filter | Cartesian product explosion | Add join condition |
|
|
307
|
+
| Regex on unpartitioned data | Full scan + CPU intensive | Filter first, then regex |
|
|
308
|
+
| Repeated CTEs | Computed multiple times | Materialize to temp table |
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Medallion Layer Transitions
|
|
313
|
+
|
|
314
|
+
### Bronze → Silver
|
|
315
|
+
|
|
316
|
+
```sql
|
|
317
|
+
-- Incremental silver update: only process new bronze records
|
|
318
|
+
MERGE `project.silver.contacts` AS target
|
|
319
|
+
USING (
|
|
320
|
+
WITH latest AS (
|
|
321
|
+
SELECT *,
|
|
322
|
+
ROW_NUMBER() OVER (PARTITION BY JSON_VALUE(raw_payload, '$.id') ORDER BY ingestion_timestamp DESC) AS rn
|
|
323
|
+
FROM `project.bronze.zoho_crm_contacts`
|
|
324
|
+
WHERE ingestion_timestamp > (SELECT MAX(_audit.processed_at) FROM `project.silver.contacts`)
|
|
325
|
+
)
|
|
326
|
+
SELECT
|
|
327
|
+
JSON_VALUE(raw_payload, '$.id') AS contact_id,
|
|
328
|
+
JSON_VALUE(raw_payload, '$.First_Name') AS first_name,
|
|
329
|
+
JSON_VALUE(raw_payload, '$.Last_Name') AS last_name,
|
|
330
|
+
JSON_VALUE(raw_payload, '$.Email') AS email,
|
|
331
|
+
JSON_VALUE(raw_payload, '$.Account_Name.name') AS company,
|
|
332
|
+
PARSE_DATE('%Y-%m-%d', JSON_VALUE(raw_payload, '$.Created_Time')) AS created_date,
|
|
333
|
+
PARSE_DATE('%Y-%m-%d', JSON_VALUE(raw_payload, '$.Modified_Time')) AS modified_date,
|
|
334
|
+
'zoho-crm' AS source_system
|
|
335
|
+
FROM latest
|
|
336
|
+
WHERE rn = 1
|
|
337
|
+
) AS source
|
|
338
|
+
ON target.contact_id = source.contact_id
|
|
339
|
+
WHEN MATCHED THEN UPDATE SET
|
|
340
|
+
first_name = source.first_name,
|
|
341
|
+
last_name = source.last_name,
|
|
342
|
+
email = source.email,
|
|
343
|
+
company = source.company,
|
|
344
|
+
modified_date = source.modified_date,
|
|
345
|
+
_audit = STRUCT(CURRENT_TIMESTAMP() AS processed_at, GENERATE_UUID() AS processing_batch)
|
|
346
|
+
WHEN NOT MATCHED THEN INSERT ROW;
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Silver → Gold
|
|
350
|
+
|
|
351
|
+
```sql
|
|
352
|
+
-- Customer 360 aggregation
|
|
353
|
+
CREATE OR REPLACE TABLE `project.gold.customer_360` AS
|
|
354
|
+
SELECT
|
|
355
|
+
c.customer_id,
|
|
356
|
+
c.first_name || ' ' || c.last_name AS customer_name,
|
|
357
|
+
COUNT(o.order_id) AS total_orders,
|
|
358
|
+
SUM(o.amount) AS total_revenue,
|
|
359
|
+
AVG(o.amount) AS avg_order_value,
|
|
360
|
+
MIN(o.order_date) AS first_order_date,
|
|
361
|
+
MAX(o.order_date) AS last_order_date,
|
|
362
|
+
DATE_DIFF(CURRENT_DATE(), MAX(o.order_date), DAY) AS days_since_last_order,
|
|
363
|
+
CASE
|
|
364
|
+
WHEN SUM(o.amount) > 50000 THEN 'high_value'
|
|
365
|
+
WHEN SUM(o.amount) > 10000 THEN 'medium'
|
|
366
|
+
ELSE 'low'
|
|
367
|
+
END AS segment,
|
|
368
|
+
STRUCT(CURRENT_TIMESTAMP() AS last_updated, 'daily' AS update_frequency) AS _refresh
|
|
369
|
+
FROM `project.silver.customers` c
|
|
370
|
+
LEFT JOIN `project.silver.orders` o ON c.customer_id = o.customer_id
|
|
371
|
+
GROUP BY c.customer_id, c.first_name, c.last_name;
|
|
372
|
+
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# BigQuery Schema Design
|
|
2
|
+
|
|
3
|
+
## Medallion Layer Schemas
|
|
4
|
+
|
|
5
|
+
### Bronze Layer (Raw)
|
|
6
|
+
```sql
|
|
7
|
+
CREATE TABLE `project.bronze.zoho_crm_contacts` (
|
|
8
|
+
ingestion_id STRING NOT NULL,
|
|
9
|
+
ingestion_timestamp TIMESTAMP NOT NULL,
|
|
10
|
+
source_system STRING,
|
|
11
|
+
raw_payload JSON,
|
|
12
|
+
_metadata STRUCT<
|
|
13
|
+
source_file STRING,
|
|
14
|
+
batch_id STRING,
|
|
15
|
+
ingested_by STRING
|
|
16
|
+
>
|
|
17
|
+
)
|
|
18
|
+
PARTITION BY DATE(ingestion_timestamp)
|
|
19
|
+
OPTIONS(
|
|
20
|
+
description='Raw CRM contacts from Zoho API',
|
|
21
|
+
labels=[('layer', 'bronze'), ('source', 'zoho-crm')]
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Silver Layer (Cleansed)
|
|
26
|
+
```sql
|
|
27
|
+
CREATE TABLE `project.silver.contacts` (
|
|
28
|
+
contact_id STRING NOT NULL,
|
|
29
|
+
first_name STRING,
|
|
30
|
+
last_name STRING,
|
|
31
|
+
email STRING,
|
|
32
|
+
company STRING,
|
|
33
|
+
created_date DATE,
|
|
34
|
+
modified_date DATE,
|
|
35
|
+
source_system STRING,
|
|
36
|
+
_quality STRUCT<
|
|
37
|
+
is_valid_email BOOL,
|
|
38
|
+
is_duplicate BOOL,
|
|
39
|
+
quality_score FLOAT64
|
|
40
|
+
>,
|
|
41
|
+
_audit STRUCT<
|
|
42
|
+
processed_at TIMESTAMP,
|
|
43
|
+
processing_batch STRING
|
|
44
|
+
>
|
|
45
|
+
)
|
|
46
|
+
PARTITION BY modified_date
|
|
47
|
+
CLUSTER BY company, source_system;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Gold Layer (Business-Ready)
|
|
51
|
+
```sql
|
|
52
|
+
CREATE TABLE `project.gold.customer_360` (
|
|
53
|
+
customer_id STRING NOT NULL,
|
|
54
|
+
customer_name STRING,
|
|
55
|
+
total_orders INT64,
|
|
56
|
+
total_revenue NUMERIC,
|
|
57
|
+
avg_order_value NUMERIC,
|
|
58
|
+
first_order_date DATE,
|
|
59
|
+
last_order_date DATE,
|
|
60
|
+
segment STRING, -- 'high_value', 'medium', 'low'
|
|
61
|
+
churn_risk_score FLOAT64,
|
|
62
|
+
_refresh STRUCT<
|
|
63
|
+
last_updated TIMESTAMP,
|
|
64
|
+
update_frequency STRING
|
|
65
|
+
>
|
|
66
|
+
)
|
|
67
|
+
CLUSTER BY segment;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Partitioning Strategy
|
|
71
|
+
- Time-series data: Partition by DATE/TIMESTAMP
|
|
72
|
+
- Large tables: Partition by ingestion date if no natural time column
|
|
73
|
+
- Partition expiration: Set for bronze layer (90 days typical)
|
|
74
|
+
|
|
75
|
+
## Clustering Strategy (max 4 columns)
|
|
76
|
+
- First column: Most frequently filtered
|
|
77
|
+
- Order: Most selective to least selective
|
|
78
|
+
- Re-cluster after significant data changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cloudstream-project-template
|
|
3
|
+
description: CloudStream project structure template for new client projects. Covers Zoho + GCP project initialization, compliance mode selection, and standard directory layout.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
status: active
|
|
6
|
+
introduced: 1.0.0
|
|
7
|
+
lastUpdated: 2026-01-25
|
|
8
|
+
activation: New project setup, client onboarding, project structure questions
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# CloudStream Project Template
|
|
12
|
+
|
|
13
|
+
Standard project structure for CloudStream client engagements.
|
|
14
|
+
|
|
15
|
+
## Project Types
|
|
16
|
+
1. **Zoho Creator App**: Forms, reports, workflows, widgets
|
|
17
|
+
2. **Catalyst Full-Stack**: AppSail web apps + serverless functions
|
|
18
|
+
3. **Widget Standalone**: React/Next.js app for Zoho or independent use
|
|
19
|
+
4. **GCP Data Pipeline**: BigQuery + dbt medallion architecture
|
|
20
|
+
5. **Integration Project**: Connecting multiple Zoho apps or external systems
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Standard Project Structure
|
|
2
|
+
|
|
3
|
+
## Zoho Creator + Catalyst Project
|
|
4
|
+
```
|
|
5
|
+
project-root/
|
|
6
|
+
├── .claude/
|
|
7
|
+
│ └── CLAUDE.md # Client-specific config + compliance mode
|
|
8
|
+
├── .env.example # Required environment variables
|
|
9
|
+
├── catalyst/
|
|
10
|
+
│ ├── catalyst.json # Catalyst project config
|
|
11
|
+
│ ├── functions/
|
|
12
|
+
│ │ ├── proxy/ # CORS proxy for widget API calls
|
|
13
|
+
│ │ ├── webhooks/ # Webhook receivers
|
|
14
|
+
│ │ └── batch/ # Cron functions for batch processing
|
|
15
|
+
│ └── appsail/ # Full web app if needed
|
|
16
|
+
│ ├── Dockerfile
|
|
17
|
+
│ ├── package.json
|
|
18
|
+
│ └── src/
|
|
19
|
+
├── widgets/
|
|
20
|
+
│ ├── dashboard/ # Each widget is a React app
|
|
21
|
+
│ │ ├── package.json
|
|
22
|
+
│ │ ├── src/
|
|
23
|
+
│ │ └── dist/ # Built widget for upload
|
|
24
|
+
│ └── data-entry/
|
|
25
|
+
├── deluge/
|
|
26
|
+
│ ├── workflows/ # Creator workflow scripts
|
|
27
|
+
│ ├── functions/ # Standalone functions
|
|
28
|
+
│ └── scheduled/ # Scheduled tasks
|
|
29
|
+
├── docs/
|
|
30
|
+
│ ├── architecture.md
|
|
31
|
+
│ ├── api-reference.md
|
|
32
|
+
│ └── runbook.md
|
|
33
|
+
└── tests/
|
|
34
|
+
├── widgets/ # Widget unit tests
|
|
35
|
+
└── catalyst/ # Catalyst function tests
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## GCP Data Pipeline Project
|
|
39
|
+
```
|
|
40
|
+
project-root/
|
|
41
|
+
├── .claude/
|
|
42
|
+
│ └── CLAUDE.md
|
|
43
|
+
├── dbt/
|
|
44
|
+
│ ├── dbt_project.yml
|
|
45
|
+
│ ├── models/
|
|
46
|
+
│ │ ├── staging/ # Bronze → Silver
|
|
47
|
+
│ │ ├── intermediate/ # Silver transformations
|
|
48
|
+
│ │ └── marts/ # Gold layer
|
|
49
|
+
│ ├── tests/
|
|
50
|
+
│ └── macros/
|
|
51
|
+
├── dataflow/
|
|
52
|
+
│ ├── pipelines/
|
|
53
|
+
│ └── templates/
|
|
54
|
+
├── cloud-functions/
|
|
55
|
+
│ ├── ingestion/ # Bronze layer loaders
|
|
56
|
+
│ └── triggers/ # Event-driven processing
|
|
57
|
+
├── bigquery/
|
|
58
|
+
│ ├── schemas/ # Table definitions
|
|
59
|
+
│ ├── views/ # Materialized views
|
|
60
|
+
│ └── procedures/ # Stored procedures
|
|
61
|
+
└── terraform/ # Infrastructure as code
|
|
62
|
+
├── main.tf
|
|
63
|
+
├── variables.tf
|
|
64
|
+
└── outputs.tf
|
|
65
|
+
```
|