-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtfx_task.py
More file actions
69 lines (54 loc) · 2.07 KB
/
tfx_task.py
File metadata and controls
69 lines (54 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
#
# Copyright 2017-2019 Spotify AB.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from abc import abstractmethod
from luigi.contrib.beam_dataflow import BeamDataflowJobTask
class TFXBaseTask(BeamDataflowJobTask):
python_script = None # type: str
def __init__(self, *args, **kwargs):
super(TFXBaseTask, self).__init__(*args, **kwargs)
def dataflow_executable(self):
""" Must be overwritten from the BeamDataflowTask """
return ["python", self.python_script]
def tfx_args(self):
""" Extra arguments that will be passed to your tfx dataflow job.
Example:
return ["--schema_file=gs://uri/to/schema_file"]
Note that:
* You "set" args by overriding this method in your tfx subclass.
* This function should return an iterable of strings.
"""
return []
def _mk_cmd_line(self):
cmd_line = super(TFXBaseTask, self)._mk_cmd_line()
cmd_line.extend(self.tfx_args())
return cmd_line
class TFTransformTask(TFXBaseTask):
# Required dataflow arg
def __init__(self, *args, **kwargs):
super(TFTransformTask, self).__init__(*args, **kwargs)
def tfx_args(self):
return [
"--schema_file=%s" % self.get_schema_file()
]
@abstractmethod
def get_schema_file(self): # type: () -> str
"""
Should return fully qualified path to the stats file generated by TFDV.
This has to be defined as a method because the stats file is based on the input dataset
"""
pass