Skip to content

Commit

Permalink
Refactor VariableSegment (#33754)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 21, 2024
1 parent 7e0b71f commit ef6c151
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -924,14 +924,14 @@ private VariableAssignSegment getVariableAssignSegment(final OptionValueContext
if (null != ctx.optionValueNoOptionType()) {
return getVariableAssignSegment(ctx.optionValueNoOptionType());
}
VariableSegment variable = new VariableSegment(ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText());
variable.setScope(ctx.optionType().getText());
VariableSegment variable = new VariableSegment(
ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText());
return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), variable, ctx.setExprOrDefault().getText());
}

private VariableAssignSegment getVariableAssignSegment(final OptionValueListContext ctx) {
VariableSegment variable = new VariableSegment(ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText());
variable.setScope(ctx.optionType().getText());
VariableSegment variable = new VariableSegment(
ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText());
return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.setExprOrDefault().stop.getStopIndex(), variable, ctx.setExprOrDefault().getText());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.sql.parser.statement.core.segment.dal;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
Expand All @@ -27,6 +28,7 @@
/**
* Variable segment.
*/
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ void assertCreateWithSelectStatementForTransactionReadOnly() {
MySQLSelectStatement selectStatement = mock(MySQLSelectStatement.class);
when(selectStatement.getFrom()).thenReturn(Optional.empty());
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
VariableSegment variableSegment = new VariableSegment(0, 0, "transaction_read_only");
variableSegment.setScope("SESSION");
VariableSegment variableSegment = new VariableSegment(0, 0, "transaction_read_only", "SESSION");
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new ExpressionProjectionSegment(0, 10, "@@session.transaction_read_only", variableSegment)));
when(selectStatement.getProjections()).thenReturn(projectionsSegment);
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Expand All @@ -225,8 +224,7 @@ void assertCreateWithSelectStatementForTransactionIsolation() {
MySQLSelectStatement selectStatement = mock(MySQLSelectStatement.class);
when(selectStatement.getFrom()).thenReturn(Optional.empty());
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
VariableSegment variableSegment = new VariableSegment(0, 0, "transaction_isolation");
variableSegment.setScope("SESSION");
VariableSegment variableSegment = new VariableSegment(0, 0, "transaction_isolation", "SESSION");
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new ExpressionProjectionSegment(0, 10, "@@session.transaction_isolation", variableSegment)));
when(selectStatement.getProjections()).thenReturn(projectionsSegment);
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Expand Down

0 comments on commit ef6c151

Please sign in to comment.