Skip to content

Commit 5d340e4

Browse files
shannywuvijaykiran
andauthored
Add scan time support in soda-spark (#111)
* Add scan time support in soda-spark Co-authored-by: Vijay Kiran <[email protected]>
1 parent 45be6f9 commit 5d340e4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- Add `time` support to `execute`
2+
13
## [0.3.1] - 2021-12-27
24

35
- Add example to README about returning spark data frames as scan result

src/sodaspark/scan.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def create_scan(
254254
variables: dict | None = None,
255255
warehouse_name: str = "sodaspark",
256256
soda_server_client: SodaServerClient | None = None,
257+
time: str | None = None,
257258
) -> Scan:
258259
"""
259260
Create a scan object.
@@ -265,19 +266,25 @@ def create_scan(
265266
variables: variables to be substituted in scan yml
266267
soda_server_client : Optional[SodaServerClient] (default : None)
267268
A soda server client.
269+
time: Optional[str] (default: None)
270+
Timestamp date in ISO8601 format. If None, use datatime.now() in ISO8601 format.
268271
269272
Returns
270273
-------
271274
out : Scan
272275
The scan.
273276
"""
277+
278+
time = time or dt.datetime.now(tz=dt.timezone.utc).isoformat(
279+
timespec="seconds"
280+
)
274281
warehouse = create_warehouse(warehouse_name)
275282
scan = Scan(
276283
warehouse=warehouse,
277284
scan_yml=scan_yml,
278285
soda_server_client=soda_server_client,
279286
variables=variables,
280-
time=dt.datetime.now(tz=dt.timezone.utc).isoformat(timespec="seconds"),
287+
time=time,
281288
)
282289
return scan
283290

@@ -422,6 +429,7 @@ def execute(
422429
warehouse_name: str = "sodaspark",
423430
soda_server_client: SodaServerClient | None = None,
424431
as_frames: bool | None = False,
432+
time: str | None = None,
425433
) -> ScanResult:
426434
"""
427435
Execute a scan on a data frame.
@@ -438,6 +446,8 @@ def execute(
438446
A soda server client.
439447
as_frames : bool (default : False)
440448
Flag to return results in Dataframe
449+
time: str (default : None)
450+
Timestamp date in ISO8601 format at the start of a scan
441451
442452
Returns
443453
-------
@@ -451,6 +461,7 @@ def execute(
451461
scan_yml,
452462
variables=variables,
453463
soda_server_client=soda_server_client,
464+
time=time,
454465
warehouse_name=warehouse_name,
455466
)
456467
scan.execute()

0 commit comments

Comments
 (0)