Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add name sanitizer for IotDB #2827

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
84 changes: 84 additions & 0 deletions streampipes-ts-store-iotdb/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Loading