@salesforce/afv-skills 1.71.0 → 1.72.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.
Files changed (116) hide show
  1. package/package.json +1 -1
  2. package/skills/agentforce-generate/SKILL.md +8 -0
  3. package/skills/agentforce-generate/assets/agents/README.md +1 -1
  4. package/skills/agentforce-generate/references/actions-reference.md +4 -0
  5. package/skills/agentforce-generate/references/mcp-actions-in-agent-script.md +233 -0
  6. package/skills/agentforce-generate/references/reference-map.md +1 -0
  7. package/skills/dx-packaging-convert-1gp-to-2gp-create/SKILL.md +9 -7
  8. package/skills/dx-packaging-convert-1gp-to-2gp-create/references/conversion-operations.md +78 -4
  9. package/skills/dx-packaging-move-to-2gp-migrate/SKILL.md +17 -13
  10. package/skills/dx-packaging-move-to-2gp-migrate/references/api-operations.md +110 -9
  11. package/skills/experience-app-mcp-generate/references/troubleshooting.md +1 -1
  12. package/skills/experience-app-mcp-generate/scripts/merge_tools.mjs +49 -18
  13. package/skills/experience-app-mcp-generate/scripts/render_eca.mjs +1 -1
  14. package/skills/experience-app-mcp-generate/scripts/render_mcp_server.mjs +1 -1
  15. package/skills/experience-app-mcp-generate/scripts/scan_tool_candidates.mjs +3 -1
  16. package/skills/experience-ui-bundle-custom-app-generate/SKILL.md +32 -26
  17. package/skills/experience-ui-bundle-custom-app-generate/references/configure-metadata-custom-application.md +6 -24
  18. package/skills/nonprofit-fundraising-configure/references/mcp-invocation.md +4 -6
  19. package/skills/platform-apex-generate/SKILL.md +2 -1
  20. package/skills/platform-apex-generate/assets/abstract.cls +0 -4
  21. package/skills/platform-apex-generate/assets/invocable-action-extension.invocableactionextension-meta.xml +28 -0
  22. package/skills/platform-apex-generate/assets/invocable.cls +2 -0
  23. package/skills/platform-apex-generate/references/dml-declarations.md +69 -0
  24. package/skills/platform-metadata-discovery-get/SKILL.md +15 -10
  25. package/skills/platform-metadata-grounding-get/SKILL.md +5 -3
  26. package/skills/service-add-agents-to-contact-center-create/SKILL.md +138 -0
  27. package/skills/service-agentforce-contact-center-coordinate/SKILL.md +5 -5
  28. package/skills/service-agentforce-contact-center-coordinate/references/omni-flow-routing.md +3 -3
  29. package/skills/service-agentforce-contact-center-coordinate/scripts/create-routing-flows.sh +8 -3
  30. package/skills/service-agentforce-contact-center-coordinate/scripts/create-voice-agent.sh +5 -5
  31. package/skills/service-agentforce-contact-center-coordinate/scripts/resolve-acc-queue.sh +10 -1
  32. package/skills/service-agentforce-contact-center-coordinate/scripts/resolve-channel-line.sh +4 -0
  33. package/skills/service-agentforce-contact-center-coordinate/scripts/resolve-flow-definition.sh +5 -0
  34. package/skills/service-agentforce-contact-center-coordinate/scripts/verify-number-live.sh +6 -1
  35. package/skills/service-concierge-portal-generate/SKILL.md +1 -1
  36. package/skills/service-concierge-portal-generate/references/portal-deploy-runbook.md +21 -8
  37. package/skills/service-digital-engagement-channel-configure/SKILL.md +45 -32
  38. package/skills/service-digital-engagement-channel-configure/assets/public_key_certificate_set_jwks_template.xml +20 -0
  39. package/skills/service-digital-engagement-channel-configure/assets/public_key_certificate_set_jwks_url_template.xml +23 -0
  40. package/skills/service-digital-engagement-channel-configure/assets/public_key_certificate_template.xml +15 -0
  41. package/skills/service-digital-engagement-channel-configure/examples/asa_agent_channel.xml +1 -1
  42. package/skills/service-digital-engagement-channel-configure/examples/auth_queue_channel.xml +3 -3
  43. package/skills/service-digital-engagement-channel-configure/examples/jwks_upload_key.xml +11 -0
  44. package/skills/service-digital-engagement-channel-configure/examples/jwks_upload_keyset.xml +13 -0
  45. package/skills/service-digital-engagement-channel-configure/examples/jwks_url_keyset.xml +17 -0
  46. package/skills/service-digital-engagement-channel-configure/examples/omni_flow_channel.xml +3 -3
  47. package/skills/service-digital-engagement-channel-configure/examples/omni_queue_channel.xml +3 -3
  48. package/skills/service-digital-engagement-channel-configure/examples/user_channel.xml +1 -1
  49. package/skills/service-digital-engagement-channel-configure/references/_vendored/service-onboarding-delegation-guidelines.md +43 -0
  50. package/skills/service-digital-engagement-channel-configure/references/channel_settings.md +1 -1
  51. package/skills/service-digital-engagement-channel-configure/references/keyset_settings.md +46 -0
  52. package/skills/service-digital-engagement-channel-configure/references/keyset_setup.md +42 -0
  53. package/skills/service-digital-engagement-channel-configure/references/onboarding_contract.md +28 -27
  54. package/skills/service-digital-engagement-channel-configure/references/recaptcha_handoff.md +2 -5
  55. package/skills/service-digital-engagement-channel-configure/references/routing_transitions.md +2 -2
  56. package/skills/service-digital-engagement-channel-configure/references/user_verification.md +3 -4
  57. package/skills/service-digital-engagement-channel-configure/references/user_verification_client.md +51 -0
  58. package/skills/service-digital-engagement-channel-configure/scripts/check-api-version.sh +7 -0
  59. package/skills/service-digital-engagement-deployment-configure/SKILL.md +28 -10
  60. package/skills/service-digital-engagement-deployment-configure/references/_vendored/service-onboarding-delegation-guidelines.md +43 -0
  61. package/skills/service-digital-engagement-deployment-configure/references/branding_and_tooling.md +2 -2
  62. package/skills/service-digital-engagement-deployment-configure/references/code_snippet.md +2 -2
  63. package/skills/service-digital-engagement-deployment-configure/references/connect_api_creation.md +13 -7
  64. package/skills/service-digital-engagement-deployment-configure/references/custom_labels.md +127 -0
  65. package/skills/service-digital-engagement-deployment-configure/references/deployment_settings.md +2 -1
  66. package/skills/service-digital-engagement-deployment-configure/references/onboarding_contract.md +24 -25
  67. package/skills/service-digital-engagement-deployment-configure/references/prechat_forms.md +1 -1
  68. package/skills/service-digital-engagement-deployment-configure/scripts/check-api-version.sh +7 -0
  69. package/skills/service-email-to-case-configure/SKILL.md +89 -80
  70. package/skills/service-email-to-case-configure/assets/CaseSettings.settings-meta.xml +1 -1
  71. package/skills/service-email-to-case-configure/examples/CaseSettings-two-addresses.settings-meta.xml +6 -3
  72. package/skills/service-email-to-case-configure/references/_vendored/service-onboarding-delegation-guidelines.md +43 -0
  73. package/skills/service-email-to-case-configure/references/agent-delegation.md +22 -0
  74. package/skills/service-email-to-case-configure/references/apply-mechanics.md +15 -12
  75. package/skills/service-email-to-case-configure/references/end-to-end-proof.md +14 -0
  76. package/skills/service-email-to-case-configure/references/onboarding-delegated-run.md +66 -0
  77. package/skills/service-email-to-case-configure/references/routing_address_reference.md +6 -2
  78. package/skills/service-email-to-case-configure/references/troubleshooting.md +17 -9
  79. package/skills/service-email-to-case-configure/scripts/apply-casesettings.py +863 -925
  80. package/skills/service-email-to-case-configure/scripts/tests/_agent.py +162 -0
  81. package/skills/service-email-to-case-configure/scripts/tests/_fakeorg.py +119 -155
  82. package/skills/service-email-to-case-configure/scripts/tests/_run.py +10 -17
  83. package/skills/service-email-to-case-configure/scripts/tests/test_apply_org_scenarios.py +14 -14
  84. package/skills/service-email-to-case-configure/scripts/tests/test_dispatch_contract.py +316 -0
  85. package/skills/service-email-to-case-configure/scripts/tests/test_new_capabilities.py +12 -43
  86. package/skills/service-email-to-case-configure/scripts/tests/test_validate_casesettings.py +13 -0
  87. package/skills/service-email-to-case-configure/scripts/validate-casesettings.py +17 -5
  88. package/skills/service-itsm-agentic-setup-incident-management/references/status-checks.md +11 -11
  89. package/skills/service-remove-agents-from-contact-center-assign/SKILL.md +145 -0
  90. package/skills/service-voice-configuration-manage/SKILL.md +206 -0
  91. package/skills/service-voice-configuration-manage/assets/regions.json +23 -0
  92. package/skills/service-voice-configuration-manage/references/lookups.md +91 -0
  93. package/skills/service-voice-configuration-manage/references/voice_config_api.md +169 -0
  94. package/skills/service-voice-configuration-manage/scripts/create-configuration.sh +20 -0
  95. package/skills/service-voice-configuration-manage/scripts/delete-configuration.sh +31 -0
  96. package/skills/service-voice-configuration-manage/scripts/get-configuration.sh +18 -0
  97. package/skills/service-voice-configuration-manage/scripts/lib.sh +22 -0
  98. package/skills/service-voice-configuration-manage/scripts/list-configurations.sh +18 -0
  99. package/skills/service-voice-configuration-manage/scripts/lookup-caller-lines.sh +30 -0
  100. package/skills/service-voice-configuration-manage/scripts/lookup-flows.sh +29 -0
  101. package/skills/service-voice-configuration-manage/scripts/lookup-profiles.sh +29 -0
  102. package/skills/service-voice-configuration-manage/scripts/lookup-users.sh +29 -0
  103. package/skills/service-voice-configuration-manage/scripts/update-configuration.sh +20 -0
  104. package/skills/tableau-next-asset-create/SKILL.md +10 -4
  105. package/skills/tableau-next-asset-create/references/dashboard-design-principles.md +133 -0
  106. package/skills/tableau-next-asset-create/references/data-transform-gotchas.md +284 -128
  107. package/skills/tableau-next-asset-create/references/deep-reference-index.md +3 -3
  108. package/skills/tableau-next-asset-create/references/edit-dashboard.md +1 -1
  109. package/skills/tableau-next-asset-create/references/edit-visualization.md +678 -468
  110. package/skills/tableau-next-asset-create/references/shared-gates.md +1 -1
  111. package/skills/tableau-next-asset-create/references/tasks/create-data-transform.md +120 -42
  112. package/skills/tableau-next-asset-create/references/tasks/create-viz.md +8 -0
  113. package/skills/tableau-next-asset-create/references/tasks/edit-viz.md +7 -4
  114. package/skills/tableau-next-asset-create/references/tasks/promote-or-reuse.md +9 -4
  115. package/skills/tableau-next-asset-create/references/viz-authoring.md +1 -1
  116. package/skills/service-email-to-case-configure/scripts/tests/test_get_session.py +0 -134
