I'm currently in my first job that involves Spark. Code is written in Java.
My current task is to continue what was left off by a previous dev.
The task in itself isn't very hard but context:
- There are 10+ datasets that come from different sources (files, company's endpoint, tables, etc...)
- These datasets have to be joined at the end into a unique dataset.
- There are hundreds of "Rules" on those datasets.
- Some of these rules can only be applied by specific joins from DsA + DsB for example.
The previous Dev wrote the Rules, the joins in only one specific class (which are getting really big, like thousand liners) with a huge main class too.
I can easily follow the same process and make those classes even bigger but I find it extremely irritating to read and maintain for the future.
For now, I restructured the project in packages like:
- read
- preprocess
- calculations
- write
But I also doubt my own methodology and I have no Senior to rely on in the company.
My classes are just utility classes with many (but organized ?) static methods that contain the Rules and I call from a helper class to chain all the processes. I feel like it is kind off "dirty" code but I'm unable to come up with any other solution
I do have a few classes in which I inject a dataset as a parameter so that this dataset serves as a reference in all the methods inside the class. But all the methods are really "specific" for example:
public class CurrencyService { private final Dataset<Row> currencyReference; // constructor public Dataset<Row> applyCurrencyConversion(Dataset<Row> targetDataset){ // target joins reference and apply conversion } private Column conversion(Column targetColumn){ // conversion rules } }How should I handle Join Keys? Every dataset has a different name for its ID. I was thinking about forcing a key String from a constant for each ID at preprocessing step. Because otherwise, I have to join every dataset manually by knowing their Column's name each time. With preprocessed join keys, I may do something like
dsA.join(dsB, Sequence of (joinKeys)).
In the end, I feel like I'm spaghettying the code even more while the previous "single class" style was easier to understand but not to maintain...
I have a background in POO, so am I taking this project too Object-Oriented?
