You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/11/22 04:17:21 UTC

[GitHub] [inlong] Yizhou-Yang commented on a diff in pull request #6541: [INLONG-6495][Sort] Support metrics and restore metrics for single-table of Doris

Yizhou-Yang commented on code in PR #6541:
URL: https://github.com/apache/inlong/pull/6541#discussion_r1028811819


##########
inlong-sort/sort-connectors/doris/src/main/java/org/apache/inlong/sort/doris/utils/DorisParseUtils.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.doris.utils;
+
+import org.apache.flink.types.RowKind;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.inlong.common.metric.MetricObserver.LOG;
+
+public class DorisParseUtils {
+
+    public static Map<String, String> parsetoMap(Object data) {
+        String[] toParse = data.toString().split("\\s+");
+        Map<String, String> ret = new HashMap<>();
+        if (toParse.length < 2) {
+            LOG.warn("parse length insufficient! string is :{}", Arrays.toString(toParse));
+            return ret;
+        }
+        ret.put("id", toParse[0]);
+        ret.put("__DORIS_DELETE_SIGN__", toParse[1]);
+        return ret;
+    }
+
+    public static String parseDeleteSign(RowKind rowKind) {
+        if (RowKind.INSERT.equals(rowKind) || RowKind.UPDATE_AFTER.equals(rowKind)) {
+            return "0";
+        } else if (RowKind.DELETE.equals(rowKind) || RowKind.UPDATE_BEFORE.equals(rowKind)) {
+            return "1";
+        } else {
+            throw new RuntimeException("Unrecognized row kind:" + rowKind.toString());
+        }
+    }
+
+    public static String escapeString(String s) {
+        Pattern p = Pattern.compile("\\\\x(\\d{2})");
+        Matcher m = p.matcher(s);
+
+        StringBuffer buf = new StringBuffer();

Review Comment:
   buffer is required for matcher's appendReplacement and appendTail methods. If we use String, then replaceAll replaces the second and later matches with the first group, and replaceFirst will end in infinite loop.



##########
inlong-sort/sort-connectors/doris/src/main/java/org/apache/inlong/sort/doris/utils/DorisParseUtils.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.doris.utils;
+
+import org.apache.flink.types.RowKind;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.inlong.common.metric.MetricObserver.LOG;
+
+public class DorisParseUtils {
+
+    public static Map<String, String> parsetoMap(Object data) {

Review Comment:
   fixed



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org