@@ -1,7 +1,7 @@
1
1
  # Data Cloud SQL transforms — payloads and gotchas
2
2
 
3
- Load this from `tasks/create-data-transform.md` (create **or** update). Not a
4
- first hop.
3
+ Read `tasks/create-data-transform.md` first. This file contains the response
4
+ interpretation and technical contract needed for that workflow.
5
5
 
6
6
  Transforms run on **SparkInternal (SI)**, a subset of Data Cloud SQL. The
7
7
  transform **creates its output object automatically** — do not pre-create the
@@ -9,103 +9,69 @@ target DLO/DMO.
9
9
 
10
10
  ## Contents
11
11
 
12
- - Confirm before create / run / update → Confirmation
13
- - Poll run history after run; `ACTIVE` ≠ rows ready → Run completion
14
- - Fresh derived table (create) → Create
15
- - Revise an existing transform-backed table → Update
16
- - Nested `definitions` / `manifest` / `nodes.out` → Payload
17
- - Flat body for create / update / validate (no envelope) → Payload
18
- - BATCH↔DCSQL pairing, DMO `KQ_<pk>`, `fullRunFrequency` → Payload
19
- - Output field names need `__c` → Payload
20
- - SparkInternal unsupported ops → DCSQL
21
- - Distinctive errors → Errors
22
-
23
- ## Confirmation
24
-
25
- **NEVER call `create_data_transform`** or `update_data_transform` (or
26
- `run_data_transform`) without explicit user approval. Show the generated SQL
27
- plus a short `run_query` / `validate_data_transform` preview, state that a
28
- new derived table will be created (or that `<outputApiName>` will be
29
- redefined), and wait for an explicit "yes" / "proceed" / "go ahead". Silence
30
- is not consent. Triggering the run is a **separate** confirmation gate.
31
-
32
- Do not call `run_data_transform` while the transform is `PROCESSING` (it
33
- fails). Lifecycle: `create → PROCESSING (~few min) → ACTIVE → run →
34
- executes (typically 10–15 min)`. Creation becoming `ACTIVE` is not the
35
- same as the output having rows — the run itself is the long step. After
36
- `run_data_transform`, poll `get_data_transform_run_history` (see Run
37
- completion).
38
-
39
- ## Run completion
40
-
41
- After `run_data_transform`, poll `get_data_transform_run_history` until the
42
- run succeeds or fails. Runs may be synchronous or asynchronous depending on
43
- the transform's mode — do **not** infer completion from
44
- `get_data_transform` status (`ACTIVE` means the definition is runnable, not
45
- that this run finished or that the output has rows). If status looks stuck
46
- (still running after the job should have finished), call
47
- `refresh_data_transform_status` then poll history again.
48
-
49
- ## Create vs update
50
-
51
- - **Create** when the target output object does **not** already exist.
52
- - **Update** when the output is already transform-backed. Never create a
53
- second transform for a table that already has one.
54
-
55
- **Create workflow:** `browse_data_assets` for the exact `assetApiName` (with
56
- `__dll` / `__dlm`) — if multiple match, STOP and ask → generate DCSQL →
57
- `validate_data_transform` and/or `run_query(sql, rowLimit: 10)` → confirm →
58
- create → `add_workspace_asset` on the new output → confirm →
59
- `run_data_transform` → poll `get_data_transform_run_history`. Persist the
60
- returned `id`. Batch cadence can be set
61
- on create via `fullRunFrequency` — do not assume scheduling only happens
62
- through `set_data_transform_schedule`.
63
-
64
- **Update workflow:** `get_data_transform` first and resend the **entire**
65
- structure (not a partial patch). Change only editable fields (typically
66
- `compiled_code` and `fields` if SELECT columns changed). Copy every 🔒
67
- immutable field byte-for-byte. Validate → confirm → update. Skip add-to-
68
- workspace. Confirm before run — the output stays OLD until the transform
69
- runs. After run, poll `get_data_transform_run_history` (see Run completion).
70
-
71
- **ALWAYS append the SAME 4-digit random number** (1000–9999) to all three API
72
- names in one transform: `transform_<n>`, `definition_<n>`, and
73
- `output_<n>__dll` (or `__dlm` for a DMO). Example: `my_transform_7521`,
74
- `my_definition_7521`, `my_output_7521__dll`. Avoids "Duplicate name" errors.
12
+ - Reading saved transforms — empty history/schedule, saved `STL` types
13
+ - Naming — shared suffix, 40-character output limit
14
+ - Payload (reference shape) — flat body, `__c` fields, DMO `KQ_<pk>`, 🔒 fields
15
+ - Timeout recovery — read back before any retry
16
+ - DCSQL (SparkInternal) — **writing SQL: read this whole section**
17
+ - Before returning SQL (mandatory) · Not supported → use instead ·
18
+ No alternative · Patterns · Cross-engine safety · Diagnostics
19
+
20
+ ## Reading saved transforms
21
+
22
+ Empty run history means **no visible run records**; an empty schedule response
23
+ means **no schedule returned**. Neither proves how the transform has or has
24
+ not run. Report saved types as returned: a BATCH transform with an `STL`
25
+ definition is not invalid because the create/update workflow authors BATCH +
26
+ `DCSQL`.
27
+
28
+ ## Naming
29
+
30
+ Transform, definition, and output apiNames must be unique. When generating
31
+ names automatically, apply the same four-digit suffix to all three:
32
+
33
+ `transform_<n>` · `definition_<n>` · `output_<n>__dll`
34
+
35
+ Use `__dlm` for a DMO output.
36
+
37
+ Keep each output object's `name` and `label` at **40 characters or fewer**.
38
+ Derive a short output name independently of the transform label, while
39
+ preserving the `__dll` or `__dlm` suffix; do not blindly copy a long
40
+ transform label into either field. Count the suffix within the 40-character
41
+ name limit; validation may pass a name that creation rejects.
75
42
 
