From d68ed97e74f4cedc41d9c4d9003e6de313efe828 Mon Sep 17 00:00:00 2001 From: vdisk Date: Fri, 2 Feb 2024 20:20:11 +0800 Subject: [PATCH] fix h2 converter v0.2 --- .../sql/converter/ApolloH2ConverterUtil.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloH2ConverterUtil.java b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloH2ConverterUtil.java index 3397b26bd8b..dd4bbb8b47a 100644 --- a/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloH2ConverterUtil.java +++ b/apollo-build-sql-converter/src/main/java/com/ctrip/framework/apollo/build/sql/converter/ApolloH2ConverterUtil.java @@ -132,7 +132,16 @@ private static String convertTableConfig(String convertedText, SqlStatement sqlS } private static final Pattern INDEX_NAME_PATTERN = Pattern.compile( - "(KEY\\s*`|KEY\\s+)(?[a-zA-Z0-9\\-_]+)(`)?", Pattern.CASE_INSENSITIVE); + // KEY `AppId_ClusterName_GroupName` + "(KEY\\s*`|KEY\\s+)(?[a-zA-Z0-9\\-_]+)(`)?\\s*" + // (`AppId`,`ClusterName`(191),`NamespaceName`(191)) + + "\\((?" + + "(`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?" + + "(," + + "(`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?" + + ")*" + + ")\\)", + Pattern.CASE_INSENSITIVE); private static String convertIndexWithTable(String convertedText, String tableName, SqlStatement sqlStatement) { @@ -147,7 +156,8 @@ private static String convertIndexWithTable(String convertedText, String tableNa // KEY `tableName_AppId_ClusterName_GroupName` (`AppId`,`ClusterName`(191),`NamespaceName`(191)) Matcher indexNameMatcher = INDEX_NAME_PATTERN.matcher(convertedLine); if (indexNameMatcher.find()) { - convertedLine = indexNameMatcher.replaceAll("KEY `" + tableName + "_${indexName}`"); + convertedLine = indexNameMatcher.replaceAll( + "KEY `" + tableName + "_${indexName}` (${indexColumns})"); } convertedLine = removePrefixIndex(convertedLine); } @@ -203,7 +213,8 @@ private static String convertAlterTable(String convertedText, SqlStatement sqlSt "\\s*ADD\\s+(?(UNIQUE\\s+)?INDEX)\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?(?.*)[,;]", Pattern.CASE_INSENSITIVE); private static final Pattern DROP_INDEX_PATTERN = Pattern.compile( - "\\s*DROP\\s+INDEX\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s*[,;]", Pattern.CASE_INSENSITIVE); + "\\s*DROP\\s+INDEX\\s+(`)?(?[a-zA-Z0-9\\-_]+)(`)?\\s*[,;]", + Pattern.CASE_INSENSITIVE); private static String convertAlterTableMulti(String convertedText, SqlStatement sqlStatement, String tableName) {