@@ -76,8 +76,8 @@ public class BigQuerySinkConfig extends AbstractConfig {
76
76
private static final int TOPICS_REGEX_ORDER_IN_GROUP = 4 ;
77
77
private static final ConfigDef .Width TOPICS_REGEX_WIDTH = ConfigDef .Width .LONG ;
78
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." ;
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
81
public static final String TOPICS_REGEX_DEFAULT = "" ;
82
82
private static final String TOPICS_REGEX_DISPLAY = "Topics regex" ;
83
83
@@ -238,7 +238,7 @@ public class BigQuerySinkConfig extends AbstractConfig {
238
238
.define (
239
239
TOPICS_CONFIG ,
240
240
TOPICS_TYPE ,
241
- TOPICS_DEFAULT ,
241
+ TOPICS_DEFAULT ,
242
242
TOPICS_IMPORTANCE ,
243
243
TOPICS_DOC ,
244
244
TOPICS_GROUP ,
@@ -248,7 +248,7 @@ public class BigQuerySinkConfig extends AbstractConfig {
248
248
.define (
249
249
TOPICS_REGEX_CONFIG ,
250
250
TOPICS_REGEX_TYPE ,
251
- TOPICS_REGEX_DEFAULT ,
251
+ TOPICS_REGEX_DEFAULT ,
252
252
TOPICS_REGEX_IMPORTANCE ,
253
253
TOPICS_REGEX_DOC ,
254
254
TOPICS_REGEX_GROUP ,
@@ -367,6 +367,34 @@ public class BigQuerySinkConfig extends AbstractConfig {
367
367
TABLE_CREATE_DOC
368
368
);
369
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
+ }
370
398
371
399
@ SuppressWarnings ("unchecked" )
372
400
public static class Validator implements ConfigDef .Validator {
0 commit comments