76
43
  ## Payload (reference shape)
77
44
 
78
45
  `outputDataObjects` is **required** — omitting it → *"Target Dlo not found"*.
79
46
  `manifest.nodes.out.relation_name` must === `outputDataObjects[0].name`.
80
47
  `fields` count/names/types must match SELECT columns. At least one
81
- `fields[].isPrimaryKey` must be `true`. Pair top-level `type` with
82
- `definitions[].type`: **BATCH → `DCSQL`**, **STREAMING → `SQL`**. The
83
- schema otherwise allows `DCSQL` / `SQL` / `STL` as a free choice — a
84
- mismatched pair fails. DMO outputs need `dataSpaceName` and
48
+ `fields[].isPrimaryKey` must be `true`; choose a non-null key unique at the
49
+ output grain, including after joins or aggregation. For transforms authored
50
+ through this create/update workflow, pair **BATCH → `DCSQL`** and
51
+ **STREAMING → `SQL`**.
52
+ Set field types and primary-key flags in the submitted body. Validation can
53
+ return an inferred schema with every field as `Text` and every primary-key flag
54
+ as `false`; do not use that response to overwrite the submitted field contract.
55
+ DMO outputs need `dataSpaceName` and
85
56
  `type: "dataModelObject"` with a `__dlm` name, plus a key-qualifier:
