thesumery commented on code in PR #6618: URL: https://github.com/apache/inlong/pull/6618#discussion_r1033077419
########## inlong-sort/sort-connectors/base/src/main/java/org/apache/inlong/sort/base/util/LabelUtils.java: ########## @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.inlong.sort.base.util; + +import java.util.LinkedHashMap; +import java.util.Map; +import static org.apache.inlong.sort.base.Constants.DELIMITER; +import static org.apache.inlong.sort.base.Constants.KEY_VALUE_DELIMITER; + +/** + * The lable utils class, it is used for parse the lables to a label map + */ +public final class LabelUtils { + + private LabelUtils() { + } + + /** + * Parse the labels to label map + * + * @param labels The labels format by 'key1=value1&key2=value2...' + * @return The label map of labels + */ + public static Map<String, String> parseLabels(String labels) { + return parseLabels(labels, new LinkedHashMap<>()); + } + + /** + * Parse the labels to label map + * + * @param labels The labels format by 'key1=value1&key2=value2...' + * @return The label map of labels + */ + public static Map<String, String> parseLabels(String labels, Map<String, String> labelMap) { + if (labelMap == null) { + labelMap = new LinkedHashMap<>(); + } + if (labels == null || labels.length() == 0) { + return labelMap; + } + String[] labelArray = labels.split(DELIMITER); + for (String label : labelArray) { + int index = label.indexOf(KEY_VALUE_DELIMITER); + if (index < 1 || index == label.length() - 1) { + throw new IllegalArgumentException("The format of option 'sink.dirty.labels' must be key=value"); Review Comment: LabelUtils is only used for 'dirty.lables'? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
