I'm new to OOP, but experienced in SQL. I'm writing a Luigi ETL task to generate reports.
I have a base class called Report, and 3 subclasses Report_Daily, Report_Weekly & Report_Monthly, which dynamically set the base class' SQL query's GROUP BY, so that the appropriate reports can be generated
#reports.py
class Report:
report_sql = {'daily':'day', 'weekly':'firstdayofweek(day)', 'monthly':'firstdayofmonth(day)'}
@property
def report_type(self):
return '' # To be instantiated by subclass
sql = 'select '+report_sql[report_type]+' count(*) from employees group by '+report_sql[report_type]
def run(self):
#code that runs sql query
class ReportDaily(Report):
report_type = 'Daily'
class ReportWeekly(Report):
report_type = 'Weekly'
class ReportMonthly(Report):
report_type = 'Monthly'
These 3 subclasses are then scheduled via Luigi & Chronos like
luigi --module etl.reports ReportDaily
luigi --module etl.reports ReportWeekly
luigi --module etl.reports ReportMonthly
But I'm getting 'Cannot concatenate string and property' error.
I tried setting report_type as a luigi parameter, but get similar error.
What is the proper design pattern to achieve this ?