|
120 | 120 | import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UninstallComponentContext; |
121 | 121 | import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UninstallPluginContext; |
122 | 122 | import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UseContext; |
| 123 | +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AlterResourceContext; |
| 124 | +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyAssignmentContext; |
| 125 | +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ResourceNameContext; |
| 126 | +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyKeyContext; |
| 127 | +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyValueContext; |
123 | 128 | import org.apache.shardingsphere.sql.parser.engine.doris.visitor.statement.DorisStatementVisitor; |
124 | 129 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CacheTableIndexSegment; |
125 | 130 | import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CloneActionSegment; |
|
153 | 158 | import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; |
154 | 159 | import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue; |
155 | 160 | import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue; |
| 161 | +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.LiteralValue; |
| 162 | +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.BooleanLiteralValue; |
| 163 | +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.DateTimeLiteralValue; |
| 164 | +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NullLiteralValue; |
| 165 | +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.OtherLiteralValue; |
| 166 | +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.TemporalLiteralValue; |
| 167 | +import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement; |
156 | 168 | import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCloneStatement; |
157 | 169 | import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCreateLoadableFunctionStatement; |
158 | 170 | import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLDelimiterStatement; |
|
233 | 245 | import java.util.LinkedList; |
234 | 246 | import java.util.List; |
235 | 247 | import java.util.Optional; |
| 248 | +import java.util.Properties; |
236 | 249 | import java.util.stream.Collectors; |
237 | 250 |
|
238 | 251 | /** |
@@ -902,6 +915,68 @@ public ASTNode visitAlterResourceGroup(final AlterResourceGroupContext ctx) { |
902 | 915 | return new MySQLAlterResourceGroupStatement(getDatabaseType(), ((IdentifierValue) visit(ctx.groupName())).getValue()); |
903 | 916 | } |
904 | 917 |
|
| 918 | + @Override |
| 919 | + public ASTNode visitAlterResource(final AlterResourceContext ctx) { |
| 920 | + String resourceName = getResourceName(ctx.resourceName()); |
| 921 | + Properties properties = new Properties(); |
| 922 | + for (PropertyAssignmentContext each : ctx.propertyAssignments().propertyAssignment()) { |
| 923 | + String key = getPropertyKey(each.propertyKey()); |
| 924 | + String value = getPropertyValue(each.propertyValue()); |
| 925 | + properties.setProperty(key, value); |
| 926 | + } |
| 927 | + return new DorisAlterResourceStatement(getDatabaseType(), resourceName, properties); |
| 928 | + } |
| 929 | + |
| 930 | + private String getResourceName(final ResourceNameContext ctx) { |
| 931 | + if (null != ctx.identifier()) { |
| 932 | + return ((IdentifierValue) visit(ctx.identifier())).getValue(); |
| 933 | + } |
| 934 | + return ((StringLiteralValue) visit(ctx.string_())).getValue(); |
| 935 | + } |
| 936 | + |
| 937 | + private String getPropertyKey(final PropertyKeyContext ctx) { |
| 938 | + if (null != ctx.identifier()) { |
| 939 | + return ((IdentifierValue) visit(ctx.identifier())).getValue(); |
| 940 | + } |
| 941 | + return ((StringLiteralValue) visit(ctx.string_())).getValue(); |
| 942 | + } |
| 943 | + |
| 944 | + private String getPropertyValue(final PropertyValueContext ctx) { |
| 945 | + if (null != ctx.identifier()) { |
| 946 | + return ((IdentifierValue) visit(ctx.identifier())).getValue(); |
| 947 | + } |
| 948 | + ASTNode result = visit(ctx.literals()); |
| 949 | + if (result instanceof LiteralValue) { |
| 950 | + return getLiteralValueAsString((LiteralValue<?>) result); |
| 951 | + } |
| 952 | + return result.toString(); |
| 953 | + } |
| 954 | + |
| 955 | + private String getLiteralValueAsString(final LiteralValue<?> literalValue) { |
| 956 | + if (literalValue instanceof StringLiteralValue) { |
| 957 | + return ((StringLiteralValue) literalValue).getValue(); |
| 958 | + } |
| 959 | + if (literalValue instanceof NumberLiteralValue) { |
| 960 | + return ((NumberLiteralValue) literalValue).getValue().toString(); |
| 961 | + } |
| 962 | + if (literalValue instanceof BooleanLiteralValue) { |
| 963 | + return String.valueOf(((BooleanLiteralValue) literalValue).getValue()); |
| 964 | + } |
| 965 | + if (literalValue instanceof NullLiteralValue) { |
| 966 | + return "NULL"; |
| 967 | + } |
| 968 | + if (literalValue instanceof DateTimeLiteralValue) { |
| 969 | + return ((DateTimeLiteralValue) literalValue).getValue(); |
| 970 | + } |
| 971 | + if (literalValue instanceof TemporalLiteralValue) { |
| 972 | + return ((TemporalLiteralValue) literalValue).getValue(); |
| 973 | + } |
| 974 | + if (literalValue instanceof OtherLiteralValue) { |
| 975 | + return String.valueOf(((OtherLiteralValue) literalValue).getValue()); |
| 976 | + } |
| 977 | + return String.valueOf(literalValue.getValue()); |
| 978 | + } |
| 979 | + |
905 | 980 | @Override |
906 | 981 | public ASTNode visitChangeMasterTo(final ChangeMasterToContext ctx) { |
907 | 982 | return new MySQLChangeMasterStatement(getDatabaseType()); |
|
0 commit comments