Created
July 24, 2017 16:49
-
-
Save ruivieira/e7abed1feb54f5ee855ac8dce3db0403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Works | |
| class Foo: | |
| def __init__(self, sc, df): | |
| self.sc = sc # a spark context | |
| self.df = df # a spark dataframe | |
| f = udf(lambda x: Foo.do_something(x), ArrayType(StringType())) | |
| self.new_df = self.df.withColum('bar', f(self.df.foo)) | |
| @staticmethod | |
| def do_something(data): | |
| return data.split('.') | |
| # Doesn't work | |
| from abc import ABCMeta, abstractmethod | |
| class Abstract: | |
| __metaclass__ = ABCMeta | |
| def __init__(self, sc, df): | |
| self.sc = sc | |
| self.df = df | |
| @abstractmethod | |
| def process(self, data): | |
| pass | |
| class Foo(Abstract): | |
| def __init__(self, sc, df): | |
| Abstract.__init__(self, sc, df) | |
| self.new_df = self.process(self.df) | |
| def process(self, data): | |
| f = udf(lambda x: Foo.do_something(x), ArrayType(StringType())) | |
| return data.withColum('bar', f(data.foo)) | |
| @staticmethod | |
| def do_something(data): | |
| return data.split('.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment