Skip to content

Commit 5837e4c

Browse files
committed
documentation fixes and write mode removal
1 parent b470208 commit 5837e4c

7 files changed

Lines changed: 25 additions & 44 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
New methods let an entry point process a Data Lake Object's Change Data Feed continuously instead of reading a bounded snapshot:
1010

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

1414
```python
1515
deltas = client.read_dlo_deltas("Input__dll")
1616
transformed = deltas.withColumn("description__c", upper(col("description__c")))
17-
query = client.write_dlo_deltas("Output__dll", transformed, WriteMode.APPEND)
17+
query = client.write_dlo_deltas("Output__dll", transformed)
1818
query.awaitTermination()
1919
```
2020

21-
Supported streaming write modes are `WriteMode.APPEND`, `WriteMode.OVERWRITE`, and `WriteMode.MERGE_UPSERT_DELETE`. These methods run only inside the Data Cloud streaming (`DELTA_SYNC`) runtime; locally they raise `NotImplementedError`. See the `examples/streaming_deltas/entrypoint.py` example and the "Streaming (delta) transforms" section of the README.
21+
These methods run only inside the Data Cloud streaming (`DELTA_SYNC`) runtime; locally they raise `NotImplementedError`. See the `examples/streaming_deltas/entrypoint.py` example and the "Streaming (delta) transforms" section of the README.
2222

2323
## 6.0.0
2424

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ You should only need the following methods:
157157
For streaming (delta) transforms, the streaming counterparts are:
158158
* `read_dlo_deltas(name)` – Read the streaming change feed (deltas) of a Data Lake Object as a streaming DataFrame
159159
* `read_dmo_deltas(name)` – Read the streaming change feed (deltas) of a Data Model Object as a streaming DataFrame
160-
* `write_dlo_deltas(name, spark_dataframe, write_mode)` – Write a streaming DataFrame of deltas to a Data Lake Object; returns the started `StreamingQuery`
160+
* `write_dlo_deltas(name, spark_dataframe)` – Write a streaming DataFrame of deltas to a Data Lake Object; returns the started `StreamingQuery`
161161

162162
For example:
163163
```python
@@ -182,28 +182,24 @@ Streaming BYOC transforms process a Data Lake Object's Change Data Feed continuo
182182
from pyspark.sql.functions import col, upper
183183

184184
from datacustomcode import Client
185-
from datacustomcode.io.writer.base import WriteMode
186185

187186
client = Client()
188187

189188
# read_dlo_deltas returns a *streaming* DataFrame over the change feed.
190189
deltas = client.read_dlo_deltas("Input__dll")
191190

192-
# Ordinary PySpark transform. Keep the change-feed metadata columns
193-
# (those starting with "_") — the streaming sink needs them to apply
194-
# inserts, updates, and deletes to the target DLO.
191+
# Ordinary PySpark transform.
195192
transformed = deltas.withColumn("description__c", upper(col("description__c")))
196193

197194
# write_dlo_deltas starts a streaming query and returns the StreamingQuery.
198-
# The runtime owns the trigger and checkpoint location; you choose only the
199-
# target table and write mode.
200-
query = client.write_dlo_deltas("Output__dll", transformed, WriteMode.APPEND)
195+
# The runtime owns the trigger and checkpoint location; you
196+
# choose only the target table.
197+
query = client.write_dlo_deltas("Output__dll", transformed)
201198
query.awaitTermination()
202199
```
203200

204201
Notes:
205202

206-
- Supported streaming write modes are `WriteMode.APPEND`, `WriteMode.OVERWRITE`, and `WriteMode.MERGE_UPSERT_DELETE`.
207203
- 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.
208204
- A complete runnable entry point is provided in [`examples/streaming_deltas/entrypoint.py`](src/datacustomcode/templates/script/examples/streaming_deltas/entrypoint.py).
209205

