25
25
@ Builder
26
26
@ Getter
27
27
public class Column {
28
+ private static final Pattern PARAMETRIZED_TYPE_PATTERN = Pattern .compile (".+\\ (.+\\ )" );
29
+ private static final Pattern DECIMAL_TYPE_PATTERN = Pattern .compile ("Decimal(?<size>\\ d{2,3})?\\ s*(\\ ((?<a1>\\ d{1,}\\ s*)?,*\\ s*(?<a2>\\ d{1,})?\\ ))?" );
30
+ private static final Pattern SIMPLE_AGGREGATE_FUNCTION_TYPE_PATTERN = Pattern .compile ("^SimpleAggregateFunction\\ s*\\ ([^,]+,\\ s*(.+)\\ )$" );
31
+
28
32
private static final Logger LOGGER = LoggerFactory .getLogger (Column .class );
29
33
30
34
private String name ;
@@ -229,7 +233,7 @@ public static Column extractColumn(String name, String valueType, boolean isNull
229
233
230
234
ColumnBuilder variantTypeBuilder = Column .builder ().type (typePrecisionAndScale .getT1 ());
231
235
232
- if (Pattern . compile ( ".+ \\ (.+ \\ )" ) .asMatchPredicate ().test (definition )) {
236
+ if (PARAMETRIZED_TYPE_PATTERN .asMatchPredicate ().test (definition )) {
233
237
variantTypeBuilder = variantTypeBuilder
234
238
.precision (typePrecisionAndScale .getT2 ())
235
239
.scale (typePrecisionAndScale .getT3 ());
@@ -251,6 +255,13 @@ public static Column extractColumn(String name, String valueType, boolean isNull
251
255
return extractColumn (name , valueType .substring ("LowCardinality" .length () + 1 , valueType .length () - 1 ), isNull , hasDefaultValue , isSubColumn );
252
256
} else if (valueType .startsWith ("Nullable" )) {
253
257
return extractColumn (name , valueType .substring ("Nullable" .length () + 1 , valueType .length () - 1 ), true , hasDefaultValue , isSubColumn );
258
+ } else if (valueType .startsWith ("SimpleAggregateFunction" )) {
259
+ Matcher m = SIMPLE_AGGREGATE_FUNCTION_TYPE_PATTERN .matcher (valueType );
260
+ if (!m .matches ()) {
261
+ throw new RuntimeException ("can't parse SimpleAggregateFunction type" );
262
+ }
263
+ String argType = m .group (1 ).trim ();
264
+ return extractColumn (name , argType , isNull , hasDefaultValue , isSubColumn );
254
265
}
255
266
256
267
// We're dealing with a primitive type here
@@ -277,9 +288,7 @@ private static Tuple3<Type, Integer, Integer> dispatchPrimitiveWithPrecisionAndS
277
288
precision = Integer .parseInt (scaleAndTimezone [0 ].trim ());
278
289
LOGGER .trace ("Parsed precision of DateTime64 is {}" , precision );
279
290
} else if (type == Type .Decimal ) {
280
- final Pattern patter = Pattern .compile ("Decimal(?<size>\\ d{2,3})?\\ s*(\\ ((?<a1>\\ d{1,}\\ s*)?,*\\ s*(?<a2>\\ d{1,})?\\ ))?" );
281
- Matcher match = patter .matcher (valueType );
282
-
291
+ Matcher match = DECIMAL_TYPE_PATTERN .matcher (valueType );
283
292
if (!match .matches ()) {
284
293
throw new RuntimeException ("type doesn't match" );
285
294
}
0 commit comments