This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 81e847c9d2 HOP-4126 added base64 encode and decode to calculator 
transform
     new dace8d2432 Merge pull request #1639 from bamaer/HOP-4126
81e847c9d2 is described below

commit 81e847c9d2eb4f4e4c3032cc582981bfaca9e82f
Author: Bart Maertens <[email protected]>
AuthorDate: Wed Aug 17 19:31:51 2022 +0200

    HOP-4126 added base64 encode and decode to calculator transform
---
 .../transforms/main-0011-calculator.hwf              |  5 ++++-
 .../pipeline/transforms/calculator/Calculator.java   | 20 ++++++++++++++++++++
 .../calculator/CalculatorMetaFunction.java           |  8 ++++++++
 .../calculator/messages/messages_en_US.properties    |  2 ++
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/integration-tests/transforms/main-0011-calculator.hwf 
b/integration-tests/transforms/main-0011-calculator.hwf
index e91f7d22e2..621e5305ce 100644
--- a/integration-tests/transforms/main-0011-calculator.hwf
+++ b/integration-tests/transforms/main-0011-calculator.hwf
@@ -55,11 +55,14 @@ limitations under the License.
       <type>RunPipelineTests</type>
       <attributes/>
       <test_names>
+        <test_name>
+          <name>0011-calculator-base64 UNIT</name>
+        </test_name>
         <test_name>
           <name>0011-calculator-basics UNIT</name>
         </test_name>
         <test_name>
-          <name>0011-calculator-dates UNIT</name>
+          <name>0011-calculator-basics UNIT</name>
         </test_name>
       </test_names>
       <parallel>N</parallel>
diff --git 
a/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java
 
b/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java
index d2a88d2dd8..79baf5ebe1 100644
--- 
a/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java
+++ 
b/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/Calculator.java
@@ -25,6 +25,7 @@ import org.apache.hop.core.row.IRowMeta;
 import org.apache.hop.core.row.IValueMeta;
 import org.apache.hop.core.row.RowDataUtil;
 import org.apache.hop.core.row.ValueDataUtil;
+import org.apache.hop.core.util.StringUtil;
 import org.apache.hop.core.util.Utils;
 import org.apache.hop.i18n.BaseMessages;
 import org.apache.hop.pipeline.Pipeline;
@@ -34,6 +35,7 @@ import org.apache.hop.pipeline.transform.TransformMeta;
 import 
org.apache.hop.pipeline.transforms.calculator.CalculatorMetaFunction.CalculationType;
 
 import java.util.ArrayList;
+import java.util.Base64;
 import java.util.List;
 
 /** Calculate new field values using pre-defined functions. */
@@ -615,6 +617,24 @@ public class Calculator extends 
BaseTransform<CalculatorMeta, CalculatorData> {
             calcData[index] = ValueDataUtil.remainder(metaA, dataA, metaB, 
dataB);
             resultType = targetMeta.getType();
             break;
+          case BASE64_ENCODE:
+            if(dataA != null){
+              calcData[index] = 
Base64.getEncoder().withoutPadding().encodeToString(dataA.toString().getBytes());
+            }else{
+              calcData[index] = null;
+            }
+            resultType = IValueMeta.TYPE_STRING;
+            break;
+          case BASE64_DECODE:
+            if(dataA != null){
+              byte[] tmpDecoded = Base64.getDecoder().decode(dataA.toString());
+              String tmpDecodedString = new String(tmpDecoded);
+              calcData[index] = targetMeta.convertData(metaA, 
tmpDecodedString);
+            }else{
+              calcData[index] = null;
+            }
+            resultType = targetMeta.getType();
+            break;
           default:
             throw new HopValueException(
                 BaseMessages.getString(PKG, 
"Calculator.Log.UnknownCalculationType")
diff --git 
a/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/CalculatorMetaFunction.java
 
b/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/CalculatorMetaFunction.java
index e04ac1e76a..8e3198b739 100644
--- 
a/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/CalculatorMetaFunction.java
+++ 
b/plugins/transforms/calculator/src/main/java/org/apache/hop/pipeline/transforms/calculator/CalculatorMetaFunction.java
@@ -351,6 +351,14 @@ public class CalculatorMetaFunction implements Cloneable {
         "REMAINDER",
         BaseMessages.getString(PKG, 
"CalculatorMetaFunction.CalcFunctions.Remainder"),
         IValueMeta.TYPE_NUMBER),
+    BASE64_ENCODE(
+            "BASE64_ENCODE",
+            BaseMessages.getString(PKG, 
"CalculatorMetaFunction.CalcFunctions.Base64Encode"),
+            IValueMeta.TYPE_STRING),
+    BASE64_DECODE(
+            "BASE64_DECODE",
+            BaseMessages.getString(PKG, 
"CalculatorMetaFunction.CalcFunctions.Base64Decode"),
+            IValueMeta.TYPE_STRING)
     ;
 
     private String code;
diff --git 
a/plugins/transforms/calculator/src/main/resources/org/apache/hop/pipeline/transforms/calculator/messages/messages_en_US.properties
 
b/plugins/transforms/calculator/src/main/resources/org/apache/hop/pipeline/transforms/calculator/messages/messages_en_US.properties
index 3331a94a32..f8cb6a6f14 100644
--- 
a/plugins/transforms/calculator/src/main/resources/org/apache/hop/pipeline/transforms/calculator/messages/messages_en_US.properties
+++ 
b/plugins/transforms/calculator/src/main/resources/org/apache/hop/pipeline/transforms/calculator/messages/messages_en_US.properties
@@ -141,3 +141,5 @@ CalculatorMeta.Injection.Calculation.ValueDecimal=Decimal 
symbol
 CalculatorMeta.Injection.Calculation.ValueCurrency=Currency symbol
 CalculatorMeta.Injection.Calculation.Remove=Remove from result?
 CalculatorMeta.keyword=Calculator
+CalculatorMetaFunction.CalcFunctions.Base64Encode=Base64 Encode
+CalculatorMetaFunction.CalcFunctions.Base64Decode=Base64 Decode
\ No newline at end of file

Reply via email to