|
123 | 123 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromTableSegment;
|
124 | 124 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.LoadTableIndexSegment;
|
125 | 125 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionDefinitionSegment;
|
| 126 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionIdSegment; |
126 | 127 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionSegment;
|
127 | 128 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetMasterOptionSegment;
|
128 | 129 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetOptionSegment;
|
|
137 | 138 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
|
138 | 139 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.LimitSegment;
|
139 | 140 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment;
|
| 141 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseIdSegment; |
140 | 142 | import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment;
|
| 143 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; |
141 | 144 | import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
|
| 145 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableIdSegment; |
| 146 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; |
142 | 147 | import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
|
143 | 148 | import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
|
144 | 149 | import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
|
@@ -935,17 +940,17 @@ private VariableAssignSegment getVariableAssignSegment(final OptionValueContext
|
935 | 940 | ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText());
|
936 | 941 | return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), variable, ctx.setExprOrDefault().getText());
|
937 | 942 | }
|
938 |
| - |
| 943 | + |
939 | 944 | private VariableAssignSegment getVariableAssignSegment(final OptionValueListContext ctx) {
|
940 | 945 | VariableSegment variable = new VariableSegment(
|
941 | 946 | ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText());
|
942 | 947 | return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.setExprOrDefault().stop.getStopIndex(), variable, ctx.setExprOrDefault().getText());
|
943 | 948 | }
|
944 |
| - |
| 949 | + |
945 | 950 | private VariableAssignSegment getVariableAssignSegment(final OptionValueNoOptionTypeContext ctx) {
|
946 | 951 | return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getVariableSegment(ctx), getAssignValue(ctx));
|
947 | 952 | }
|
948 |
| - |
| 953 | + |
949 | 954 | private VariableSegment getVariableSegment(final OptionValueNoOptionTypeContext ctx) {
|
950 | 955 | if (null != ctx.NAMES()) {
|
951 | 956 | // TODO Consider setting all three system variables: character_set_client, character_set_results, character_set_connection
|
@@ -1080,44 +1085,89 @@ public ASTNode visitHelp(final HelpContext ctx) {
|
1080 | 1085 | result.setSearchString(ctx.textOrIdentifier().getText());
|
1081 | 1086 | return result;
|
1082 | 1087 | }
|
1083 |
| - |
| 1088 | + |
1084 | 1089 | @Override
|
1085 | 1090 | public ASTNode visitRecoverDatabase(final RecoverDatabaseContext ctx) {
|
1086 | 1091 | DorisRecoverDatabaseStatement result = new DorisRecoverDatabaseStatement();
|
1087 |
| - result.setDatabaseName(new IdentifierValue(ctx.databaseName().getText()).getValue()); |
| 1092 | + DatabaseSegment databaseName = new DatabaseSegment( |
| 1093 | + ctx.databaseName().start.getStartIndex(), |
| 1094 | + ctx.databaseName().stop.getStopIndex(), |
| 1095 | + new IdentifierValue(ctx.databaseName().identifier().getText())); |
| 1096 | + result.setDatabaseName(databaseName); |
| 1097 | + |
1088 | 1098 | if (null != ctx.databaseId()) {
|
1089 |
| - result.setDatabaseId(new IdentifierValue(ctx.databaseId().getText()).getValue()); |
| 1099 | + DatabaseIdSegment databaseIdSegment = new DatabaseIdSegment( |
| 1100 | + ctx.databaseId().start.getStartIndex(), |
| 1101 | + ctx.databaseId().stop.getStopIndex(), |
| 1102 | + new IdentifierValue(ctx.databaseId().identifier().getText())); |
| 1103 | + result.setDatabaseId(databaseIdSegment); |
1090 | 1104 | }
|
1091 |
| - if (null != ctx.newDatabaseName()) { |
1092 |
| - result.setDatabaseName(new IdentifierValue(ctx.newDatabaseName().getText()).getValue()); |
| 1105 | + if (null != ctx.newDatabaseName) { |
| 1106 | + DatabaseSegment newDatabaseName = new DatabaseSegment( |
| 1107 | + ctx.newDatabaseName.start.getStartIndex(), |
| 1108 | + ctx.newDatabaseName.stop.getStopIndex(), |
| 1109 | + new IdentifierValue(ctx.newDatabaseName.getText())); |
| 1110 | + result.setDatabaseName(newDatabaseName); |
1093 | 1111 | }
|
1094 | 1112 | return result;
|
1095 | 1113 | }
|
1096 |
| - |
| 1114 | + |
1097 | 1115 | @Override
|
1098 | 1116 | public ASTNode visitRecoverPartition(final RecoverPartitionContext ctx) {
|
1099 | 1117 | DorisRecoverPartitionStatement result = new DorisRecoverPartitionStatement();
|
1100 |
| - result.setPartitionName(new IdentifierValue(ctx.partitionName().getText()).getValue()); |
| 1118 | + PartitionSegment partitionSegment = new PartitionSegment( |
| 1119 | + ctx.partitionName().start.getStartIndex(), |
| 1120 | + ctx.partitionName().stop.getStopIndex(), |
| 1121 | + new IdentifierValue(ctx.partitionName().identifier().getText())); |
| 1122 | + result.setPartitionName(partitionSegment); |
1101 | 1123 | if (null != ctx.partitionId()) {
|
1102 |
| - result.setPartitionId(new IdentifierValue(ctx.partitionId().getText()).getValue()); |
| 1124 | + PartitionIdSegment partitionId = new PartitionIdSegment( |
| 1125 | + ctx.partitionId().start.getStartIndex(), |
| 1126 | + ctx.partitionId().stop.getStopIndex(), |
| 1127 | + new IdentifierValue(ctx.partitionId().identifier().getText())); |
| 1128 | + result.setPartitionId(partitionId); |
1103 | 1129 | }
|
1104 |
| - if (null != ctx.newPartitionName()) { |
1105 |
| - result.setNewPartitionName(new IdentifierValue(ctx.newPartitionName().getText()).getValue()); |
| 1130 | + if (null != ctx.newPartitionName) { |
| 1131 | + final PartitionSegment newPartitionName = new PartitionSegment( |
| 1132 | + ctx.newPartitionName.start.getStartIndex(), |
| 1133 | + ctx.newPartitionName.stop.getStopIndex(), |
| 1134 | + new IdentifierValue(ctx.newPartitionName.getText())); |
| 1135 | + result.setNewPartitionName(newPartitionName); |
1106 | 1136 | }
|
1107 |
| - if (null != ctx.tableName().owner()) { |
1108 |
| - result.setOwner(new IdentifierValue(ctx.tableName().owner().getText()).getValue()); |
1109 |
| - } |
1110 |
| - result.setTableName(new IdentifierValue(ctx.tableName().name().getText()).getValue()); |
| 1137 | + SimpleTableSegment simpleTableSegment = createSimpleTableSegment(ctx.tableName()); |
| 1138 | + result.setTableName(simpleTableSegment); |
| 1139 | + |
1111 | 1140 | return result;
|
1112 | 1141 | }
|
1113 |
| - |
| 1142 | + |
1114 | 1143 | @Override
|
1115 | 1144 | public ASTNode visitRecoverTable(final RecoverTableContext ctx) {
|
1116 | 1145 | DorisRecoverTableStatement result = new DorisRecoverTableStatement();
|
1117 |
| - result.setTableName(new IdentifierValue(ctx.tableName().getText()).getValue()); |
| 1146 | + SimpleTableSegment simpleTableSegment = createSimpleTableSegment(ctx.tableName()); |
| 1147 | + result.setTableName(simpleTableSegment); |
1118 | 1148 | if (null != ctx.tableId()) {
|
1119 |
| - result.setTableName(new IdentifierValue(ctx.tableId().getText()).getValue()); |
| 1149 | + final TableIdSegment tableIdSegment = new TableIdSegment( |
| 1150 | + ctx.tableId().start.getStartIndex(), |
| 1151 | + ctx.tableId().stop.getStopIndex(), |
| 1152 | + new IdentifierValue(ctx.tableId().getText())); |
| 1153 | + result.setTableId(tableIdSegment); |
1120 | 1154 | }
|
1121 | 1155 | return result;
|
1122 | 1156 | }
|
| 1157 | + |
| 1158 | + private SimpleTableSegment createSimpleTableSegment(final TableNameContext tableNameContext) { |
| 1159 | + final TableNameSegment tableNameSegment = new TableNameSegment( |
| 1160 | + tableNameContext.start.getStartIndex(), |
| 1161 | + tableNameContext.stop.getStopIndex(), |
| 1162 | + new IdentifierValue(tableNameContext.getText())); |
| 1163 | + SimpleTableSegment simpleTableSegment = new SimpleTableSegment(tableNameSegment); |
| 1164 | + if (null != tableNameContext.owner()) { |
| 1165 | + OwnerSegment ownerSegment = new OwnerSegment( |
| 1166 | + tableNameContext.owner().start.getStartIndex(), |
| 1167 | + tableNameContext.owner().stop.getStopIndex(), |
| 1168 | + new IdentifierValue(tableNameContext.owner().getText())); |
| 1169 | + simpleTableSegment.setOwner(ownerSegment); |
| 1170 | + } |
| 1171 | + return simpleTableSegment; |
| 1172 | + } |
1123 | 1173 | }
|
0 commit comments