This is an automated email from the ASF dual-hosted git repository.
bossenti pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 9236304f24 feat: add measurement sanitizer for IoTDB (#2821)
9236304f24 is described below
commit 9236304f242bb92328ff049f610f3cc934d5de5b
Author: Tim <[email protected]>
AuthorDate: Mon May 6 08:34:11 2024 +0200
feat: add measurement sanitizer for IoTDB (#2821)
---
.../ts/store/iotdb/MeasureNameSanitizerIotDb.java | 49 ++++++++++++++++++++++
.../sanitize/MeasureNameSanitizerIotDbTest.java | 38 +++++++++++++++++
2 files changed, 87 insertions(+)
diff --git
a/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/MeasureNameSanitizerIotDb.java
b/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/MeasureNameSanitizerIotDb.java
new file mode 100644
index 0000000000..bc30a4ed2d
--- /dev/null
+++
b/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/MeasureNameSanitizerIotDb.java
@@ -0,0 +1,49 @@
+/*
+ * 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.streampipes.ts.store.iotdb;
+
+/**
+ * Ensures that measurement names comply with IoTDB path specifications.
+ * <p>
+ * Measurement names in IoTDB paths should consist of characters that are
either:
+ * <ul>
+ * <li>Word characters (letters, digits, or underscore), or </li>
+ * <li>Chinese characters (Unicode range: u2E80-u9FFF). </li>
+ * </ul>
+ * <p>
+ * {@see <a
href="https://iotdb.apache.org/UserGuide/latest/Basic-Concept/Data-Model-and-Terminology.html#path">IoTDB
Data Model and Terminology</a>}
+ */
+public class MeasureNameSanitizerIotDb {
+
+ /**
+ * Sanitizes the given measurement name to comply with IoTDB path
specifications.
+ *
+ * @param measureName The measurement name to be sanitized
+ * @return The sanitized measurement name with non-compliant characters
replaced by underscores
+ */
+ public String sanitize(String measureName) {
+
+ // matches any character that is not a word character (\w, equivalent to
[a-zA-Z0-9_]) or
+ // a Chinese character (\u2E80-\u9FFF).
+ // according to
https://iotdb.apache.org/UserGuide/latest/Basic-Concept/Data-Model-and-Terminology.html#path
+ String allowedCharacterPattern = "[^\\w\\u2E80-\\u9FFF]";
+
+ return measureName.replaceAll(allowedCharacterPattern, "_");
+ }
+}
diff --git
a/streampipes-ts-store-iotdb/src/test/java/org/apache/streampipes/ts/store/iotdb/sanitize/MeasureNameSanitizerIotDbTest.java
b/streampipes-ts-store-iotdb/src/test/java/org/apache/streampipes/ts/store/iotdb/sanitize/MeasureNameSanitizerIotDbTest.java
new file mode 100644
index 0000000000..6a11f4dee6
--- /dev/null
+++
b/streampipes-ts-store-iotdb/src/test/java/org/apache/streampipes/ts/store/iotdb/sanitize/MeasureNameSanitizerIotDbTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.streampipes.ts.store.iotdb.sanitize;
+
+import org.apache.streampipes.ts.store.iotdb.MeasureNameSanitizerIotDb;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class MeasureNameSanitizerIotDbTest {
+
+ @Test
+ public void sanitize(){
+ var sanitizer = new MeasureNameSanitizerIotDb();
+
+ assertEquals("myMeasure", sanitizer.sanitize("myMeasure"));
+ assertEquals("我的措施", sanitizer.sanitize("我的措施"));
+ assertEquals("my_Measure", sanitizer.sanitize("my-Measure"));
+ assertEquals("my_Measure_", sanitizer.sanitize("my-Measure?"));
+ assertEquals("my_", sanitizer.sanitize("my🙂"));
+ }
+}
\ No newline at end of file