86
- each PK carries `"keyQualifierField": "KQ_<pk>"` and you add an explicit
87
- `KQ_<pk>` field (same suffix as the PK name).
88
-
89
- Date SQL (`cast(x AS date)`) maps to field type **`DateOnly`** (not `Date`).
90
-
91
- **Every output field name must be `__c`-suffixed** (same convention as
92
- DLO/DMO ingest fields) — SELECT column aliases in `compiled_code` and the
93
- matching `fields[].name` entries all need the suffix, e.g. `status__c`,
94
- `order_count__c`, not `status`, `order_count`. `validate_data_transform`
95
- does **not** reject a bare alias — it silently derives an `__c`-suffixed
96
- field in the schema it returns without warning. If you then create/update
97
- with the bare alias still in `compiled_code`, the transform creates fine
98
- and goes `ACTIVE`, but `run_data_transform` fails post-hoc with `"target
99
- object ... doesn't have the required field <bare_alias>"` because the
100
- runtime write binds by the literal SQL alias, which no longer matches the
101
- silently-renamed backing field. Always write `__c`-suffixed aliases
102
- yourself in both `compiled_code` and `fields[]` — do not rely on
103
- `validate_data_transform`'s response to catch a bare one.
57
+ each PK carries `"keyQualifierField": "KQ_<pk>"` and you add the matching
58
+ qualifier to both `fields[]` and the SQL output. Preserve the PK's `__c`
59
+ suffix in the qualifier name, for example `id__c` → `KQ_id__c`.
60
+
61
+ A SQL `date` column maps to field type **`DateOnly`** (not `Date`).
62
+
63
+ **Every output field name must be `__c`-suffixed.** Use the same suffixed name
64
+ in the `compiled_code` SELECT alias and `fields[].name`, for example
65
+ `status__c`, not `status`. `validate_data_transform` may silently suffix its
66
+ derived schema without rejecting the bare SQL alias; creation then succeeds,
67
+ but `run_data_transform` fails because the SQL alias and backing field differ.
68
+ Never rely on validation to catch this mismatch.
104
69
 
