Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0c7ec2c
Add column casing hints for lowercase requirement
markdlv-sf Aug 18, 2026
0017c14
Merge remote-tracking branch 'origin/main' into column-casing-hints
markdlv-sf Aug 19, 2026
b2d3a64
Merge pull request #138 from forcedotcom/column-casing-hints
markdlv-sf Aug 20, 2026
5f79ab5
support dlo output object schema
zach-maddox Sep 15, 2026
47b47ee
linter fix
zach-maddox Sep 16, 2026
6df7437
Merge pull request #143 from forcedotcom/support-dlo-output-object-sc…
zach-maddox Sep 16, 2026
a4a61d6
Add 3 new scripts into new docs/examples
markdlv-sf Sep 23, 2026
7130e6f
Lint fixes
markdlv-sf Sep 23, 2026
b0a8735
Merge pull request #146 from forcedotcom/develop
zach-maddox Sep 29, 2026
1a5c63c
Merge pull request #144 from forcedotcom/examples-for-docs
markdlv-sf Sep 30, 2026
340be1c
support local testing of streaming transforms
atulikumwenayo Sep 30, 2026
c0e6ecf
defer pyspark loading - regression fix
zach-maddox Sep 30, 2026
12d4c97
Merge pull request #153 from forcedotcom/pyspark-defer-loading
zach-maddox Sep 30, 2026
5f34e3e
Merge pull request #150 from forcedotcom/localStreaming3
atulikumwenayo Oct 1, 2026
403ecdc
Support per-row path in named_credential_request_col (#158)
rkang-sf Oct 9, 2026
f9d157b
adding some lineage generating features
joroscoSF Oct 9, 2026
ded2ea2
remediate LLM findings
joroscoSF Oct 9, 2026
27dbe95
more bugfixes
joroscoSF Oct 9, 2026
0d765ab
Document currency code capability, in README and example
markdlv-sf Oct 12, 2026
f1dc099
Merge pull request #161 from forcedotcom/currency-code-docs
markdlv-sf Oct 12, 2026
eadd5db
addressing PR comments
joroscoSF Oct 12, 2026
856d863
more UDF tracer things
joroscoSF Oct 15, 2026
99c909f
few more PR comments, and updated docs
joroscoSF Oct 15, 2026
d94ad4b
Merge pull request #160 from forcedotcom/jo_lineage_gen
joroscoSF Oct 16, 2026
035387b
Add write_dmo_deltas to StreamingClient
andrewmiller-sf Oct 27, 2026
a0b2624
Skip symlink files in zip command
andrewmiller-sf Oct 28, 2026
453ee59
Merge pull request #164 from andrewmiller-sf/fix/deny-symlink
andrewmiller-sf Oct 29, 2026
f57814b
Merge branch 'main' into feat/write-dmo-delta-support
andrewmiller-sf Oct 29, 2026
48dbac8
Merge pull request #163 from forcedotcom/feat/write-dmo-delta-support
andrewmiller-sf Oct 30, 2026
215948c
Merge pull request #166 from forcedotcom/develop
atulikumwenayo Nov 4, 2026
b25a835
adding pkce
joroscoSF Nov 4, 2026
6e09a1e
Merge pull request #167 from forcedotcom/jo_pkce
joroscoSF Nov 5, 2026
773b816
Dynamic error message instead of static for function signature mistmatch
ritaagarwala-sf Nov 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 7.0.0

### Breaking Changes

- **`datacustomcode zip` and `datacustomcode deploy` no longer package symlinks.**

Symlinks found inside the payload directory are skipped instead of being followed. A symlinked file logs a `Skipping symlink file <path>` warning and is left out of `deployment.zip`.

**Why:** Following a symlink packaged the bytes of its target into the archive, even when the target was outside the payload (for example `payload/notes.txt -> ~/.ssh/id_rsa`).

**Migration:** Replace any symlink in the payload with a real copy of the file or directory it points to:

```bash
# Before
ln -s ../shared/helpers.py payload/helpers.py

# After
cp ../shared/helpers.py payload/helpers.py
```

### Added

- **`StreamingClient.write_dmo_deltas(name, dataframe)`** – start a streaming query that writes each micro-batch to the target DMO and return the `StreamingQuery` handle. It is the DMO counterpart to `write_dlo_deltas` and pairs with `read_dmo_deltas()`.

## 6.1.0

### Added
Expand Down
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ For a batch transform, use `Client`. You should only need the following methods:
* `find_file_path(file_name)` – Resolve a bundled file (placed under `payload/files/`) to a `pathlib.Path` that exists. Works the same locally and inside Data Cloud — see [Bundled file resolution](#bundled-file-resolution) below for the full lookup order. Raises `FileNotFoundError` if the file isn't found.
* `read_dlo(name)` – Read from a Data Lake Object by name
* `read_dmo(name)` – Read from a Data Model Object by name
* `write_to_dlo(name, spark_dataframe, write_mode)` – Write to a Data Model Object by name with a Spark dataframe
* `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
* `write_to_dlo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
* `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Model Object by name with a Spark dataframe

For a streaming (delta) transform, use `StreamingClient`, which exposes the streaming counterparts:
* `read_dlo_deltas()` – Read the streaming change feed (deltas) of a Data Lake Object as a streaming DataFrame.
* `read_dmo_deltas()` – Read the streaming change feed (deltas) of a Data Model Object as a streaming DataFrame.
* `write_dlo_deltas(name, spark_dataframe)` – Write a streaming DataFrame of deltas to a Data Lake Object; returns the started `StreamingQuery`
* `write_dmo_deltas(name, spark_dataframe)` – Write a streaming DataFrame of deltas to a Data Model Object; returns the started `StreamingQuery`

`find_file_path`, `llm_gateway_generate_text`, and `einstein_predict` are available on both clients.

Expand All @@ -176,6 +177,27 @@ client.write_to_dlo('output_DLO')
> [!WARNING]
> Currently we only support reading from DMOs and writing to DMOs or reading from DLOs and writing to DLOs, but they cannot mix.

### Writing Currency fields

A DLO or DMO with a Currency field has a system field, `cdp_sys_record_currency__c`, that holds each record's ISO currency code. Data Explorer UI uses it to display currency values, and shows a blank value if it's null (Query Editor still shows it).

Code Extensions don't set `cdp_sys_record_currency__c` for you, since only your script knows what currency its amounts are in. When writing to an object with Currency fields, set it yourself:

```python
from pyspark.sql.functions import lit

# Either source has Currency fields: keep its cdp_sys_record_currency__c in your output
df = source.select("id__c", "amount__c", "cdp_sys_record_currency__c")

# OR amounts are in a known currency
df = df.withColumn("cdp_sys_record_currency__c", lit("EUR"))
```

- Use an ISO code that exists in your org's configured currency rates.
- When aggregating, group by the currency code so amounts in different currencies aren't summed together.

See [`docs/examples/script/currency_totals`](docs/examples/script/currency_totals) for a complete example.

### Streaming (delta) transforms

Streaming BYOC transforms process a Data Lake Object's Change Data Feed continuously instead of reading a bounded snapshot. Use a `StreamingClient` and its `*_deltas` methods in place of the batch `Client` read/write methods:
Expand All @@ -201,6 +223,15 @@ query = client.write_dlo_deltas("Output__dll", transformed)
query.awaitTermination()
```

A streaming transform can also read and write Data Model Objects with `read_dmo_deltas()` and `write_dmo_deltas()`:

```python
deltas = client.read_dmo_deltas()
transformed = deltas.withColumn("description__c", upper(col("description__c")))
query = client.write_dmo_deltas("Output__dlm", transformed)
query.awaitTermination()
```

Notes:

- These methods only run inside the Data Cloud streaming (`DELTA_SYNC`) runtime. Locally (`datacustomcode run`) they raise `NotImplementedError`, since there is no change feed to stream.
Expand All @@ -224,6 +255,29 @@ If none of these exist, `find_file_path` raises `FileNotFoundError` with the lis

`$LIBRARY_PATH` is set automatically to the root of the package at runtime inside Data Cloud.

### Generating lineage

`generate_lineage` runs a script entry point locally and derives the field-level `dataLineage` section of `config.json` from the Spark plans of the DataFrames it writes:

```python
from datacustomcode.lineage import generate_lineage

result = generate_lineage("payload/entrypoint.py", sf_cli_org="my-org")
print(result.to_dict()["dataLineage"])
# [{"targetField": "Output__dll.name__c",
# "sourceFields": ["Input__dll.first__c", "Input__dll.last__c"]}, ...]
```

The entry point runs exactly as it would locally (same config, reader, and credentials), except that writes are traced and validated against the target DLO instead of being performed. It runs in a separate Python process, which inherits your working directory, environment, and `sys.path`; errors raised by the script are re-raised from `generate_lineage`. Reads use the reader's `default_row_limit` (1000 by default; set it in your `config.yaml`).

> **Review the output before you use it.** The generated lineage is a starting point for review, not a guarantee. It reflects only the code paths and data your local run exercised, and it can't see inside UDFs. Accurate and complete `dataLineage` in your package is your responsibility as the package author.

- A target field's sources are the fields its *value* is computed from. Fields that only decide which rows, groups or branch are used aren't sources, however the logic is written: filter conditions, join keys, `groupBy` keys, sort keys, window `partitionBy`/`orderBy` keys, `when()`/`if()` conditions, and aggregate `FILTER (WHERE …)` clauses. For example, `groupBy("region").agg(sum("amount"))` and `sum("amount").over(Window.partitionBy("region"))` both trace to `amount` only.
- Fields computed only from literals are listed in `noSources`. So are fields whose value doesn't come from any input field's value, such as `row_number()`, `rank()`, `count("*")`, or `sum(when(cond, 1))`.
- Fields that can't be traced are listed in `unresolved` with a reason and get no lineage. This covers data that didn't come from `read_dlo`/`read_dmo` (for example a `toPandas()` → `createDataFrame` round trip), `mapInPandas`, and subqueries.
- `pairCount` is the total number of (target, source) field pairs.
- Only batch script packages are supported.


## CLI

Expand Down Expand Up @@ -339,6 +393,8 @@ Options:
#### `datacustomcode zip`
Zip a transformation job in preparation to upload to Data Cloud. Make sure to change directory into your code package folder (e.g., `my_package`) before running this command.

Symlinks inside the payload folder are not followed or packaged. Each symlinked file that is skipped is reported with a warning, and symlinked directories are not included. `datacustomcode deploy` zips the same way.

Arguments:
- `PATH`: Path to the code directory i.e. the payload folder (default: "payload")

Expand Down
16 changes: 16 additions & 0 deletions docs/examples/script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Code Extension for Batch Transform — Examples

End-to-end Code Extension scripts. Each subdirectory is a self-contained deploy package (`payload/entrypoint.py` + `config.json` + `requirements.txt` + any bundled assets) that can run against a Data 360 org.

## Loading sample data

Many examples ship with a `sample_data/` folder containing CSV(s) needed to exercise it. To load one:

1. In Data 360, go to **Data Streams → New** and pick the **File Upload** connector.
2. Upload the CSV from `<example-name>/sample_data/`.
3. Map columns to the target object listed in the example's README, in your dataspace.
4. Run the ingest.

## Related

- Developer guide — [Data 360 Code Extension](https://developer.salesforce.com/docs/data/data-cloud-code-ext/guide/use-custom-code.html).
23 changes: 23 additions & 0 deletions docs/examples/script/account_rollup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Example: Iterative rollup of an account hierarchy

A Code Extension for Batch Transform that walks a self-referencing `Account__dll` and produces `Account_Rollup__dll` with each account's **total-tree ARR** — its own ARR plus every descendant account's ARR.

## What it demonstrates

- Imperative control flow (a `while` loop with `isEmpty()` convergence) around DataFrame ops.
- `.persist()` on the frontier + growing set, so each iteration doesn't re-derive earlier hops.
- Alias-based joins (`accounts.alias("a")` / `descendants.alias("d")`) — required whenever the same DataFrame appears on both sides.

## Prerequisites

An `Account__dll` DLO in the target dataspace with columns:

| Column | Type | Notes |
|-----------------|---------|---------------------------------------------|
| `id__c` | text | Primary key. |
| `parent_id__c` | text | Nullable. FK back to `Account__dll.id__c`. |
| `arr__c` | number | Annual recurring revenue for this account. |

Data should be loaded via `sample_data/account.csv`. See [loading sample data](../README.md#loading-sample-data).

Output DLO `Account_Rollup__dll` must also exist with `id__c` and `tree_arr__c` columns.
13 changes: 13 additions & 0 deletions docs/examples/script/account_rollup/payload/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"sdkVersion": "6.0.4",
"entryPoint": "entrypoint.py",
"dataspace": "default",
"permissions": {
"read": {
"dlo": ["Account__dll"]
},
"write": {
"dlo": ["Account_Rollup__dll"]
}
}
}
62 changes: 62 additions & 0 deletions docs/examples/script/account_rollup/payload/entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from pyspark.sql.functions import (
coalesce,
col,
lit,
sum as _sum,
)

from datacustomcode.client import Client
from datacustomcode.io.writer.base import WriteMode


def main():
client = Client()

accounts = (
client.read_dlo("Account__dll")
.select("id__c", "parent_id__c", "arr__c")
.persist()
)

descendants = accounts.select(
col("id__c").alias("root_id"),
col("id__c").alias("descendant_id"),
).persist()

frontier = descendants
while True:
next_hop = (
frontier.alias("f")
.join(
accounts.alias("a"),
col("a.parent_id__c") == col("f.descendant_id"),
"inner",
)
.select(
col("f.root_id").alias("root_id"),
col("a.id__c").alias("descendant_id"),
)
)
if next_hop.isEmpty():
break
descendants = descendants.union(next_hop).persist()
frontier = next_hop

totals = (
descendants.alias("d")
.join(
accounts.alias("a"),
col("d.descendant_id") == col("a.id__c"),
"left",
)
.select(col("d.root_id"), col("a.arr__c"))
.groupBy("root_id")
.agg(coalesce(_sum("arr__c"), lit(0)).alias("tree_arr__c"))
.withColumnRenamed("root_id", "id__c")
)

client.write_to_dlo("Account_Rollup__dll", totals, WriteMode.OVERWRITE)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions docs/examples/script/account_rollup/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Packages required for the custom code
9 changes: 9 additions & 0 deletions docs/examples/script/account_rollup/sample_data/account.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id,parent_id,arr
A1,,100000
A2,A1,50000
A3,A1,25000
A4,A2,10000
A5,A2,5000
A6,,200000
A7,A6,75000
A8,A7,15000
33 changes: 33 additions & 0 deletions docs/examples/script/currency_totals/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Example: Totals that keep their currency code

A Code Extension for Batch Transform that sums `Payment__dll` amounts per customer and writes them to `Customer_Payment_Totals__dll`, a DLO with a Currency field, setting the `cdp_sys_record_currency__c` system field so Data Explorer UI can display the totals.

## What it demonstrates

- **Carrying `cdp_sys_record_currency__c` through** from the source rows to the output. Code Extensions don't auto-populate `cdp_sys_record_currency__c`. And if it's null, Data Explorer shows the Currency value as blank. See [Writing Currency fields](../../../../README.md#writing-currency-fields).
- **Grouping by currency** so EUR and USD amounts are never summed together. Customer `C1` gets one EUR row and one USD row.
- If all amounts are in one known currency, one can also use `lit("EUR")` instead of copying a column.

## Prerequisites

Input DLO `Payment__dll` in the target dataspace:

| Column | Type | Notes |
|------------------------------|----------|------------------------------------------------------------------------|
| `id__c` | text | Primary key. |
| `customer_id__c` | text | |
| `amount__c` | Currency | |
| `cdp_sys_record_currency__c` | text | System field, added with the Currency field. From CSV `currency_code`. |

Data should be loaded via `sample_data/payment.csv`. See [loading sample data](../README.md#loading-sample-data).

Output DLO `Customer_Payment_Totals__dll` in the same dataspace:

| Column | Type | Notes |
|------------------------------|----------|--------------------------------------------------|
| `id__c` | text | Primary key (`<customer_id>_<currency>`). |
| `customer_id__c` | text | |
| `total_amount__c` | Currency | |
| `cdp_sys_record_currency__c` | text | System field, added with the Currency field. |

The ISO codes in `sample_data/payment.csv` must exist in your org's currency rates.
13 changes: 13 additions & 0 deletions docs/examples/script/currency_totals/payload/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"sdkVersion": "6.1.0",
"entryPoint": "entrypoint.py",
"dataspace": "default",
"permissions": {
"read": {
"dlo": ["Payment__dll"]
},
"write": {
"dlo": ["Customer_Payment_Totals__dll"]
}
}
}
35 changes: 35 additions & 0 deletions docs/examples/script/currency_totals/payload/entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pyspark.sql.functions import (
col,
concat_ws,
sum as _sum,
)

from datacustomcode.client import Client
from datacustomcode.io.writer.base import WriteMode


def main():
client = Client()

payments = client.read_dlo("Payment__dll").select(
"customer_id__c", "amount__c", "cdp_sys_record_currency__c"
)

totals = (
payments.groupBy("customer_id__c", "cdp_sys_record_currency__c")
.agg(_sum("amount__c").alias("total_amount__c"))
.select(
concat_ws(
"_", col("customer_id__c"), col("cdp_sys_record_currency__c")
).alias("id__c"),
col("customer_id__c"),
col("total_amount__c"),
col("cdp_sys_record_currency__c"),
)
)

client.write_to_dlo("Customer_Payment_Totals__dll", totals, WriteMode.OVERWRITE)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions docs/examples/script/currency_totals/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Packages required for the custom code
7 changes: 7 additions & 0 deletions docs/examples/script/currency_totals/sample_data/payment.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id,customer_id,amount,currency_code
P1,C1,100.00,EUR
P2,C1,250.50,EUR
P3,C1,40.00,USD
P4,C2,1200.00,USD
P5,C2,300.00,USD
P6,C3,75.25,GBP
33 changes: 33 additions & 0 deletions docs/examples/script/json_explode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Example: Flatten a batched event stream from a JSON-array column

A Code Extension for Batch Transform that reads a `User_Sessions__dll` DLO — one row per session, with each session's events packed into a JSON-array column — and writes one row per event into `User_Events__dll`. Parse-and-explode logic lives in a reusable module under `payload/py-files/`.

## What it demonstrates

- **`payload/py-files/`** — Split real logic into modules, unit-test them locally, reuse them across scripts.
- **`from_json` + `explode_outer`** to turn one row per session into one row per event, carrying the parent `session_id__c` and `user_id__c` through.
- **`to_timestamp()`** to parse ISO-8601 event timestamps into Spark `TimestampType`, which writes cleanly into Data 360's `DateTime` column.

## Prerequisites

Input DLO `User_Sessions__dll` in the target dataspace:

| Column | Type | Notes |
|------------------|------|---------------------------------------------|
| `session_id__c` | text | Primary key. |
| `user_id__c` | text | |
| `events__c` | text | JSON array of `{event_id, event_type, ts, path, value}`. |

Data should be loaded via `sample_data/user_sessions.csv`. See [loading sample data](../README.md#loading-sample-data).

Output DLO `User_Events__dll` in the same dataspace:

| Column | Type | Notes |
|-----------------|----------|---------------|
| `event_id__c` | text | Primary key. |
| `session_id__c` | text | |
| `user_id__c` | text | |
| `event_type__c` | text | |
| `event_ts__c` | DateTime | |
| `path__c` | text | |
| `value__c` | text | |
Loading
Loading