Skip to content

Commit bee582b

Browse files
authored
Merge pull request #35 from forcedotcom/p.fix.allow_multiple_writes
Allow multiple writes
2 parents 9cba6e6 + ac7cefb commit bee582b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/datacustomcode/scan.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ class DataAccessLayerCalls(pydantic.BaseModel):
5454
def validate_access_layer(self) -> DataAccessLayerCalls:
5555
if self.read_dlo and self.read_dmo:
5656
raise ValueError("Cannot read from DLO and DMO in the same file.")
57-
if len(self.write_to_dlo) > 1 or len(self.write_to_dmo) > 1:
58-
raise ValueError(
59-
"Cannot write to more than one DLO or DMO in the same file."
60-
)
6157
if not self.read_dlo and not self.read_dmo:
6258
raise ValueError("Must read from at least one DLO or DMO.")
6359
if self.read_dlo and self.write_to_dmo:

tests/test_scan.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_read_dmo_write_dlo_throws_error(self):
247247
finally:
248248
os.unlink(temp_path)
249249

250-
def test_invalid_multiple_writes(self):
250+
def test_multiple_writes(self):
251251
"""Test scanning a file with multiple write operations."""
252252
content = textwrap.dedent(
253253
"""
@@ -258,15 +258,25 @@ def test_invalid_multiple_writes(self):
258258
# Read from DLO
259259
df = client.read_dlo("input_dlo")
260260
261-
# Write to multiple DLOs - invalid
262-
client.write_to_dlo("output_dlo_1", df, "overwrite")
263-
client.write_to_dlo("output_dlo_2", df, "overwrite")
261+
# Transform data for different outputs
262+
df_filtered = df.filter(df.col > 10)
263+
df_aggregated = df.groupBy("category").agg({"value": "sum"})
264+
265+
# Write to multiple DLOs
266+
client.write_to_dlo("output_filtered", df_filtered, "overwrite")
267+
client.write_to_dlo("output_aggregated", df_aggregated, "overwrite")
264268
"""
265269
)
266270
temp_path = create_test_script(content)
267271
try:
268-
with pytest.raises(ValueError, match="Cannot write to more than one DLO"):
269-
scan_file(temp_path)
272+
result = scan_file(temp_path)
273+
assert "input_dlo" in result.read_dlo
274+
assert "output_filtered" in result.write_to_dlo
275+
assert "output_aggregated" in result.write_to_dlo
276+
assert len(result.read_dlo) == 1
277+
assert len(result.write_to_dlo) == 2
278+
assert len(result.read_dmo) == 0
279+
assert len(result.write_to_dmo) == 0
270280
finally:
271281
os.unlink(temp_path)
272282

0 commit comments

Comments
 (0)