Skip to content

Commit a71e510

Browse files
authored
Document per-row path in the external_callout example (#159)
1 parent 1a3537e commit a71e510

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

  • src/datacustomcode/templates/script/examples/external_callout

‎src/datacustomcode/templates/script/examples/external_callout/README.md‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,43 @@ if response.is_success:
3737

3838
## Per-row path — fan out across the DataFrame
3939

40-
`named_credential_request_col` dispatches one callout per row; only the body
41-
Column varies.
40+
`named_credential_request_col` dispatches one callout per row. The body Column
41+
varies per row, and so can the optional `path` Column.
4242

4343
```python
4444
# One callout per row; body is a Column built from the row's data.
4545
df = df.withColumn("_callout", named_credential_request_col(request, body=body_col))
4646
```
4747

48+
### Optional per-row `path`
49+
50+
Pass `path` to call a different endpoint of the **same** Named Credential per
51+
row. It is appended to the template's URL, e.g. to pick a model per row when the
52+
Named Credential's URL stops at `.../v1beta/models`:
53+
54+
```python
55+
from pyspark.sql.functions import col, concat, lit, url_encode, when
56+
57+
# callout:gemini/gemini-2.5-pro:generateContent or .../gemini-2.5-flash:generateContent
58+
path = when(col("priority__c") == "high", lit("/gemini-2.5-pro:generateContent")).otherwise(
59+
lit("/gemini-2.5-flash:generateContent")
60+
)
61+
df = df.withColumn(
62+
"_callout", named_credential_request_col(request, body=body_col, path=path)
63+
)
64+
65+
# Query-string lookups work too: callout:geo?address=1+Market+St
66+
geo_path = concat(lit("?address="), url_encode(col("address__c")))
67+
```
68+
69+
- A path starting with `/` or `?` is appended as is; any other path is joined
70+
with `/` (`2/v1` → `callout:gemini/2/v1`), so a row can never switch to a
71+
different Named Credential.
72+
- A null or empty `path` uses the template's URL unchanged; omitting `path`
73+
behaves exactly as before.
74+
- Keep the template URL free of a query string when using `path` — put
75+
per-row query parameters in `path` instead.
76+
4877
It returns a struct Column:
4978

5079
```

0 commit comments

Comments
 (0)