ottobackwards commented on a change in pull request #257:
URL: https://github.com/apache/plc4x/pull/257#discussion_r739582483



##########
File path: 
plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/test/java/org/apache/plc4x/nifi/util/Plc4xSchemaTest.java
##########
@@ -0,0 +1,125 @@
+package org.apache.plc4x.nifi.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avro.Schema;
+import org.apache.nifi.avro.AvroTypeUtil;
+import org.apache.nifi.serialization.record.MapRecord;
+import org.apache.plc4x.java.api.value.PlcValue;
+import org.apache.plc4x.java.spi.values.PlcBOOL;
+import org.apache.plc4x.java.spi.values.PlcBYTE;
+import org.apache.plc4x.java.spi.values.PlcBigDecimal;
+import org.apache.plc4x.java.spi.values.PlcBigInteger;
+import org.apache.plc4x.java.spi.values.PlcBitString;
+import org.apache.plc4x.java.spi.values.PlcCHAR;
+import org.apache.plc4x.java.spi.values.PlcDATE;
+import org.apache.plc4x.java.spi.values.PlcDATE_AND_TIME;
+import org.apache.plc4x.java.spi.values.PlcDINT;
+import org.apache.plc4x.java.spi.values.PlcDWORD;
+import org.apache.plc4x.java.spi.values.PlcINT;
+import org.apache.plc4x.java.spi.values.PlcLINT;
+import org.apache.plc4x.java.spi.values.PlcLREAL;
+import org.apache.plc4x.java.spi.values.PlcLTIME;
+import org.apache.plc4x.java.spi.values.PlcLWORD;
+import org.apache.plc4x.java.spi.values.PlcList;
+import org.apache.plc4x.java.spi.values.PlcNull;
+import org.apache.plc4x.java.spi.values.PlcREAL;
+import org.apache.plc4x.java.spi.values.PlcSINT;
+import org.apache.plc4x.java.spi.values.PlcSTRING;
+import org.apache.plc4x.java.spi.values.PlcStruct;
+import org.apache.plc4x.java.spi.values.PlcTIME;
+import org.apache.plc4x.java.spi.values.PlcTIME_OF_DAY;
+import org.apache.plc4x.java.spi.values.PlcUDINT;
+import org.apache.plc4x.java.spi.values.PlcUINT;
+import org.apache.plc4x.java.spi.values.PlcULINT;
+import org.apache.plc4x.java.spi.values.PlcUSINT;
+import org.apache.plc4x.java.spi.values.PlcWCHAR;
+import org.apache.plc4x.java.spi.values.PlcWORD;
+import org.junit.jupiter.api.Test;
+
+public class Plc4xSchemaTest {
+       
+    @Test
+    public void testSchemaTypesAndValues() {
+       
+       Map<String, PlcValue> map = new HashMap<String, PlcValue>();
+       Map<String, Object> mapValues = new HashMap<String, Object>();
+       //Map<String, ? extends PlcValue> map = new HashMap<String, PlcValue>();
+       
+       
+       Double plcBigDecimalOriginal = 10.0;
+       PlcValue plcBigDecimal = new PlcBigDecimal(new 
BigDecimal(plcBigDecimalOriginal));
+       map.put("plcBigDecimal", plcBigDecimal);
+       mapValues.put("plcBigDecimal", 
Plc4xCommon.normalizeValue(plcBigDecimal));
+       
+       Integer plcBigIntegerOriginal = 10;
+       PlcValue plcBigInteger = new 
PlcBigInteger(BigInteger.valueOf(plcBigIntegerOriginal));
+       map.put("plcBigInteger", plcBigInteger);
+       mapValues.put("plcBigInteger", 
Plc4xCommon.normalizeValue(plcBigInteger));
+       
+       
+       Boolean plcBooleanOriginal = false;
+       PlcValue plcBoolean = new PlcBOOL(plcBooleanOriginal);
+       map.put("plcBoolean", plcBoolean);
+       mapValues.put("plcBoolean", Plc4xCommon.normalizeValue(plcBoolean));
+       
+       byte plcByteOriginal = 1;
+       PlcValue plcByte = new PlcBYTE(plcByteOriginal);
+       map.put("plcByte", plcByte);
+       mapValues.put("plcByte", Plc4xCommon.normalizeValue(plcByte));
+       
+       /*
+       PlcBigDecimal
+               PlcBigInteger
+               PlcBitString
+               PlcBOOL
+               PlcBYTE
+               PlcCHAR
+               PlcDATE_AND_TIME
+               PlcDATE
+               PlcDINT
+               PlcDWORD
+               PlcINT
+               PlcLINT
+               PlcList
+               PlcLREAL
+               PlcLTIME
+               PlcLWORD
+               PlcNull
+               PlcREAL
+               PlcSINT
+               PlcSTRING
+               PlcStruct
+               PlcTIME_OF_DAY
+               PlcTIME
+               PlcUDINT
+               PlcUINT
+               PlcULINT
+               PlcUSINT
+               PlcWCHAR
+               PlcWORD
+               */
+       

Review comment:
       Still looking for an answer
   

##########
File path: 
plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/util/Plc4xCommon.java
##########
@@ -130,7 +131,16 @@ public static Schema createSchema(Map<String, ? extends 
PlcValue> responseDataSt
                        //}else if (entry.getValue() instanceof PlcIECValue<T>) 
{
                        //}else if (entry.getValue() instanceof 
PlcSimpleValue<T>) {
                        
-                       
+                       else if(entry.getValue() instanceof PlcList) {
+                               if(!entry.getValue().getList().isEmpty()) {
+                                       if(entry.getValue().getList().get(0) 
instanceof PlcBOOL) {
+                                               
//builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().bytesType().endUnion().noDefault();
+                                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().array().items().booleanType().endUnion().noDefault();
+                                       }
+                               } else {
+                                       
builder.name(fieldName).type().nullBuilder().endNull();
+                               }
+                       }

Review comment:
       looking for answer

##########
File path: 
plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/util/Plc4xCommon.java
##########
@@ -0,0 +1,149 @@
+package org.apache.plc4x.nifi.util;
+import java.util.Map;
+
+import org.apache.avro.Schema;
+import org.apache.avro.SchemaBuilder;
+import org.apache.avro.SchemaBuilder.FieldAssembler;
+import org.apache.plc4x.java.api.value.PlcValue;
+import org.apache.plc4x.java.spi.values.PlcBOOL;
+import org.apache.plc4x.java.spi.values.PlcBYTE;
+import org.apache.plc4x.java.spi.values.PlcBigDecimal;
+import org.apache.plc4x.java.spi.values.PlcBigInteger;
+import org.apache.plc4x.java.spi.values.PlcBitString;
+import org.apache.plc4x.java.spi.values.PlcCHAR;
+import org.apache.plc4x.java.spi.values.PlcDATE;
+import org.apache.plc4x.java.spi.values.PlcDATE_AND_TIME;
+import org.apache.plc4x.java.spi.values.PlcDINT;
+import org.apache.plc4x.java.spi.values.PlcDWORD;
+import org.apache.plc4x.java.spi.values.PlcIECValue;
+import org.apache.plc4x.java.spi.values.PlcINT;
+import org.apache.plc4x.java.spi.values.PlcLINT;
+import org.apache.plc4x.java.spi.values.PlcLREAL;
+import org.apache.plc4x.java.spi.values.PlcLTIME;
+import org.apache.plc4x.java.spi.values.PlcLWORD;
+import org.apache.plc4x.java.spi.values.PlcList;
+import org.apache.plc4x.java.spi.values.PlcNull;
+import org.apache.plc4x.java.spi.values.PlcREAL;
+import org.apache.plc4x.java.spi.values.PlcSINT;
+import org.apache.plc4x.java.spi.values.PlcSTRING;
+import org.apache.plc4x.java.spi.values.PlcSimpleValue;
+import org.apache.plc4x.java.spi.values.PlcStruct;
+import org.apache.plc4x.java.spi.values.PlcTIME;
+import org.apache.plc4x.java.spi.values.PlcTIME_OF_DAY;
+import org.apache.plc4x.java.spi.values.PlcUDINT;
+import org.apache.plc4x.java.spi.values.PlcUINT;
+import org.apache.plc4x.java.spi.values.PlcULINT;
+import org.apache.plc4x.java.spi.values.PlcUSINT;
+import org.apache.plc4x.java.spi.values.PlcValueAdapter;
+import org.apache.plc4x.java.spi.values.PlcValues;
+import org.apache.plc4x.java.spi.values.PlcWCHAR;
+import org.apache.plc4x.java.spi.values.PlcWORD;
+//TODO review remaining datatypes
+import org.apache.plc4x.java.api.value.*;
+
+
+
+public class Plc4xCommon {
+
+       /**
+        * This method could be used to infer output AVRO schema directly from 
the PlcReadResponse object. 
+        * And used directly from the RecordPlc4xWriter.writePlcReadResponse() 
method.
+        * However, to make sure output schema does not change, it is built 
from the processor configuration (variable memory addresses).
+        */
+       
+       //TODO this variable name could be configurable in the future
+       public static final String PLC4X_RECORD_TIMESTAMP_FIELD_NAME = "ts";
+       
+       //TODO please review this method so that it may be better way to map 
values 
+       public static Schema createSchema(Map<String, ? extends PlcValue> 
responseDataStructure){
+               //plc and record datatype map
+               final FieldAssembler<Schema> builder = 
SchemaBuilder.record("PlcReadResponse").namespace("any.data").fields();  
+               String fieldName = null;
+               
+               for (Map.Entry<String, ? extends PlcValue> entry : 
responseDataStructure.entrySet()) {
+                        
+                       fieldName = entry.getKey();
+                       
+                       //TODO here many PLC values are mapped to string, just 
because i am not sure about which avro datatype should be used...
+                       if (entry.getValue() instanceof PlcBigDecimal) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().floatType().endUnion().noDefault();
                              
+                       }else if (entry.getValue() instanceof PlcBigInteger) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().longType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcBitString) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcBOOL) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().booleanType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcBYTE) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcCHAR) {        
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcDATE_AND_TIME) 
{
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
     
+                       }else if (entry.getValue() instanceof PlcDATE) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcDINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcDWORD) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().intType().endUnion().noDefault();
                                
+                       }else if (entry.getValue() instanceof PlcLINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcList) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcLREAL) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcLTIME) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcLWORD) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcNull) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcREAL) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().doubleType().endUnion().noDefault();
             
