|
30 | 30 | import java.util.concurrent.LinkedBlockingQueue; |
31 | 31 | import java.util.concurrent.TimeUnit; |
32 | 32 | import java.util.concurrent.ThreadPoolExecutor; |
| 33 | +import java.util.function.Consumer; |
33 | 34 | import java.util.function.Supplier; |
34 | 35 | import java.util.function.UnaryOperator; |
35 | 36 |
|
@@ -1066,6 +1067,91 @@ public static int readEnumValues(String args, int startIndex, int len, Map<Strin |
1066 | 1067 | return len; |
1067 | 1068 | } |
1068 | 1069 |
|
| 1070 | + public static List<String> readValueArray(String args, int startIndex, int len) { |
| 1071 | + List<String> list = new LinkedList<>(); |
| 1072 | + readValueArray(args, startIndex, len, list::add); |
| 1073 | + return list.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(list); |
| 1074 | + } |
| 1075 | + |
| 1076 | + public static int readValueArray(String args, int startIndex, int len, Consumer<String> func) { |
| 1077 | + char closeBracket = ']'; |
| 1078 | + StringBuilder builder = new StringBuilder(); |
| 1079 | + for (int i = startIndex; i < len; i++) { |
| 1080 | + char ch = args.charAt(i); |
| 1081 | + if (ch == '[') { |
| 1082 | + startIndex = i + 1; |
| 1083 | + break; |
| 1084 | + } else if (Character.isWhitespace(ch)) { |
| 1085 | + continue; |
| 1086 | + } else if (i + 1 < len) { |
| 1087 | + char nextCh = args.charAt(i + 1); |
| 1088 | + if (ch == '-' && nextCh == '-') { |
| 1089 | + i = skipSingleLineComment(args, i + 2, len) - 1; |
| 1090 | + } else if (ch == '/' && nextCh == '*') { |
| 1091 | + i = skipMultiLineComment(args, i + 2, len) - 1; |
| 1092 | + } else { |
| 1093 | + startIndex = i; |
| 1094 | + break; |
| 1095 | + } |
| 1096 | + } else { |
| 1097 | + startIndex = i; |
| 1098 | + break; |
| 1099 | + } |
| 1100 | + } |
| 1101 | + |
| 1102 | + boolean hasNext = false; |
| 1103 | + for (int i = startIndex; i < len; i++) { |
| 1104 | + char ch = args.charAt(i); |
| 1105 | + if (Character.isWhitespace(ch)) { |
| 1106 | + continue; |
| 1107 | + } else if (ch == '\'') { // string |
| 1108 | + hasNext = false; |
| 1109 | + int endIndex = readNameOrQuotedString(args, i, len, builder); |
| 1110 | + func.accept(unescape(args.substring(i, endIndex))); |
| 1111 | + builder.setLength(0); |
| 1112 | + i = endIndex + 1; |
| 1113 | + } else if (ch == '[') { // array |
| 1114 | + hasNext = false; |
| 1115 | + int endIndex = skipContentsUntil(args, i + 1, len, ']'); |
| 1116 | + func.accept(args.substring(i, endIndex)); |
| 1117 | + builder.setLength(0); |
| 1118 | + i = endIndex; |
| 1119 | + } else if (ch == '(') { // tuple |
| 1120 | + hasNext = false; |
| 1121 | + int endIndex = skipContentsUntil(args, i + 1, len, ')'); |
| 1122 | + func.accept(args.substring(i, endIndex)); |
| 1123 | + builder.setLength(0); |
| 1124 | + i = endIndex; |
| 1125 | + } else if (ch == closeBracket) { |
| 1126 | + len = i + 1; |
| 1127 | + break; |
| 1128 | + } else if (ch == ',') { |
| 1129 | + hasNext = true; |
| 1130 | + String str = builder.toString(); |
| 1131 | + func.accept(str.isEmpty() || ClickHouseValues.NULL_EXPR.equalsIgnoreCase(str) ? null : str); |
| 1132 | + builder.setLength(0); |
| 1133 | + } else if (i + 1 < len) { |
| 1134 | + char nextCh = args.charAt(i + 1); |
| 1135 | + if (ch == '-' && nextCh == '-') { |
| 1136 | + i = skipSingleLineComment(args, i + 2, len) - 1; |
| 1137 | + } else if (ch == '/' && nextCh == '*') { |
| 1138 | + i = skipMultiLineComment(args, i + 2, len) - 1; |
| 1139 | + } else { |
| 1140 | + builder.append(ch); |
| 1141 | + } |
| 1142 | + } else { |
| 1143 | + builder.append(ch); |
| 1144 | + } |
| 1145 | + } |
| 1146 | + |
| 1147 | + if (hasNext || builder.length() > 0) { |
| 1148 | + String str = builder.toString(); |
| 1149 | + func.accept(str.isEmpty() || ClickHouseValues.NULL_EXPR.equalsIgnoreCase(str) ? null : str); |
| 1150 | + } |
| 1151 | + |
| 1152 | + return len; |
| 1153 | + } |
| 1154 | + |
1069 | 1155 | public static int readParameters(String args, int startIndex, int len, List<String> params) { |
1070 | 1156 | char closeBracket = ')'; // startIndex points to the openning bracket |
1071 | 1157 | Deque<Character> stack = new ArrayDeque<>(); |
|
0 commit comments