You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/12/14 06:43:25 UTC

[GitHub] [nifi] lizhizhou commented on a diff in pull request #6416: NIFI-10234 implement PutIoTDB

lizhizhou commented on code in PR #6416:
URL: https://github.com/apache/nifi/pull/6416#discussion_r1048072863


##########
nifi-nar-bundles/nifi-iotdb-bundle/nifi-iotdb-processors/src/test/java/org/apache/nifi/processors/AbstractIoTDBUT.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * 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.nifi.processors;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.processors.model.IoTDBSchema;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.model.ValidationResult;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AbstractIoTDBUT {
+    private static TestAbstractIoTDBProcessor processor;
+
+    @Before
+    public void init() {
+        processor = new TestAbstractIoTDBProcessor();
+    }
+
+    @Test
+    public void testValidateSchemaAttribute() {
+        // normal schema
+        String schemaAttribute =
+                "{\n"
+                        + "\t\"timeName\": \"Time\",\n"
+                        + "\t\"fields\": [{\n"
+                        + "\t\t\"tsName\": \"s1\",\n"
+                        + "\t\t\"dataType\": \"INT32\",\n"
+                        + "\t\t\"encoding\": \"RLE\"\n"
+                        + "\t}, {\n"
+                        + "\t\t\"tsName\": \"s2\",\n"
+                        + "\t\t\"dataType\": \"DOUBLE\",\n"
+                        + "\t\t\"encoding\": \"PLAIN\"\n"
+                        + "\t}]\n"
+                        + "}";
+
+        ValidationResult result = processor.validateSchemaAttribute(schemaAttribute);
+         assertTrue(result.getKey());
+         assertEquals(null, result.getValue());
+
+        // schema with wrong field
+        schemaAttribute =
+                "{\n"
+                        + "\t\"time\": \"Time\",\n"
+                        + "\t\"fields\": [{\n"
+                        + "\t\t\"tsName\": \"s1\",\n"
+                        + "\t\t\"dataType\": \"INT32\",\n"
+                        + "\t\t\"encoding\": \"RLE\"\n"
+                        + "\t}, {\n"
+                        + "\t\t\"tsName\": \"s2\",\n"
+                        + "\t\t\"dataType\": \"DOUBLE\",\n"
+                        + "\t\t\"encoding\": \"PLAIN\"\n"
+                        + "\t}]\n"
+                        + "}";
+        result = processor.validateSchemaAttribute(schemaAttribute);
+        String exceptedMsg = "The JSON of schema must contain `timeName` and `fields`";
+
+         assertEquals(false, result.getKey());
+         assertEquals(exceptedMsg, result.getValue());
+
+        // schema without tsName
+        schemaAttribute =
+                "{\n"
+                        + "\t\"timeName\": \"Time\",\n"
+                        + "\t\"fields\": [{\n"
+                        + "\t\t\"dataType\": \"INT32\",\n"
+                        + "\t\t\"encoding\": \"RLE\"\n"
+                        + "\t}, {\n"
+                        + "\t\t\"tsName\": \"s2\",\n"
+                        + "\t\t\"dataType\": \"DOUBLE\",\n"
+                        + "\t\t\"encoding\": \"PLAIN\"\n"
+                        + "\t}]\n"
+                        + "}";
+        result = processor.validateSchemaAttribute(schemaAttribute);
+        exceptedMsg = "`tsName` or `dataType` has not been set";
+
+        assertEquals(false, result.getKey());
+        assertEquals(exceptedMsg, result.getValue());
+
+        // schema without data type
+        schemaAttribute =
+                "{\n"
+                        + "\t\"timeName\": \"Time\",\n"
+                        + "\t\"fields\": [{\n"
+                        + "\t\t\"tsName\": \"s1\",\n"
+                        + "\t\t\"encoding\": \"RLE\"\n"
+                        + "\t}, {\n"
+                        + "\t\t\"tsName\": \"s2\",\n"
+                        + "\t\t\"dataType\": \"DOUBLE\",\n"
+                        + "\t\t\"encoding\": \"PLAIN\"\n"
+                        + "\t}]\n"
+                        + "}";
+        result = processor.validateSchemaAttribute(schemaAttribute);
+        exceptedMsg = "`tsName` or `dataType` has not been set";
+
+        assertEquals(false, result.getKey());
+        assertEquals(exceptedMsg, result.getValue());
+
+        // schema with wrong data type
+        schemaAttribute =
+                "{\n"
+                        + "\t\"timeName\": \"Time\",\n"
+                        + "\t\"fields\": [{\n"
+                        + "\t\t\"tsName\": \"s1\",\n"
+                        + "\t\t\"dataType\": \"INT\",\n"
+                        + "\t\t\"encoding\": \"RLE\"\n"
+                        + "\t}, {\n"
+                        + "\t\t\"tsName\": \"s2\",\n"
+                        + "\t\t\"dataType\": \"DOUBLE\",\n"
+                        + "\t\t\"encoding\": \"PLAIN\"\n"
+                        + "\t}]\n"
+                        + "}";
+
+        result = processor.validateSchemaAttribute(schemaAttribute);
+        exceptedMsg =
+                "Unknown `dataType`: INT. The supported dataTypes are [FLOAT, INT64, INT32, TEXT, DOUBLE, BOOLEAN]";
+
+        assertEquals(false, result.getKey());
+        assertEquals(exceptedMsg, result.getValue());
+
+        // schema with wrong key
+        schemaAttribute =
+                "{\n"
+                        + "\t\"timeName\": \"Time\",\n"
+                        + "\t\"fields\": [{\n"
+                        + "\t\t\"tsName\": \"s1\",\n"
+                        + "\t\t\"dataType\": \"INT32\",\n"
+                        + "\t\t\"encode\": \"RLE\"\n"
+                        + "\t}, {\n"
+                        + "\t\t\"tsName\": \"s2\",\n"
+                        + "\t\t\"dataType\": \"DOUBLE\",\n"
+                        + "\t\t\"encoding\": \"PLAIN\"\n"
+                        + "\t}]\n"
+                        + "}";
+
+        result = processor.validateSchemaAttribute(schemaAttribute);
+        exceptedMsg = "Unknown property or properties: [encode]";
+
+        assertEquals(false, result.getKey());
+        assertEquals(exceptedMsg, result.getValue());
+
+        // schema with wrong compression type
+        schemaAttribute =
+                "{\n"
+                        + "\t\"timeName\": \"Time\",\n"
+                        + "\t\"fields\": [{\n"
+                        + "\t\t\"tsName\": \"s1\",\n"
+                        + "\t\t\"dataType\": \"INT32\",\n"
+                        + "\t\t\"encoding\": \"RLE\",\n"
+                        + "\t\t\"compressionType\": \"ZIP\"\n"
+                        + "\t}, {\n"
+                        + "\t\t\"tsName\": \"s2\",\n"
+                        + "\t\t\"dataType\": \"DOUBLE\",\n"
+                        + "\t\t\"encoding\": \"PLAIN\",\n"
+                        + "\t\t\"compressionType\": \"GZIP\"\n"
+                        + "\t}]\n"
+                        + "}";
+
+        result = processor.validateSchemaAttribute(schemaAttribute);
+        exceptedMsg =
+                "Unknown `compressionType`: ZIP, The supported compressionType are [LZO, PAA, SDT, UNCOMPRESSED, PLA, LZ4, GZIP, SNAPPY]";
+
+        assertEquals(false, result.getKey());
+        assertEquals(exceptedMsg, result.getValue());
+    }
+
+    @Test
+    public void testParseSchema() {
+        ArrayList<String> filedNames =
+                new ArrayList<String>() {
+                    {
+                        add("root.sg1.d1.s1");
+                        add("root.sg1.d1.s2");
+                        add("root.sg1.d2.s1");
+                    }
+                };
+        Map<String, List<String>> deviceMeasurementMap = processor.parseSchema(filedNames);
+        HashMap<String, List<String>> exceptedMap =
+                new HashMap<String, List<String>>() {
+                    {
+                        put(
+                                "root.sg1.d1",
+                                new ArrayList<String>() {
+                                    {
+                                        add("s1");
+                                        add("s2");
+                                    }
+                                });

Review Comment:
   Resolved



-- 
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: issues-unsubscribe@nifi.apache.org

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