+                       }else if (entry.getValue() instanceof PlcSINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().intType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcSTRING) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcStruct) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcTIME_OF_DAY) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcTIME) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcUDINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcUINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcULINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcUSINT) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcWCHAR) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
+                       }else if (entry.getValue() instanceof PlcWORD) {
+                               
builder.name(fieldName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
                             
+                       }

Review comment:
       still issue

##########
File path: 
plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/record/Plc4xReadResponseRecordSet.java
##########
@@ -0,0 +1,130 @@
+package org.apache.plc4x.nifi.record;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.avro.Schema;
+import org.apache.nifi.avro.AvroTypeUtil;
+import org.apache.nifi.serialization.record.MapRecord;
+import org.apache.nifi.serialization.record.Record;
+import org.apache.nifi.serialization.record.RecordField;
+import org.apache.nifi.serialization.record.RecordSchema;
+import org.apache.nifi.serialization.record.RecordSet;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.value.PlcValue;
+import org.apache.plc4x.nifi.util.Plc4xCommon;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class Plc4xReadResponseRecordSet implements RecordSet, Closeable {
+    private static final Logger logger = 
LoggerFactory.getLogger(Plc4xReadResponseRecordSet.class);
+    private final PlcReadResponse readResponse;
+    private final Set<String> rsColumnNames;
+    private boolean moreRows;
+
+    // TODO: review this AtomicReference?
+       // TODO: this could be enhanced checking if record schema should be 
updated (via a cache boolean, checking property values is a nifi expression 
language, etc)

Review comment:
       Still an issue

##########
File path: 
plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/test/java/org/apache/plc4x/nifi/Plc4xSourceRecordProcessorTest.java
##########
@@ -0,0 +1,104 @@
+/*
+ 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.plc4x.nifi;
+import org.apache.nifi.avro.AvroRecordSetWriter;
+import org.apache.nifi.json.JsonRecordSetWriter;
+import org.apache.nifi.json.JsonTreeReader;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.serialization.record.MockRecordWriter;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.apache.plc4x.nifi.Plc4xSourceRecordProcessor;
+import org.junit.jupiter.api.BeforeEach;
+//import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Test;
+
+

Review comment:
       Still an issue

##########
File path: 
plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/util/Plc4xCommon.java
##########
@@ -145,5 +155,100 @@ public static Schema createSchema(Map<String, ? extends 
PlcValue> responseDataSt
 
        }
        
-
+       

Review comment:
       Still looking for @chrisdutz feedback

##########
File path: 
plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/util/Plc4xCommon.java
##########
@@ -0,0 +1,149 @@
+package org.apache.plc4x.nifi.util;
+import java.util.Map;
+
+import org.apache.avro.Schema;
+import org.apache.avro.SchemaBuilder;
+import org.apache.avro.SchemaBuilder.FieldAssembler;
+import org.apache.plc4x.java.api.value.PlcValue;
+import org.apache.plc4x.java.spi.values.PlcBOOL;
+import org.apache.plc4x.java.spi.values.PlcBYTE;
+import org.apache.plc4x.java.spi.values.PlcBigDecimal;
+import org.apache.plc4x.java.spi.values.PlcBigInteger;
+import org.apache.plc4x.java.spi.values.PlcBitString;
+import org.apache.plc4x.java.spi.values.PlcCHAR;
+import org.apache.plc4x.java.spi.values.PlcDATE;
+import org.apache.plc4x.java.spi.values.PlcDATE_AND_TIME;
+import org.apache.plc4x.java.spi.values.PlcDINT;
+import org.apache.plc4x.java.spi.values.PlcDWORD;
+import org.apache.plc4x.java.spi.values.PlcIECValue;
+import org.apache.plc4x.java.spi.values.PlcINT;
+import org.apache.plc4x.java.spi.values.PlcLINT;
+import org.apache.plc4x.java.spi.values.PlcLREAL;
+import org.apache.plc4x.java.spi.values.PlcLTIME;
+import org.apache.plc4x.java.spi.values.PlcLWORD;
+import org.apache.plc4x.java.spi.values.PlcList;
+import org.apache.plc4x.java.spi.values.PlcNull;
+import org.apache.plc4x.java.spi.values.PlcREAL;
+import org.apache.plc4x.java.spi.values.PlcSINT;
+import org.apache.plc4x.java.spi.values.PlcSTRING;
+import org.apache.plc4x.java.spi.values.PlcSimpleValue;
+import org.apache.plc4x.java.spi.values.PlcStruct;
+import org.apache.plc4x.java.spi.values.PlcTIME;
+import org.apache.plc4x.java.spi.values.PlcTIME_OF_DAY;
+import org.apache.plc4x.java.spi.values.PlcUDINT;
+import org.apache.plc4x.java.spi.values.PlcUINT;
+import org.apache.plc4x.java.spi.values.PlcULINT;
+import org.apache.plc4x.java.spi.values.PlcUSINT;
+import org.apache.plc4x.java.spi.values.PlcValueAdapter;
+import org.apache.plc4x.java.spi.values.PlcValues;
+import org.apache.plc4x.java.spi.values.PlcWCHAR;
+import org.apache.plc4x.java.spi.values.PlcWORD;
+//TODO review remaining datatypes
+import org.apache.plc4x.java.api.value.*;
+
+
+
+public class Plc4xCommon {
+

Review comment:
       If we are going to javadoc, please use the correct format, document the 
parameters etc and return 




-- 
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: dev-unsubscr...@plc4x.apache.org

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


Reply via email to