leonardBang commented on a change in pull request #10468: [FLINK-14649][table 
sql / api] Flatten all the connector properties keys to make it easy to 
configure in DDL
URL: https://github.com/apache/flink/pull/10468#discussion_r355155261
 
 

 ##########
 File path: 
flink-connectors/flink-connector-kafka-base/src/main/java/org/apache/flink/table/descriptors/KafkaValidator.java
 ##########
 @@ -134,4 +153,55 @@ public static String normalizeStartupMode(StartupMode 
startupMode) {
                }
                throw new IllegalArgumentException("Invalid startup mode.");
        }
+
+       /**
+        * Parse SpecificOffsets String to Map.
+        *
+        * <p>SpecificOffsets String format was given as following:
+        *
+        * <pre>
+        *     connector.specific-offsets = 
partition:0,offset:42;partition:1,offset:300
+        * </pre>
+        * @param descriptorProperties
+        * @return
+        */
+       public static Map<Integer, Long> 
validateAndGetSpecificOffsetsStr(DescriptorProperties descriptorProperties) {
+               final Map<Integer, Long> offsetMap = new HashMap<>();
+
+               final String parseSpecificOffsetsStr = 
descriptorProperties.getString(CONNECTOR_SPECIFIC_OFFSETS);
+               if (null == parseSpecificOffsetsStr || 
parseSpecificOffsetsStr.length() == 0) {
+                       throw new ValidationException("Properties 
connector.specific-offsets can not be empty, but is:" + 
parseSpecificOffsetsStr);
+               }
+
+               final String[] pairs = parseSpecificOffsetsStr.split(";");
+               for (String pair: pairs) {
+                       if (null == pair || pair.length() == 0 || 
!pair.contains(",")) {
+                               throw new ValidationException("Invalid 
properties '" + CONNECTOR_SPECIFIC_OFFSETS + "'" +
+                                               "should in the format 
'partition:0,offset:42;partition:1,offset:300', " +
+                                               "but is '" + 
parseSpecificOffsetsStr + "'.");                   }
+
+                       final String[] kv = pair.split(",");
+                       if (kv.length != 2 ||
+                                       
!kv[0].startsWith(CONNECTOR_SPECIFIC_OFFSETS_PARTITION + ':') ||
+                                       
!kv[1].startsWith(CONNECTOR_SPECIFIC_OFFSETS_OFFSET + ':')) {
+                               throw new ValidationException("Invalid 
properties '" + CONNECTOR_SPECIFIC_OFFSETS + "'" +
+                                               "should in the format 
'partition:0,offset:42;partition:1,offset:300', " +
+                                               "but is '" + 
parseSpecificOffsetsStr + "'.");
+                       }
+
+                       String partitionValue = 
kv[0].substring(kv[0].indexOf(":") + 1);
+                       String offsetValue = kv[1].substring(kv[1].indexOf(":") 
+ 1);
+                       try {
+                               final Integer parttion = 
Integer.valueOf(partitionValue);
+                               final Long offset = Long.valueOf(offsetValue);
+                               offsetMap.put(parttion, offset);
+                       }
+                       catch (NumberFormatException e) {
 
 Review comment:
   yes, i got it

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to