Applied Refactoring techniques to improve code quality #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please review my pull request and if you find it useful then please accept it. it is very important for me if you could do it on or before 27 March, 2022. Thanks in advance.
Description:
Location: src/main/java/simpledb/algorithm/Join
• File: src/main/java/simpledb/algorithm/Join/SortMergeJoin.java
• Class: SortMergeJoin.java
• Method: mergeJoin
To reduce duplicate code and cyclomatic complexity: Extracted code block from mergeJoin() and created two new methods
a)joinTuples() which joins the tuple based on predicate operator(LESS_THAN_OR_EQ or GREATER_THAN_OR_EQ) passed.
b)equalsPredicate.
Refactoring name: RENAME VARIABLE
Location: src/main/java/simpledb/index
• File: src/main/java/simpledb/index/BTreeFile.java
• Class: BTreeFile.java
Class level field is renamed from f to file for better understanding and readability.
Refactoring name: PULL UP VARIABLE
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/Operator.java
• Class: Operator.java
• Variable: TupleDesc td;
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/Aggregate.java
• Class: Aggregate.java
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/Delete.java
• Class: Delete.java
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/Filter.java
• Class: Filter.java
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/HashEquiJoin.java
• Class: HashEquiJoin.java
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/Insert.java
• Class: Insert.java
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/Join.java
• Class: Join.java
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/OrderBy.java
• Class: OrderBy.java
Location: src/main/java/simpledb/execution
• File: src/main/java/simpledb/execution/Project.java
• Class: Project.java
To remove duplication of code for the variable of type TupleDesc in 8 classes,Pull up variable refactoring is performed and variable is pulled from 8 classes and is kept in the parent class Operator.
4 . Refactoring name: PUSH DOWN METHOD
Location: src/main/java/simpledb/algorithm/Join
• File: src/main/java/simpledb/algorithm/Join/JoinStrategy.java
• Class: JoinStrategy.java
• Method: close()
Location: src/main/java/simpledb/algorithm/Join
• File: src/main/java/simpledb/algorithm/Join/HashJoin.java
• Class: HashJoin.java
• Method: close()
Location: src/main/java/simpledb/algorithm/Join
• File: src/main/java/simpledb/algorithm/Join/NestedLoopJoin.java
• Class: NestedLoopJoin.java
• Method: close()
Location: src/main/java/simpledb/algorithm/Join
• File: src/main/java/simpledb/algorithm/Join/SortMergeJoin.java
• Class: SortMergeJoin.java
• Method: close()
close() method declared in JoinStrategy was being used in only one child class i.e SortMergeJoin and was not useful in other classes.It was defined with empty body in rest 2 classes.
Hence, close() method is moved to subclass SortMergeJoin and removed form parent class i.e Join/JoinStrategy.
Location: src/main/java/simpledb/optimizer
• File: src/main/java/simpledb/optimizer/JoinOptimizer.java
• Class: JoinOptimizer.java
Location: src/main/java/simpledb/optimizer/LogicalPlan.javaa
• File: src/main/java/simpledb/optimizer
• Class: LogicalPlan.java
Removed bidirectional asociation between JoinOptimizer and LogicalPlan classes. It reduces depenedency between these two classes since independent classes are easier to maintain.
Please let me know, in case of any queries.