src/datacustomcode/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def write_to_dmo(
396396
return self._writer.write_to_dmo(name, dataframe, write_mode, **kwargs) # type: ignore[no-any-return]
397397

398398
def write_dlo_deltas(
399-
self, name: str, dataframe: PySparkDataFrame, write_mode: WriteMode, **kwargs
399+
self, name: str, dataframe: PySparkDataFrame, **kwargs
400400
) -> StreamingQuery:
401401
"""Write a streaming DataFrame of deltas to a DLO in Data Cloud.
402402
@@ -409,15 +409,12 @@ def write_dlo_deltas(
409409
Args:
410410
name: The name of the DLO to write to.
411411
dataframe: The streaming PySpark DataFrame to write.
412-
write_mode: The write mode to use. Supported streaming modes are
413-
``WriteMode.APPEND``, ``WriteMode.OVERWRITE``, and
414-
``WriteMode.MERGE_UPSERT_DELETE``.
415412
416413
Returns:
417414
The started ``StreamingQuery``.
418415
"""
419416
self._validate_data_layer_history_does_not_contain(DataCloudObjectType.DMO)
420-
return self._writer.write_dlo_deltas(name, dataframe, write_mode, **kwargs) # type: ignore[no-any-return]
417+
return self._writer.write_dlo_deltas(name, dataframe, **kwargs) # type: ignore[no-any-return]
421418

422419
def find_file_path(self, file_name: str) -> Path:
423420
"""Resolve a bundled file shipped in the package to an absolute path.

src/datacustomcode/io/writer/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,22 @@ def write_to_dmo(
6060
) -> None: ...
6161

6262
def write_dlo_deltas(
63-
self, name: str, dataframe: PySparkDataFrame, write_mode: WriteMode
63+
self, name: str, dataframe: PySparkDataFrame
6464
) -> StreamingQuery:
6565
"""Write a streaming DataFrame of deltas to a Data Lake Object.
6666
6767
Streaming counterpart to :meth:`write_to_dlo`. Starts a streaming query
6868
that writes each micro-batch to the target DLO via the Data Cloud
6969
streaming sink and returns the resulting ``StreamingQuery`` handle. The
7070
runtime owns the trigger and checkpoint location; callers pass only the
71-
table name and write mode. Concrete streaming behavior is provided by
72-
the deployed Data Cloud runtime; the base implementation raises
71+
table name. Concrete streaming behavior is provided by the deployed
72+
Data Cloud runtime; the base implementation raises
7373
:class:`NotImplementedError`.
7474
7575
Args:
7676
name: Target Data Lake Object name.
7777
dataframe: Streaming PySpark DataFrame produced from a
7878
``read_dlo_deltas`` / ``read_dmo_deltas`` source.
79-
write_mode: Write mode for the streaming sink. Supported modes are
80-
``WriteMode.APPEND``, ``WriteMode.OVERWRITE``, and
81-
``WriteMode.MERGE_UPSERT_DELETE``.
8279
8380
Returns:
8481
The started ``StreamingQuery``; the caller drives its lifecycle

src/datacustomcode/templates/script/examples/streaming_deltas/entrypoint.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* ``client.read_dlo_deltas(name)`` returns a *streaming* DataFrame over the
88
Change Data Feed of the source DLO. Each row carries the source columns plus
99
change-feed metadata columns (``_record_type``, ``_commit_*``).
10-
* ``client.write_dlo_deltas(name, df, write_mode)`` starts a streaming query
11-
that writes each micro-batch to the target DLO and returns the
12-
``StreamingQuery`` handle. The runtime owns the trigger and checkpoint
13-
location — the caller only chooses the table and write mode.
10+
* ``client.write_dlo_deltas(name, df)`` starts a streaming query that writes
11+
each micro-batch to the target DLO and returns the ``StreamingQuery`` handle.
12+
The runtime owns the trigger, and checkpoint location — the caller only
13+
chooses the table.
1414
1515
The transform in between is ordinary PySpark. Because the source is a change
1616
feed, keep the metadata columns on the DataFrame you hand to
@@ -24,7 +24,6 @@
2424
from pyspark.sql.functions import col, upper
2525

2626
from datacustomcode.client import Client
27-
from datacustomcode.io.writer.base import WriteMode
2827

2928

3029
def main():
@@ -33,16 +32,12 @@ def main():
3332
# Streaming DataFrame over the source DLO's change feed.
3433
deltas = client.read_dlo_deltas("Account_std__dll")
3534

36-
# Ordinary PySpark transform. Note we do NOT drop the change-feed metadata
37-
# columns (those starting with "_") — the streaming sink needs them to apply
38-
# inserts, updates, and deletes to the target DLO.
35+
# Ordinary PySpark transform.
3936
transformed = deltas.withColumn("description__c", upper(col("description__c")))
4037

4138
# Start the streaming write. write_dlo_deltas returns the StreamingQuery;
4239
# the trigger and checkpoint location are provided by the runtime.
43-
query = client.write_dlo_deltas(
44-
"Account_std_copy__dll", transformed, WriteMode.APPEND
45-
)
40+
query = client.write_dlo_deltas("Account_std_copy__dll", transformed)
4641

4742
# Drive the query's lifecycle. In the streaming runtime this blocks until
4843
# the job is stopped by the platform.

tests/io/writer/test_print.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_write_to_dmo(self, print_writer, mock_dataframe):
6262
def test_write_dlo_deltas_not_supported_locally(self, print_writer, mock_dataframe):
6363
"""Streaming delta writes are not supported by the local writer."""
6464
with pytest.raises(NotImplementedError) as exc_info:
65-
print_writer.write_dlo_deltas("test_dll", mock_dataframe, WriteMode.APPEND)
65+
print_writer.write_dlo_deltas("test_dll", mock_dataframe)
6666
assert "write_dlo_deltas" in str(exc_info.value)
6767

6868
def test_config_name(self):

tests/test_client.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,10 @@ def test_write_dlo_deltas(self, reset_client, mock_spark):
229229
client = Client(reader=reader, writer=writer)
230230
client._record_dlo_access("some_dlo")
231231

232-
result = client.write_dlo_deltas(
233-
"test_dlo", mock_df, WriteMode.APPEND, extra_param=True
234-
)
232+
result = client.write_dlo_deltas("test_dlo", mock_df, extra_param=True)
235233

236234
writer.write_dlo_deltas.assert_called_once_with(
237-
"test_dlo", mock_df, WriteMode.APPEND, extra_param=True
235+
"test_dlo", mock_df, extra_param=True
238236
)
239237
assert result is mock_query
240238

@@ -250,7 +248,7 @@ def test_write_dlo_deltas_after_dmo_read_raises_exception(
250248
client._record_dmo_access("test_dmo")
251249

252250
with pytest.raises(DataCloudAccessLayerException) as exc_info:
253-
client.write_dlo_deltas("test_dlo", mock_df, WriteMode.APPEND)
251+
client.write_dlo_deltas("test_dlo", mock_df)
254252

255253
assert "test_dmo" in str(exc_info.value)
256254
writer.write_dlo_deltas.assert_not_called()
@@ -265,12 +263,10 @@ def test_streaming_read_write_flow(self, reset_client, mock_spark):
265263
client = Client(reader=reader, writer=writer)
266264

267265
df = client.read_dlo_deltas("source_dll")
268-
client.write_dlo_deltas("target_dll", df, WriteMode.MERGE_UPSERT_DELETE)
266+
client.write_dlo_deltas("target_dll", df)
269267

270268
reader.read_dlo_deltas.assert_called_once_with("source_dll")
271-
writer.write_dlo_deltas.assert_called_once_with(
272-
"target_dll", stream_df, WriteMode.MERGE_UPSERT_DELETE
273-
)
269+
writer.write_dlo_deltas.assert_called_once_with("target_dll", stream_df)
274270
assert "source_dll" in client._data_layer_history[DataCloudObjectType.DLO]
275271

276272
def test_mixed_dlo_dmo_raises_exception(self, reset_client, mock_spark):

0 commit comments

Comments
 (0)