105
70
  `create_data_transform`, `update_data_transform`, and
106
71
  `validate_data_transform` all take this **same flat body** — `name`,
107
72
  `type`, `definitions` at the top level. Do **not** wrap it in
108
- `dataTransformObject` or `dataTransform`.
73
+ `dataTransformObject` or `dataTransform`. Pass a structured object, not a
74
+ JSON-encoded string; `definitions` must be an array, not serialized JSON text.
109
75
 
110
76
  ```json
111
77
  {
@@ -135,7 +101,8 @@ yourself in both `compiled_code` and `fields[]` — do not rely on
135
101
  "name": "out",
136
102
  "relation_name": "my_output_1234__dll",
137
103
  "config": { "materialized": "table" },
138
- "compiled_code": "SELECT id__c, cast(amount__c AS numeric) AS \"amount__c\" FROM \"source__dll\""
104
+ "depends_on": { "nodes": [] },
105
+ "compiled_code": "SELECT id__c, try_cast(amount__c AS decimal(18,2)) AS \"amount__c\" FROM \"source__dll\""
139
106
  }
140
107
  },
141
108
  "sources": { "src1": { "relation_name": "source__dll" } }
@@ -144,12 +111,22 @@ yourself in both `compiled_code` and `fields[]` — do not rely on
144
111
  }
145
112
  ```
146
113
 
114
+ `depends_on.nodes` names upstream **manifest nodes**, not entries in
115
+ `manifest.sources`. For an output node that reads a source directly, use `[]`;
116
+ putting a source key there can cause opaque mapping/output validation errors.
117
+
118
+ For a new DLO, project business columns explicitly rather than copying source
119
+ system fields such as `DataSource__c`, `DataSourceObject__c`, `KQ_*`,
120
+ `cdp_sys_*`, or `InternalOrganization__c`; validation can drop them and create
121
+ can then fail with `MktDataLakeField CDPServiceException`. The explicit
122
+ `KQ_<pk>` field required for a **DMO output** above is a separate exception.
123
+
147
124
  DMO output fields (instead of the DLO pair above) — PK + explicit qualifier:
148
125
 
149
126
  ```json
150
127
  [
151
- { "name": "id__c", "label": "ID", "type": "Text", "isPrimaryKey": true, "keyQualifierField": "KQ_id" },
152
- { "name": "KQ_id", "label": "KQ id", "type": "Text", "isPrimaryKey": false }
128
+ { "name": "id__c", "label": "ID", "type": "Text", "isPrimaryKey": true, "keyQualifierField": "KQ_id__c" },
129
+ { "name": "KQ_id__c", "label": "KQ id", "type": "Text", "isPrimaryKey": false }
153
130
  ]
154
131
  ```
155
132
 
@@ -162,15 +139,22 @@ DMO output fields (instead of the DLO pair above) — PK + explicit qualifier:
162
139
  **Changing any 🔒 field → 400.** Editable: labels, description, DMO
163
140
  `dataSpaceName`, `category`, `fields[]`, `compiled_code`, `manifest.sources`.
164
141
 
165
- ## Update timeout
142
+ ## Timeout recovery
166
143
 
167
- The update API may time out while the update **succeeds** on the server.
168
- **NEVER blindly retry.** On `TIMEOUT` / 504 / "timed out":
144
+ An API timeout does not establish whether a write succeeded. On `TIMEOUT` /
145
+ 504 / "timed out", read back before retrying:
169
146
 
170
- 1. `get_data_transform`.
171
- 2. Compare `definitions[0].manifest.nodes.out.compiled_code` to the new SQL.
172
- 3. If it **matches** → succeeded; do not retry.
173
- 4. If it **differs** → did not apply; retry once.
147
+ - **Create:** resolve the submitted transform name with
148
+ `browse_data_assets_v2` and inspect any match with `get_data_transform`.
149
+ Do not generate another name or create a duplicate. Retry the same validated,
150
+ approved body only after absence is established.
151
+ - **Update:** call `get_data_transform` and compare every requested change,
152
+ including `compiled_code`, fields, and output metadata. Matching SQL alone
153
+ does not prove a field- or metadata-only update applied. If all requested
154
+ changes match, report success. If processing is still pending or the read
155
+ cannot establish the outcome, report it as unresolved. Once processing has
156
+ settled and the requested changes are absent, retry the same validated,
157
+ approved body at most once.
174
158
 
175
159
  ## DCSQL (SparkInternal)
176
160
 
@@ -178,33 +162,205 @@ This SI subset is **only** for `create_data_transform` / `update_data_transform`
178
162
  Do not carry it over to `run_query` (that is Hyper SQL / full SELECT — see
179
163
  `tasks/query-model.md`).
180
164
 
