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 abafb8417b feat: add name sanitizer for IotDB (#2827)
abafb8417b is described below

commit abafb8417ba89a52ff6930ad52b57628bca143f2
Author: Tim <[email protected]>
AuthorDate: Tue May 7 08:21:20 2024 +0200

    feat: add name sanitizer for IotDB (#2827)
    
    * feat: add name sanitizer for IotDB
    
    * style: add file headers
---
 pom.xml                                            |   1 +
 streampipes-ts-store-iotdb/pom.xml                 |  84 ++++++++
 .../ts/store/iotdb/IotDbNameSanitizer.java         |  39 ++++
 .../ts/store/iotdb/IotDbReservedKeywords.java      | 224 +++++++++++++++++++++
 .../ts/store/iotdb/IotDbNameSanitizerTest.java     |  37 ++++
 5 files changed, 385 insertions(+)

diff --git a/pom.xml b/pom.xml
index a807e2d270..6c4bfefdd5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -869,6 +869,7 @@
         <module>streampipes-storage-management</module>
         <module>streampipes-test-utils</module>
         <module>streampipes-test-utils-executors</module>
+        <module>streampipes-ts-store-iotdb</module>
         <module>streampipes-user-management</module>
         <module>streampipes-vocabulary</module>
         <module>streampipes-wrapper</module>
diff --git a/streampipes-ts-store-iotdb/pom.xml 
b/streampipes-ts-store-iotdb/pom.xml
new file mode 100644
index 0000000000..4029c81906
--- /dev/null
+++ b/streampipes-ts-store-iotdb/pom.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  ~
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.streampipes</groupId>
+        <artifactId>streampipes-parent</artifactId>
+        <version>0.95.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>streampipes-ts-store-iotdb</artifactId>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <!-- StreamPipes dependencies -->
+        <dependency>
+            <groupId>org.apache.streampipes</groupId>
+            <artifactId>streampipes-client-api</artifactId>
+            <version>0.95.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.streampipes</groupId>
+            <artifactId>streampipes-commons</artifactId>
+            <version>0.95.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.streampipes</groupId>
+            <artifactId>streampipes-data-explorer</artifactId>
+            <version>0.95.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.streampipes</groupId>
+            <artifactId>streampipes-model</artifactId>
+            <version>0.95.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.streampipes</groupId>
+            <artifactId>streampipes-vocabulary</artifactId>
+            <version>0.95.0-SNAPSHOT</version>
+        </dependency>
+
+        <!-- External dependencies -->
+        <dependency>
+            <groupId>org.apache.iotdb</groupId>
+            <artifactId>iotdb-session</artifactId>
+            <version>1.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <!--Test dependencies -->
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git 
a/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/IotDbNameSanitizer.java
 
b/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/IotDbNameSanitizer.java
new file mode 100644
index 0000000000..8d66978dc9
--- /dev/null
+++ 
b/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/IotDbNameSanitizer.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+public class IotDbNameSanitizer {
+
+  private final IotDbReservedKeywords reservedKeywords = new 
IotDbReservedKeywords();
+
+  /**
+   * Checks if a runtime name conflicts with any reserved keyword. If a 
conflict is found,
+   * the runtime name is suffixed with an underscore.
+   *
+   * @param runtimeName the runtime name to be checked for conflicts with 
reserved keywords
+   * @return the modified runtime name with underscore suffix if conflict 
exists, otherwise returns the original runtime name
+   */
+  public String renameReservedKeywords(String runtimeName){
+    var containsKeyword = reservedKeywords.getAll()
+        .stream()
+        .anyMatch(keyword -> keyword.equalsIgnoreCase(runtimeName));
+
+    return containsKeyword ? runtimeName + "_" : runtimeName;
+  }
+}
diff --git 
a/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/IotDbReservedKeywords.java
 
b/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/IotDbReservedKeywords.java
new file mode 100644
index 0000000000..5813cffce1
--- /dev/null
+++ 
b/streampipes-ts-store-iotdb/src/main/java/org/apache/streampipes/ts/store/iotdb/IotDbReservedKeywords.java
@@ -0,0 +1,224 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class IotDbReservedKeywords {
+
+  private static final List<String> KEYWORD_LIST = Arrays.asList(
+      // Common Keywords
+      "ADD",
+      "AFTER",
+      "ALIAS",
+      "ALIGN",
+      "ALIGNED",
+      "ALL",
+      "ALTER",
+      "ANY",
+      "AS",
+      "ASC",
+      "ATTRIBUTES",
+      "AUTOREGISTER",
+      "BEFORE",
+      "BEGIN",
+      "BY",
+      "CACHE",
+      "CHILD",
+      "CLEAR",
+      "COMPRESSION",
+      "COMPRESSOR",
+      "CONCAT",
+      "CONFIGURATION",
+      "CONTINUOUS",
+      "COUNT",
+      "CONTAIN",
+      "CQ",
+      "CQS",
+      "CREATE",
+      "DATATYPE",
+      "DEBUG",
+      "DELETE",
+      "DESC",
+      "DESCRIBE",
+      "DEVICE",
+      "DEVICES",
+      "DISABLE",
+      "DROP",
+      "ENCODING",
+      "END",
+      "EVERY",
+      "EXPLAIN",
+      "FILL",
+      "FLUSH",
+      "FOR",
+      "FROM",
+      "FULL",
+      "FUNCTION",
+      "FUNCTIONS",
+      "GLOBAL",
+      "GRANT",
+      "GROUP",
+      "INDEX",
+      "INFO",
+      "INSERT",
+      "INTO",
+      "KILL",
+      "LABEL",
+      "LAST",
+      "LATEST",
+      "LEVEL",
+      "LIKE",
+      "LIMIT",
+      "LINEAR",
+      "LINK",
+      "LIST",
+      "LOAD",
+      "LOCK",
+      "MERGE",
+      "METADATA",
+      "NODES",
+      "NOW",
+      "OF",
+      "OFF",
+      "OFFSET",
+      "ON",
+      "ORDER",
+      "PARTITION",
+      "PASSWORD",
+      "PATHS",
+      "PREVIOUS",
+      "PREVIOUSUNTILLAST",
+      "PRIVILEGES",
+      "PROCESSLIST",
+      "PROPERTY",
+      "QUERIES",
+      "QUERY",
+      "READONLY",
+      "REGEXP",
+      "REMOVE",
+      "RENAME",
+      "RESAMPLE",
+      "REVOKE",
+      "ROLE",
+      "ROOT",
+      "SCHEMA",
+      "SELECT",
+      "SET",
+      "SETTLE",
+      "SGLEVEL",
+      "SHOW",
+      "SLIMIT",
+      "SNAPSHOT",
+      "SOFFSET",
+      "STORAGE",
+      "START",
+      "STOP",
+      "SYSTEM",
+      "TAGS",
+      "TASK",
+      "TEMPLATE",
+      "TIME",
+      "TIMESERIES",
+      "TIMESTAMP",
+      "TO",
+      "TOLERANCE",
+      "TOP",
+      "TRACING",
+      "TRIGGER",
+      "TRIGGERS",
+      "TTL",
+      "UNLINK",
+      "UNLOAD",
+      "UNSET",
+      "UPDATE",
+      "UPSERT",
+      "USER",
+      "USING",
+      "VALUES",
+      "VERIFY",
+      "VERSION",
+      "WATERMARK_EMBEDDING",
+      "WHERE",
+      "WITH",
+      "WITHOUT",
+      "WRITABLE",
+
+      // Data Type Keywords
+      "BOOLEAN",
+      "DOUBLE",
+      "FLOAT",
+      "INT32",
+      "INT64",
+      "TEXT",
+
+      // Encoding Type Keywords
+      "DICTIONARY",
+      "DIFF",
+      "GORILLA",
+      "PLAIN",
+      "REGULAR",
+      "RLE",
+      "TS_2DIFF",
+
+      // Compressor Type Keywords
+      "GZIP",
+      "LZ4",
+      "SNAPPY",
+      "UNCOMPRESSED",
+
+      // Privileges Keywords
+      "SET_STORAGE_GROUP",
+      "CREATE_TIMESERIES",
+      "INSERT_TIMESERIES",
+      "READ_TIMESERIES",
+      "DELETE_TIMESERIES",
+      "CREATE_USER",
+      "DELETE_USER",
+      "MODIFY_PASSWORD",
+      "LIST_USER",
+      "GRANT_USER_PRIVILEGE",
+      "REVOKE_USER_PRIVILEGE",
+      "GRANT_USER_ROLE",
+      "REVOKE_USER_ROLE",
+      "CREATE_ROLE",
+      "DELETE_ROLE",
+      "LIST_ROLE",
+      "GRANT_ROLE_PRIVILEGE",
+      "REVOKE_ROLE_PRIVILEGE",
+      "CREATE_FUNCTION",
+      "DROP_FUNCTION",
+      "CREATE_TRIGGER",
+      "DROP_TRIGGER",
+      "START_TRIGGER",
+      "STOP_TRIGGER",
+      "CREATE_CONTINUOUS_QUERY",
+      "DROP_CONTINUOUS_QUERY"
+  );
+
+  /** Provides a full list of all reserved keywords of IoTDB.
+   *
+   * @return A link to the full list of reserved keywords of IoTDB.
+   * @see <a 
href="https://iotdb.apache.org/UserGuide/V0.13.x/Reference/Keywords.html";>IoTDB 
Reserved Keywords</a>
+   */
+  public List<String> getAll(){
+    return KEYWORD_LIST;
+  }
+}
diff --git 
a/streampipes-ts-store-iotdb/src/test/java/org/apache/streampipes/ts/store/iotdb/IotDbNameSanitizerTest.java
 
b/streampipes-ts-store-iotdb/src/test/java/org/apache/streampipes/ts/store/iotdb/IotDbNameSanitizerTest.java
new file mode 100644
index 0000000000..16cbf865b2
--- /dev/null
+++ 
b/streampipes-ts-store-iotdb/src/test/java/org/apache/streampipes/ts/store/iotdb/IotDbNameSanitizerTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class IotDbNameSanitizerTest {
+
+  @Test
+  public void renameReservedKeywords() {
+    var sanitizer = new IotDbNameSanitizer();
+
+    assertEquals("runtimeName", 
sanitizer.renameReservedKeywords("runtimeName"));
+    assertEquals("CREATE_", sanitizer.renameReservedKeywords("CREATE"));
+    assertEquals("create_", sanitizer.renameReservedKeywords("create"));
+    assertEquals("Create_", sanitizer.renameReservedKeywords("Create"));
+    assertEquals("CREATE1", sanitizer.renameReservedKeywords("CREATE1"));
+  }
+}

Reply via email to