New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Oracle SQL - Update statement #11692
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11692 +/- ##
============================================
+ Coverage 63.11% 63.15% +0.03%
Complexity 1225 1225
============================================
Files 2328 2329 +1
Lines 35177 35263 +86
Branches 6130 6141 +11
============================================
+ Hits 22203 22271 +68
- Misses 11181 11196 +15
- Partials 1793 1796 +3
Continue to review full report at Codecov.
|
Hi @ThanoshanMV , Looks our final evaluation is on the way. Let us make it all the way through and win! ;-) @ThanoshanMV @wgy8283335 |
@@ -36,5 +39,7 @@ | |||
|
|||
private final ColumnSegment column; | |||
|
|||
private List<ColumnSegment> columns = new LinkedList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about combining the column and columns?
And change the value to list.
@RequiredArgsConstructor
@Getter
public final class AssignmentSegment implements SQLSegment {
private final int startIndex;
private final int stopIndex;
private final List<ColumnSegment> columns;
private final List<ExpressionSegment> values;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below is not reasonable:
@RequiredArgsConstructor
@Getter
public final class AssignmentSegment implements SQLSegment {
private final int startIndex;
private final int stopIndex;
private final ColumnSegment column;
private List<ColumnSegment> columns = new LinkedList<>();
private final ExpressionSegment value;
}
But what shall we do in this situation? @jingshanglu @tristaZero
UPDATE employees a SET department_id = (SELECT department_id FROM departments WHERE location_id = '2100'), (salary, commission_pct) = (SELECT 1.1*AVG(salary), 1.5*AVG(commission_pct) FROM employees b WHERE a.department_id = b.department_id);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wgy8283335 @ThanoshanMV Maybe we can extract abstract class and combine these two idea.
public abstract class AssignmentSegment implements SQLSegment {
List<ColumnSegment> getColumns();
ExpressionSegment getValue();
}
@RequiredArgsConstructor
@Getter
public final class OracleAssignmentSegment extends AssignmentSegment {
private final int startIndex;
private final int stopIndex;
private List<ColumnSegment> columns = new LinkedList<>();
private final ExpressionSegment value;
}
SET department_id = (SELECT department_id FROM departments WHERE location_id = '2100')
expressed as
OracleAssignmentSegment{columns=[department_id],value=subquery}
(salary, commission_pct) = (SELECT 1.1*AVG(salary), 1.5*AVG(commission_pct) FROM employees b WHERE a.department_id = b.department_id)
expressed as
OracleAssignmentSegment{columns=[salary, commission_pct],value=subquery}
Maybe it has better decoupling and scalability, but we need to make changes in all AssignmentSegment
occurrences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we create similar child classes for other SQL dialects, for example, PostgreSQLAssignmentSegment
or shall we rename OracleAssignmentSegment
to a generic one?
Currently, whenever we need to create an instance of AssignmentSegment
, we have to utilize OracleAssignmentSegment
. In the below image, the method visitSetClause
is in PostgreSQLStatementSQLVisitor
which returns an instance of AssignmentSegment
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we create similar child classes for other SQL dialects, for example,
PostgreSQLAssignmentSegment
or shall we renameOracleAssignmentSegment
to a generic one?Currently, whenever we need to create an instance of
AssignmentSegment
, we have to utilizeOracleAssignmentSegment
. In the below image, the methodvisitSetClause
is inPostgreSQLStatementSQLVisitor
which returns an instance ofAssignmentSegment
:
@ThanoshanMV Yes, maybe it is better to rename OracleAssignmentSegment
to a genneric one, define new subclasses when we need to expand.
…ent and refactor AssignmentSegment related code.
|
||
private final int stopIndex; | ||
|
||
private List<ColumnSegment> columns = new LinkedList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it need to be initialized with LinkedList, as ColumnAssignmentSegment has @RequiredArgsConstructor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change as private final List<ColumnSegment> columns
, remove the initialization and make other changes accordingly.
There are many changes in this pr, and it's better to make all of the ci checks pass. |
Hi @wgy8283335 Thanks for your tips, all the CI tests passed, do you think this one is ready to merge? |
@ThanoshanMV, have you finished your modification? |
Yes @wgy8283335. I changed as |
#10111
Hi @wgy8283335, I've added SQL definition for Oracle UPDATE statement. Please check it.
Changes proposed in this pull request:
DELETE
statement.update_with_special_comments
as it's not aligned with Oracle SQL'sreturningCluase
:AssignmentSegment
: