ijokarumawak commented on a change in pull request #3478: NIFI-6304 added trim, 
toLowerCase and toUpperCase to record path oper…
URL: https://github.com/apache/nifi/pull/3478#discussion_r286287474
 
 

 ##########
 File path: 
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/AbstractStringFunction.java
 ##########
 @@ -0,0 +1,57 @@
+/*
+ * 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.record.path.functions;
+
+import org.apache.nifi.record.path.FieldValue;
+import org.apache.nifi.record.path.RecordPathEvaluationContext;
+import org.apache.nifi.record.path.StandardFieldValue;
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+import org.apache.nifi.serialization.record.RecordField;
+import org.apache.nifi.serialization.record.RecordFieldType;
+
+import java.util.stream.Stream;
+
+public abstract class AbstractStringFunction extends RecordPathSegment {
 
 Review comment:
   To explain why we need to return multiple converted FieldValues stream with 
`trim`, `toUpperCase` or `toLowerCase`, I suggest adding following test case:
   
   ```java
       @Test
       public void testTrimArray() {
           final List<RecordField> fields = new ArrayList<>();
           final DataType dataType = new 
ArrayDataType(RecordFieldType.STRING.getDataType());
           fields.add(new RecordField("names", dataType));
   
           final RecordSchema schema = new SimpleRecordSchema(fields);
   
           final Map<String, Object> values = new HashMap<>();
           values.put("names", new String[]{"   John Smith     ", "   Jane 
Smith     "});
           final Record record = new MapRecord(schema, values);
   
           final List<FieldValue> results = 
RecordPath.compile("trim(/names[*])").evaluate(record).getSelectedFields().collect(Collectors.toList());
           assertEquals("John Smith", results.get(0).getValue());
           assertEquals("Jane Smith", results.get(1).getValue());
       }
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to