Skip to content

Commit 1022658

Browse files
authored
Merge pull request #124 from forcedotcom/remove-streaming-delta-source-name
rely on config for name source
2 parents 6df6d83 + 2cb85d3 commit 1022658

11 files changed

Lines changed: 569 additions & 255 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

55
### Added
66

7-
- **Streaming (delta) read/write methods on `Client` for BYOC streaming transforms.**
7+
- **`StreamingClient` for BYOC streaming (delta) transforms.**
88

9-
New methods let an entry point process a Data Lake Object's Change Data Feed continuously instead of reading a bounded snapshot:
9+
A dedicated `StreamingClient` (alongside the batch `Client`) lets an entry point process a Data Lake Object's Change Data Feed continuously instead of reading a bounded snapshot.
1010

11-
- `read_dlo_deltas(name)` / `read_dmo_deltas(name)` – return a streaming DataFrame over the object's change feed.
11+
- `read_dlo_deltas()` / `read_dmo_deltas()` – return a streaming DataFrame over the object's change feed.
1212
- `write_dlo_deltas(name, dataframe)` – start a streaming query that writes each micro-batch to the target DLO and return the `StreamingQuery` handle.
1313

14+
The shared functions (`find_file_path`, `llm_gateway_generate_text`, `einstein_predict`) are available on both `Client` and `StreamingClient`.
15+
1416
```python
15-
deltas = client.read_dlo_deltas("Input__dll")
17+
from datacustomcode import StreamingClient
18+
19+
client = StreamingClient()
20+
deltas = client.read_dlo_deltas()
1621
transformed = deltas.withColumn("description__c", upper(col("description__c")))
1722
query = client.write_dlo_deltas("Output__dll", transformed)
1823
query.awaitTermination()

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,22 @@ Your Python dependencies can be packaged as .py files, .zip archives (containing
145145

146146
## API
147147

148-
Your entry point script will define logic using the `Client` object which wraps data access layers.
148+
Your entry point script will define logic using the `Client` object (for batch transforms) or the `StreamingClient` object (for streaming delta transforms), which wrap the data access layers. Both are singletons; a single transform should use one or the other, not both.
149149

150-
You should only need the following methods:
150+
For a batch transform, use `Client`. You should only need the following methods:
151151
* `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.
152152
* `read_dlo(name)` – Read from a Data Lake Object by name
153153
* `read_dmo(name)` – Read from a Data Model Object by name
154154
* `write_to_dlo(name, spark_dataframe, write_mode)` – Write to a Data Model Object by name with a Spark dataframe
155155
* `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
156156

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

162+
`find_file_path`, `llm_gateway_generate_text`, and `einstein_predict` are available on both clients.
163+
162164
For example:
163165
```python
164166
from datacustomcode import Client
@@ -176,17 +178,18 @@ client.write_to_dlo('output_DLO')
176178
177179
### Streaming (delta) transforms
178180

179-
Streaming BYOC transforms process a Data Lake Object's Change Data Feed continuously instead of reading a bounded snapshot. Use the `*_deltas` methods in place of the batch read/write methods:
181+
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:
180182

181183
```python
182184
from pyspark.sql.functions import col, upper
183185

184-
from datacustomcode import Client
186+
from datacustomcode import StreamingClient
185187

186-
client = Client()
188+
client = StreamingClient()
187189

188190
# read_dlo_deltas returns a *streaming* DataFrame over the change feed.
189-
deltas = client.read_dlo_deltas("Input__dll")
191+
# The runtime resolves the single streaming source, so no name is passed.
192+
deltas = client.read_dlo_deltas()
190193

191194
# Ordinary PySpark transform.
192195
transformed = deltas.withColumn("description__c", upper(col("description__c")))

src/datacustomcode/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"QueryAPIDataCloudReader",
2424
"SparkEinsteinPredictions",
2525
"SparkLLMGateway",
26+
"StreamingClient",
2627
"einstein_predict_col",
2728
"llm_gateway_generate_text_col",
2829
]
@@ -34,6 +35,10 @@ def __getattr__(name: str):
3435
from datacustomcode.client import Client
3536

3637
return Client
38+
elif name == "StreamingClient":
39+
from datacustomcode.client import StreamingClient
40+
41+
return StreamingClient
3742
elif name == "AuthType":
3843
from datacustomcode.credentials import AuthType
3944

0 commit comments

Comments
 (0)