Skip to content

Commit 06dae52

Browse files
authored
Include file_dependencies as variable for Copy Commands. (#17)
1 parent c1ad2ba commit 06dae52

File tree

1 file changed

+25
-1
lines changed
  • data_integration/commands

1 file changed

+25
-1
lines changed

data_integration/commands/sql.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,16 @@ class Copy(_SQLCommand):
140140

141141
def __init__(self, source_db_alias: str, target_table: str, target_db_alias: str = None,
142142
sql_statement: str = None, sql_file_name: Union[Callable, str] = None, replace: {str: str} = None,
143-
timezone: str = None, csv_format: bool = None, delimiter_char: str = None) -> None:
143+
timezone: str = None, csv_format: bool = None, delimiter_char: str = None,
144+
file_dependencies = None) -> None:
144145
_SQLCommand.__init__(self, sql_statement, sql_file_name, replace)
145146
self.source_db_alias = source_db_alias
146147
self.target_table = target_table
147148
self._target_db_alias = target_db_alias
148149
self.timezone = timezone
149150
self.csv_format = csv_format
150151
self.delimiter_char = delimiter_char
152+
self.file_dependencies = file_dependencies or []
151153

152154
@property
153155
def target_db_alias(self):
@@ -156,6 +158,28 @@ def target_db_alias(self):
156158
def file_path(self) -> pathlib.Path:
157159
return self.parent.parent.base_path() / self.file_name
158160

161+
def run(self) -> bool:
162+
if self.sql_file_name:
163+
logger.log(self.sql_file_name, logger.Format.ITALICS)
164+
165+
dependency_type = 'Copy ' + (self.sql_file_name or self.sql_statement)
166+
167+
if self.file_dependencies:
168+
assert (self.parent)
169+
pipeline_base_path = self.parent.parent.base_path()
170+
if not file_dependencies.is_modified(self.node_path(), dependency_type,
171+
pipeline_base_path,
172+
self.file_dependencies):
173+
logger.log('no changes')
174+
return True
175+
176+
if not super().run():
177+
return False
178+
179+
if self.file_dependencies:
180+
file_dependencies.update(self.node_path(), dependency_type, pipeline_base_path, self.file_dependencies)
181+
return True
182+
159183
def shell_command(self):
160184
return _SQLCommand.shell_command(self) \
161185
+ ' | ' + mara_db.shell.copy_command(self.source_db_alias, self.target_db_alias, self.target_table,

0 commit comments

Comments
 (0)