181
- Validate with `run_query(sql, rowLimit: 10)` for a fast preview; SI
182
- compatibility is checked inside create/update. On failure, swap the
183
- unsupported op and retry.
184
-
185
- Compressed substitutions (do not use the left-hand ops):
186
-
187
- | Unsupported | Use instead |
188
- |---|---|
189
- | `varpop(x)` / `varsamp(x)` | `power(stddevpop(x),2)` / `power(stddevsamp(x),2)` |
190
- | `regexpreplace` / `regexpsubstr` | `replace()` + `substring()` |
191
- | `position(x in y)` | `arrayposition(y,x)` (arrays) or compute manually |
192
- | `age(d1,d2)` | `datediff(unit, d2, d1)` |
193
- | `tochar(v,fmt)` | `cast(v AS varchar)` |
194
- | `val <=all (subq)` / `>=all` | `val <= (select min(...) …)` / `>= (select max(...) …)` |
195
-
196
- Also unsupported: `chr`, `overlay`, `similarto`, `trunc`, `sequence`,
197
- `regexp*`, fiscal `extract*`, casts `date←timestamp` / `integer←bigint` /
198
- `timestamp←varchar`. Avoid correlated subqueries and deeply nested `CASE`.
199
-
200
- ## Errors
201
-
202
- | Error | Fix |
203
- |---|---|
204
- | `Target Dlo not found` | Include `outputDataObjects` |
205
- | `Schema mismatch` | `fields` must match SELECT columns exactly |
206
- | `At least one field must be primary key` | `isPrimaryKey: true` on ≥1 field |
207
- | `Source relation not found` | exact `assetApiName` from `browse_data_assets`, with `__dll`/`__dlm` |
208
- | `relation_name` mismatch | `manifest.nodes.out.relation_name` === `outputDataObjects[0].name` |
209
- | `DMO requires dataSpaceName` | `"dataSpaceName": "default"` at transform level |
210
- | `target object ... doesn't have the required field <name>` (on run, not create/validate) | Bare (non-`__c`) SELECT alias — re-suffix it `<name>__c` in both `compiled_code` and `fields[]`, then update |
165
+ `run_query(sql, rowLimit: 10)` previews rows; `validate_data_transform` checks
166
+ the request contract. **Neither proves the transform will run.** Everything
167
+ below can pass both and still fail at run time. These rules override any
168
+ passing check.
169
+
170
+ ### Before returning SQL (mandatory)
171
+
172
+ Scan the **whole** SQL — including SQL kept from a saved transform — and fix
173
+ every hit before you preview, validate, show, create, or update:
174
+
175
+ 1. **§Not supported** → rewrite to the listed alternative.
176
+ 2. **§No alternative** → remove it, simplify the output, and tell the user
177
+ what was dropped.
178
+ 3. **`NOT IN` / `<> ALL`** → add `col IS NOT NULL`.
179
+ 4. **`ORDER BY`** (query-level and inside `OVER`) → add `NULLS FIRST` or
180
+ `NULLS LAST`. Exception: write percentiles exactly as
181
+ `percentile_cont(0.5) WITHIN GROUP (ORDER BY x)`, with no `NULLS` clause.
182
+
183
+ If preview rejects an alternative, never revert to the unsupported form; drop
184
+ that expression from the preview and tell the user.
185
+
186
+ ### Not supported → use instead
187
+
188
+ `col` column · `n` number · `ts` timestamp · `d` date
189
+
190
+ **Casts**
191
+
192
+ - Plain `cast` from text → `try_cast` (plain cast fails at run time).
193
+ - `numeric` / `decimal` without precision, `bignumeric`, `real` →
194
+ `decimal(18,2)` or `numeric(38,18)`.
195
+ - Text numbers →
196
+ `try_cast(nullif(trim(replace(replace(col, '$', ''), ',', '')), '') AS decimal(18,2))`.
197
+ - Text-parsed timestamp straight to `date` →
198
+ `try_cast(try_cast(col AS timestamptz) AS date)`.
199
+ - `timestamp` / `time` / `double` to `varchar`, `interval`, `char(n)`,
200
+ `varchar(n)` → keep the native type.
201
+ - Decimal to text → `cast(cast(x AS numeric(38,2)) AS varchar)`.
202
+ - `integer` / `smallint` from `bigint` → `try_cast`.
203
+ - `bool` to a number → `CASE WHEN b THEN 1 WHEN NOT b THEN 0 END`.
204
+
205
+ **Strings and regex**
206
+
207
+ - `||` on nullable inputs (returns `NULL`) → `concat()`, which skips `NULL`s.
208
+ When the result must stay `NULL`, guard it (§Cross-engine).
209
+ - `regexp_replace` without a flag → `regexp_replace(col, pattern, replacement, 'g')`
210
+ (or `'ig'`). Without it, preview replaces only the first match and
211
+ validation can return `invalidStl`.
212
+ - `regexp_substr` with an occurrence argument → `split_part(col, delimiter, n)`
213
+ or `regexp_substr(col, pattern[, start])`.
214
+ - `instr`, `locate` → `position(sub IN col)` or `strpos(col, sub)`.
215
+ - `translate` → nested `replace()`.
216
+ - `overlay` → `concat(substring(…), 'X', substring(…))`.
217
+ - `SIMILAR TO` with regex classes → `~` or `regexp_like`.
218
+
219
+ **JSON**
220
+
221
+ - `->`, `->>`, `json_value`, `get_json_object`, `json_extract_path_text`,
222
+ `from_json` → `split_part(regexp_substr(col, '"key"\s*:\s*"[^"]*'), '"', 4)`.
223
+ String values only. The SQL has one backslash before `s`; the JSON request
224
+ body carries it as `\\s`.
225
+
226
+ **Dates and times**
227
+
228
+ - `dateadd`, `ts + interval`, `justify_*`, `make_interval` →
229
+ `date_add('day', cast(n AS integer), ts)`.
230
+ - `date_diff`, `age`, `ts - ts`, interval arithmetic → `datediff('day', a, b)`.
231
+ - `to_char`, `trunc(date)` → `date_trunc('month', ts)`, `extract`, or
232
+ `try_cast`.
233
+ - `current_time` → `current_timestamp`.
234
+ - `make_time`, `make_timestamp` →
235
+ `try_cast(concat(date_text, ' ', time_text) AS timestamp)`.
236
+ - `last_day(d)` →
237
+ `date_add('day', -1, date_add('month', 1, date_trunc('month', d)))`.
238
+
239
+ **Numeric**
240
+
241
+ - `trunc(number)` → `CASE WHEN x >= 0 THEN floor(x) ELSE ceil(x) END`.
242
+ - `div(a, b)` → the same `CASE` on `a / b`.
243
+ - `log10` → `ln(x) / ln(10)`. **`log` is base 10; `ln` is natural.**
244
+ - `try_log`, `try_power` → `CASE` guard + `log` / `power`, e.g.
245
+ `CASE WHEN x > 0 THEN log(x) END`.
246
+
247
+ **Aggregates**
248
+
249
+ - `count_if(cond)` → `sum(CASE WHEN cond THEN 1 ELSE 0 END)`.
250
+ - `variance`, `var_samp` → `covar_samp(x, x)`.
251
+ - `var_pop` → `covar_pop(x, x)`.
252
+ - `corr(x, y)` → `covar_pop(x, y) / (stddev_pop(x) * stddev_pop(y))`.
253
+ - `median(x)` → `percentile_cont(0.5) WITHIN GROUP (ORDER BY x)` with
254
+ `GROUP BY`.
255
+ - `mode`, `percent_mode` → §Patterns: top value per group.
256
+
257
+ **Window functions**
258
+
259
+ - `median`, `percentile_cont`, `percentile_disc`, `covar_*`, or
260
+ `count(DISTINCT …)` with `OVER` → §Patterns: aggregate joined back.
261
+ - `QUALIFY` → subquery + outer `WHERE`.
262
+ - `modified_rank` → `rank()` or `dense_rank()`.
263
+ - `lag` / `lead` default of another type, e.g. `lag(x, 1, 0)` →
264
+ `lag(x, 1, x)` or `lag(x, 1, cast(0 AS numeric(38,18)))`.
265
+
266
+ **Other**
267
+
268
+ - `unnest`, `sequence`, `generate_series` with column bounds →
269
+ `CROSS JOIN generate_series(1, <constant>) AS g(n)`.
270
+ - Bare `sha256` (binary) → `encode(sha256(col), 'hex')`.
271
+ - Bare `decode` (binary) → `encode(decode(col, 'base64'), 'escape')`.
272
+ - `greatest` / `least` that must preserve `NULL`s → `CASE WHEN`.
273
+
274
+ ### No alternative — never emit
275
+
276
+ Simplify the request instead, and tell the user.
277
+
278
+ - **Arrays:** `ARRAY[]`, `array_*`, `string_to_array`, `split`, `cardinality`,
279
+ `array_agg`.
280
+ - **Vectors:** `dot_product`, `cosine_similarity`, `binary_quantize`,
281
+ `hamming_similarity`.
282
+ - **Aggregates:** ordered `string_agg`, `listagg`, `regr_*`.
283
+ - **Characters and bits:** `chr`, `try_chr`, `to_hex`, `quote_ident`,
284
+ `quote_literal`, `get_bit`, `set_bit`, `set_byte`.
285
+ - **Regex:** `tb_regexp_extract_nth`.
286
+ - **Dates:** fiscal extracts, timezone extracts, `extract` on `time`,
287
+ `to_timestamp(number)`.
288
+
289
+ ### Patterns
290
+
291
+ **Aggregate joined back** (windowed median, percentile, `covar_*`,
292
+ `count(DISTINCT)`):
293
+
294
+ ```sql
295
+ SELECT o.order_id__c, o.region__c, m.region_median__c
296
+ FROM "orders__dll" o
297
+ LEFT JOIN (
298
+ SELECT region__c,
299
+ percentile_cont(0.5) WITHIN GROUP (ORDER BY amount__c) AS region_median__c
300
+ FROM "orders__dll"
301
+ GROUP BY region__c
302
+ ) m ON m.region__c = o.region__c
303
+ ```
304
+
305
+ **Top value per group** (`mode`; the outer `WHERE` is also the `QUALIFY`
306
+ rewrite):
307
+
308
+ ```sql
309
+ SELECT region__c, product__c AS top_product__c
310
+ FROM (
311
+ SELECT region__c, product__c,
312
+ row_number() OVER (
313
+ PARTITION BY region__c
314
+ ORDER BY count(*) DESC NULLS LAST, product__c ASC NULLS LAST
315
+ ) AS rn
316
+ FROM "orders__dll"
317
+ GROUP BY region__c, product__c
318
+ ) ranked
319
+ WHERE rn = 1
320
+ ```
321
+
322
+ ### Cross-engine and payload safety
323
+
324
+ The same SQL crosses three compatibility boundaries: Hyper executes the
325
+ preview, SparkInternal executes the transform, and JSON carries the SQL in the
326
+ request body. Write for all three:
327
+
328
+ - **Guard nullable expressions explicitly.** Do not rely on
329
+ `concat(NULL, suffix)` to stay `NULL`; Hyper can treat the null argument as
330
+ an empty string. When a missing input must yield `NULL`, guard the complete
331
+ expression before parsing or casting:
332
+
333
+ ```sql
334
+ CASE
335
+ WHEN iso_date IS NULL THEN NULL
336
+ ELSE try_cast(concat(substring(iso_date, 1, 7), '-01') AS date)
337
+ END
338
+ ```
339
+
340
+ - **Avoid escape-sensitive predicates.** Do not use `LIKE ... ESCAPE` or
341
+ backslash-dependent patterns when a supported string primitive is enough;
342
+ behavior can differ between engines and JSON adds another escaping layer.
343
+ For example, detect a percent sign with `replace(value, '%', '') <> value`.
344
+ The JSON pattern above is the one exception.
345
+ - **Preserve SQL text and literals.** Use a JSON serializer for the request;
346
+ do not flatten SQL by globally collapsing whitespace or rewriting escapes.
347
+ Such cleanup can change spaces inside string literals and silently alter the
348
+ transform. Send actual newlines in the `sql` argument, not literal `\n` text.
349
+ - **Use a preview-compatible numeric type.** Hyper rejects `DOUBLE` as a cast
350
+ target, while validation can infer `DOUBLE PRECISION` as `Text`. Use an
351
+ explicit precision and scale such as `decimal(18,2)`. Preserve negative
352
+ signs when cleaning parenthesized amounts.
353
+
354
+ ### Preview and validation diagnostics
355
+
356
+ - `Mapping set Cannot Be Empty` and `At least one output object is required`
357
+ may be follow-on validation errors. Inspect the other issue first:
358
+ `invalidStl` points to SQL (including a missing regex flags argument);
359
+ `unable to validate: {manifest}` can mean `depends_on.nodes` incorrectly
360
+ contains a source key.
361
+ - In `run_query`, `REGEXP_SUBSTR` accepts only the string, pattern, and optional
362
+ start position; group index, `e` flag, and occurrence `-1` are unsupported.
363
+ `SUBSTRING(x FROM regex)`, regex lookaheads, `REGEXP_EXTRACT`, `JSON_VALUE`,
364
+ `JSON_QUERY`, `json_extract`, `json_extract_string`, `STRFTIME`, and
365
+ `STRPTIME` are not reliable preview substitutes here. Avoid
366
+ `TO_DATE(x, 'M/D/YYYY')`: `D` is interpreted as day-of-week by this parser.
@@ -24,9 +24,9 @@ router (`SKILL.md`); the first-hop rules there still apply.
24
24
  gotchas (§B);
