Extending PySpark functionality

I created a class to extend DataFrame functionality.
I would say like a wrapper of the dataframe.
This may bring something up, but allow me to get to it.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class TurboDF(DataFrame):
def __init__(self, *args):
df = self._init_args(*args)
DataFrame.__init__(self, df._jdf, df.sql_ctx)
self._df = df
self._turbo_df()
def _init_args(self, *args):
if isinstance(args[0], DataFrame):
return args[0]
(assert isinstance(args[0], SparkSession),
"First argument must be DataFrame or SparkSession")
a_spark = args[0]
if Δ.isDeltaTable(a_spark, args[1]):
return a_spark.read.format('delta').load(args[1])
# and other ways to read tables
</code>
<code>class TurboDF(DataFrame): def __init__(self, *args): df = self._init_args(*args) DataFrame.__init__(self, df._jdf, df.sql_ctx) self._df = df self._turbo_df() def _init_args(self, *args): if isinstance(args[0], DataFrame): return args[0] (assert isinstance(args[0], SparkSession), "First argument must be DataFrame or SparkSession") a_spark = args[0] if Δ.isDeltaTable(a_spark, args[1]): return a_spark.read.format('delta').load(args[1]) # and other ways to read tables </code>
class TurboDF(DataFrame): 
  def __init__(self, *args): 
    df = self._init_args(*args)
    DataFrame.__init__(self, df._jdf, df.sql_ctx)
    self._df = df
    self._turbo_df()    

  def _init_args(self, *args): 
    if isinstance(args[0], DataFrame): 
      return args[0]
    (assert isinstance(args[0], SparkSession), 
      "First argument must be DataFrame or SparkSession")
    a_spark = args[0]
    if Δ.isDeltaTable(a_spark, args[1]): 
      return a_spark.read.format('delta').load(args[1])
    # and other ways to read tables

There are two issues here:

  1. With newer pyspark versions, some of the elements that I used are no longer valid.
    So I would like to correct them.
  2. The second issue may be more phylosophical: since I may be “reinventing the wheel”, and therefore I could add the functionality in some other way.

Elements that have changed with newer pyspark versions:

  • df.sql_ctx changed to df.sparkSession (or perhaps it was the other way around).
    This was the first change, and I just caught it with a try...except block.
  • isinstance(args[0], SparkSession) changed because I used to import it at spark.sql.SparkSession and then at spark.sql.connection.session.SparkSession.
  • df._jdf this is the newest error that mentions something like “the attribute is not supported in Spark Connect.”

And as they say, third time is the chime. So most likely I don’t need to be maintaing this extra functionality and instead I’d be better on moving to the second issue.

What is the way to go about this extra functionality?

Working on this functionality had gotten me to understanding a few things about Spark, and it feels like I may be able to collaborate better with the Spark project, instead of creating my own tiny project.

Let me take a step back and mention what is the extra functionality that I added to my TurboDF:

  • Build DataFrame from any of (pandasDF, deltaTable path, deltaTable in catalog).
  • Allow select_turbo to read list of columns, or dictionary of {name: column}.
  • Allow filter_turbo to read list of filters, and optimize them with and instead of one by one.
  • Allow with_column_turbo to call a dictionary of {name: column} or list of dictionaries as before where the columns hold some dependencies.
  • Allow with_column_renamed_turbo to rename several columns at once.
  • Allow join_turbo to use suffixes for the new common columns, and deal with common non-join ones.
  • Allow save_as_file (in Databricks) for when the DataFrame is not very long. Obviously a functionality issue.
  • Similar functionality in GroupedData with its corresponding TurboGrouped.

In addition, after reading the newer documentation I did find that some of these implementations had already been carried out natively. And this is why I’m reaching out to the community, in order to be involved better.

Thank you for your support.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật