@@ -66,8 +66,21 @@ public class BigQuerySinkConfig extends AbstractConfig {
66
66
private static final ConfigDef .Width TOPICS_WIDTH = ConfigDef .Width .LONG ;
67
67
private static final String TOPICS_DOC =
68
68
"List of topics to consume, separated by commas" ;
69
+ public static final String TOPICS_DEFAULT = "" ;
69
70
private static final String TOPICS_DISPLAY = "Topics" ;
70
71
72
+ public static final String TOPICS_REGEX_CONFIG = "topics.regex" ;
73
+ private static final ConfigDef .Type TOPICS_REGEX_TYPE = ConfigDef .Type .STRING ;
74
+ private static final ConfigDef .Importance TOPICS_REGEX_IMPORTANCE = ConfigDef .Importance .HIGH ;
75
+ private static final String TOPICS_REGEX_GROUP = "Common" ;
76
+ private static final int TOPICS_REGEX_ORDER_IN_GROUP = 4 ;
77
+ private static final ConfigDef .Width TOPICS_REGEX_WIDTH = ConfigDef .Width .LONG ;
78
+ private static final String TOPICS_REGEX_DOC = "Regular expression giving topics to consume. " +
79
+ "Under the hood, the regex is compiled to a <code>java.util.regex.Pattern</code>. " +
80
+ "Only one of " + TOPICS_CONFIG + " or " + TOPICS_REGEX_CONFIG + " should be specified." ;
81
+ public static final String TOPICS_REGEX_DEFAULT = "" ;
82
+ private static final String TOPICS_REGEX_DISPLAY = "Topics regex" ;
83
+
71
84
public static final String ENABLE_BATCH_CONFIG = "enableBatchLoad" ;
72
85
private static final ConfigDef .Type ENABLE_BATCH_TYPE = ConfigDef .Type .LIST ;
73
86
private static final List <String > ENABLE_BATCH_DEFAULT = Collections .emptyList ();
@@ -225,12 +238,23 @@ public class BigQuerySinkConfig extends AbstractConfig {
225
238
.define (
226
239
TOPICS_CONFIG ,
227
240
TOPICS_TYPE ,
241
+ TOPICS_DEFAULT ,
228
242
TOPICS_IMPORTANCE ,
229
243
TOPICS_DOC ,
230
244
TOPICS_GROUP ,
231
245
TOPICS_ORDER_IN_GROUP ,
232
246
TOPICS_WIDTH ,
233
247
TOPICS_DISPLAY )
248
+ .define (
249
+ TOPICS_REGEX_CONFIG ,
250
+ TOPICS_REGEX_TYPE ,
251
+ TOPICS_REGEX_DEFAULT ,
252
+ TOPICS_REGEX_IMPORTANCE ,
253
+ TOPICS_REGEX_DOC ,
254
+ TOPICS_REGEX_GROUP ,
255
+ TOPICS_REGEX_ORDER_IN_GROUP ,
256
+ TOPICS_REGEX_WIDTH ,
257
+ TOPICS_REGEX_DISPLAY )
234
258
.define (
235
259
ENABLE_BATCH_CONFIG ,
236
260
ENABLE_BATCH_TYPE ,
@@ -343,6 +367,34 @@ public class BigQuerySinkConfig extends AbstractConfig {
343
367
TABLE_CREATE_DOC
344
368
);
345
369
}
370
+ /**
371
+ * Throw an exception if the passed-in properties do not constitute a valid sink.
372
+ * @param props sink configuration properties
373
+ */
374
+ public static void validate (Map <String , String > props ) {
375
+ final boolean hasTopicsConfig = hasTopicsConfig (props );
376
+ final boolean hasTopicsRegexConfig = hasTopicsRegexConfig (props );
377
+
378
+ if (hasTopicsConfig && hasTopicsRegexConfig ) {
379
+ throw new ConfigException (TOPICS_CONFIG + " and " + TOPICS_REGEX_CONFIG +
380
+ " are mutually exclusive options, but both are set." );
381
+ }
382
+
383
+ if (!hasTopicsConfig && !hasTopicsRegexConfig ) {
384
+ throw new ConfigException ("Must configure one of " +
385
+ TOPICS_CONFIG + " or " + TOPICS_REGEX_CONFIG );
386
+ }
387
+ }
388
+
389
+ public static boolean hasTopicsConfig (Map <String , String > props ) {
390
+ String topicsStr = props .get (TOPICS_CONFIG );
391
+ return topicsStr != null && !topicsStr .trim ().isEmpty ();
392
+ }
393
+
394
+ public static boolean hasTopicsRegexConfig (Map <String , String > props ) {
395
+ String topicsRegexStr = props .get (TOPICS_REGEX_CONFIG );
396
+ return topicsRegexStr != null && !topicsRegexStr .trim ().isEmpty ();
397
+ }
346
398
347
399
@ SuppressWarnings ("unchecked" )
348
400
public static class Validator implements ConfigDef .Validator {
0 commit comments