mgaido91 commented on a change in pull request #3615: NIFI-6500 Support Padding 
functions in Expression Language
URL: https://github.com/apache/nifi/pull/3615#discussion_r309410111
 
 

 ##########
 File path: 
nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/PaddingEvaluator.java
 ##########
 @@ -0,0 +1,72 @@
+/*
+ * 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.attribute.expression.language.evaluation.functions;
+
+import org.apache.nifi.attribute.expression.language.evaluation.Evaluator;
+import org.apache.nifi.attribute.expression.language.evaluation.EvaluatorState;
+import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
+import 
org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult;
+import 
org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator;
+
+import java.util.Map;
+
+abstract class PaddingEvaluator extends StringEvaluator {
+
+    public static final char DEFAULT_PADDING_CHARACTER = '_';
+
+    private final Evaluator<String> subject;
+    private final Evaluator<Long> desiredLength;
+    private final Evaluator<String> pad;
+
+    PaddingEvaluator( final Evaluator<String> subject,
+                             final Evaluator<Long> desiredLength,
+                             final Evaluator<String> pad) {
+        this.subject = subject;
+        this.desiredLength = desiredLength;
+        this.pad = pad;
+    }
+
+    @Override
+    public QueryResult<String> evaluate(final Map<String, String> attributes, 
final EvaluatorState context) {
+        final String subjectValue = subject.evaluate(attributes, 
context).getValue();
+        if (subjectValue == null) {
+            return new StringQueryResult(null);
+        }
+        final Long desiredLengthValue = desiredLength.evaluate(attributes, 
context).getValue();
+        if(desiredLengthValue == null || desiredLengthValue > 
Integer.MAX_VALUE) {
 
 Review comment:
   I think we should just return the string as it is. Overflow is not handled 
in other expression language functions, and when overflow happens, a negative 
value is returned. So I think it is fine to behave as for negative values in 
case of overflow. At least, it is consistent with other EL functions.

----------------------------------------------------------------
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