Skip to content

Commit

Permalink
table: materialize_to_file return file (move-coop#449)
Browse files Browse the repository at this point in the history
This commit updates the `Table.materialize_to_file` method to
return the path to the temp file that contains the data of the
Parsons `Table`. This allows users to track and clean up the
temp files as needed.
  • Loading branch information
Eliot Stone authored Oct 20, 2020
1 parent 0142646 commit 147adf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions parsons/etl/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ def materialize_to_file(self, file_path=None):
file_path: str
The path to the file to materialize the table to; if not specified, a temp file
will be created.
`Returns:`
str
Path to the temp file that now contains the table
"""

# Load the data in batches, and "pickle" the rows to a temp file.
Expand All @@ -212,6 +215,8 @@ def materialize_to_file(self, file_path=None):
# Load a Table from the file
self.table = petl.frompickle(file_path)

return file_path

def is_valid_table(self):
"""
Performs some simple checks on a Table. Specifically, verifies that we have a valid petl
Expand Down
2 changes: 1 addition & 1 deletion test/test_etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_materialize(self):
def test_materialize_to_file(self):
# Simple test that materializing doesn't change the table
tbl_materialized = Table(self.lst_dicts)
tbl_materialized.materialize_to_file()
_ = tbl_materialized.materialize_to_file()

assert_matching_tables(self.tbl, tbl_materialized)

Expand Down

0 comments on commit 147adf4

Please sign in to comment.