25
25
  cited by `ingest-flat-file.md` and `enrich-model.md`. **Not a first hop** for
26
26
  an ingest-how-to (that first-hops to `tasks/ingest-flat-file.md`).
27
- - **`references/data-transform-gotchas.md`** — DCSQL transform create/update
28
- payload, confirmation gates, immutable fields, timeout recovery, BATCH↔DCSQL
29
- pairing, DMO `KQ_<pk>`. Cited by
27
+ - **`references/data-transform-gotchas.md`** — saved-transform read caveats,
28
+ DCSQL create/update payload, immutable fields, timeout recovery, authoring
29
+ type pairing, DMO `KQ_<pk>`. Cited by
30
30
  `tasks/create-data-transform.md`; **not a first hop.**
31
31
  - **`references/sharing-and-promotion.md`** — principal lookup, access-type
32
32
  matrix, Personal Org shadow IDs, safe share mutation, Reuse/Promotion
@@ -225,7 +225,7 @@ this doc and flag it for a doc update.
225
225
  save on the user's explicit confirmation given *after* seeing it — even if the
226
226
  original request already said "save it" in the same message as the edit (same
227
227
  discipline as `edit_visualization` → `update_visualization`,
228
- `edit-visualization.md` §8).
228
+ `edit-visualization.md` "Persistence handoff").
229
229
 
230
230
  ## 6. Deleting a widget — `remove_widget_from_dashboard`
231
231