You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by mc...@apache.org on 2022/11/14 17:56:36 UTC
[hop] branch master updated: HOP-4587 : Formula - FormulaParser casts directly to the input row instead of using the getString(), getBoolean() methods.
This is an automated email from the ASF dual-hosted git repository.
mcasters 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 11fba2e935 HOP-4587 : Formula - FormulaParser casts directly to the input row instead of using the getString(), getBoolean() methods.
new e6e4fc47be Merge pull request #1784 from uraychang/master
11fba2e935 is described below
commit 11fba2e9353103a8ccff7938871fbd77a3743069
Author: Ray Chang <ur...@apache.org>
AuthorDate: Sun Nov 13 18:55:53 2022 +0800
HOP-4587 : Formula - FormulaParser casts directly to the input row instead of using the getString(), getBoolean() methods.
---
.../transforms/0042-formula-basic-computations.hpl | 107 ++++++++++++++-------
.../datasets/golden-formula-basic-computations.csv | 4 +-
.../dataset/golden-formula-basic-computations.json | 36 ++++---
.../0042-formula-basic-computations UNIT.json | 10 +-
.../transforms/formula/util/FormulaParser.java | 20 ++--
5 files changed, 113 insertions(+), 64 deletions(-)
diff --git a/integration-tests/transforms/0042-formula-basic-computations.hpl b/integration-tests/transforms/0042-formula-basic-computations.hpl
index 6e9d135f75..1c7912129a 100644
--- a/integration-tests/transforms/0042-formula-basic-computations.hpl
+++ b/integration-tests/transforms/0042-formula-basic-computations.hpl
@@ -34,8 +34,6 @@ limitations under the License.
<created_date>2022/04/29 08:04:27.209</created_date>
<modified_user>-</modified_user>
<modified_date>2022/04/29 08:04:27.209</modified_date>
- <key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
- <is_key_private>N</is_key_private>
</info>
<notepads>
</notepads>
@@ -66,6 +64,7 @@ limitations under the License.
<formula>
<field_name>percentage</field_name>
<formula>[three]%</formula>
+ <replace_field/>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<value_type>1</value_type>
@@ -73,6 +72,7 @@ limitations under the License.
<formula>
<field_name>eight</field_name>
<formula>[one]+([ten]-[three])</formula>
+ <replace_field/>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<value_type>5</value_type>
@@ -80,10 +80,19 @@ limitations under the License.
<formula>
<field_name>mixed_computation</field_name>
<formula>((([two_and_a_half]*[three])/[ten])^[three])^[two_and_a_half]</formula>
+ <replace_field/>
<value_length>-1</value_length>
<value_precision>-1</value_precision>
<value_type>1</value_type>
</formula>
+ <formula>
+ <field_name>big_num_computation</field_name>
+ <formula>[big_number]*3</formula>
+ <replace_field/>
+ <value_length>-1</value_length>
+ <value_precision>-1</value_precision>
+ <value_type>6</value_type>
+ </formula>
</formulas>
<attributes/>
<GUI>
@@ -91,6 +100,23 @@ limitations under the License.
<yloc>80</yloc>
</GUI>
</transform>
+ <transform>
+ <name>Verify</name>
+ <type>Dummy</type>
+ <description/>
+ <distribute>Y</distribute>
+ <custom_distribution/>
+ <copies>1</copies>
+ <partitioning>
+ <method>none</method>
+ <schema_name/>
+ </partitioning>
+ <attributes/>
+ <GUI>
+ <xloc>448</xloc>
+ <yloc>80</yloc>
+ </GUI>
+ </transform>
<transform>
<name>numbers grid</name>
<type>DataGrid</type>
@@ -102,67 +128,78 @@ limitations under the License.
<method>none</method>
<schema_name/>
</partitioning>
+ <data>
+ <line>
+ <item>1</item>
+ <item>3</item>
+ <item>10</item>
+ <item>2.5</item>
+ <item>123.45</item>
+ </line>
+ </data>
<fields>
<field>
- <set_empty_string>N</set_empty_string>
<length>-1</length>
- <name>one</name>
<precision>-1</precision>
+ <currency/>
+ <set_empty_string>N</set_empty_string>
+ <name>one</name>
+ <format/>
+ <group/>
+ <decimal/>
<type>Integer</type>
</field>
<field>
- <set_empty_string>N</set_empty_string>
<length>-1</length>
- <name>three</name>
<precision>-1</precision>
+ <currency/>
+ <set_empty_string>N</set_empty_string>
+ <name>three</name>
+ <format/>
+ <group/>
+ <decimal/>
<type>Integer</type>
</field>
<field>
- <set_empty_string>N</set_empty_string>
<length>-1</length>
- <name>ten</name>
<precision>-1</precision>
+ <currency/>
+ <set_empty_string>N</set_empty_string>
+ <name>ten</name>
+ <format/>
+ <group/>
+ <decimal/>
<type>Integer</type>
</field>
<field>
- <set_empty_string>N</set_empty_string>
<length>-1</length>
- <name>two_and_a_half</name>
<precision>-1</precision>
+ <currency/>
+ <set_empty_string>N</set_empty_string>
+ <name>two_and_a_half</name>
+ <format/>
+ <group/>
+ <decimal/>
<type>Number</type>
</field>
+ <field>
+ <length>-1</length>
+ <precision>-1</precision>
+ <currency/>
+ <set_empty_string>N</set_empty_string>
+ <name>big_number</name>
+ <format/>
+ <group/>
+ <decimal/>
+ <type>BigNumber</type>
+ </field>
</fields>
- <data>
- <line>
- <item>1</item>
- <item>3</item>
- <item>10</item>
- <item>2.5</item>
- </line>
- </data>
<attributes/>
<GUI>
<xloc>128</xloc>
<yloc>80</yloc>
</GUI>
</transform>
- <transform>
- <name>Verify</name>
- <type>Dummy</type>
- <description/>
- <distribute>Y</distribute>
- <custom_distribution/>
- <copies>1</copies>
- <partitioning>
- <method>none</method>
- <schema_name/>
- </partitioning>
- <attributes/>
- <GUI>
- <xloc>448</xloc>
- <yloc>80</yloc>
- </GUI>
- </transform>
<transform_error_handling>
</transform_error_handling>
<attributes/>
diff --git a/integration-tests/transforms/datasets/golden-formula-basic-computations.csv b/integration-tests/transforms/datasets/golden-formula-basic-computations.csv
index 8e077b8ccf..d28014f89a 100644
--- a/integration-tests/transforms/datasets/golden-formula-basic-computations.csv
+++ b/integration-tests/transforms/datasets/golden-formula-basic-computations.csv
@@ -1,2 +1,2 @@
-one,three,ten,two_and_a_half,percentage,eight,mixed_computation
-1,3,10,2.5,0.03,8,0.1156004369
+one,three,ten,two_and_a_half,percentage,eight,mixed_computation,big_num_computation
+1,3,10,2.5,0.03,8,0.1156004369,370.35
diff --git a/integration-tests/transforms/metadata/dataset/golden-formula-basic-computations.json b/integration-tests/transforms/metadata/dataset/golden-formula-basic-computations.json
index f2d75c73b4..be42bca45c 100644
--- a/integration-tests/transforms/metadata/dataset/golden-formula-basic-computations.json
+++ b/integration-tests/transforms/metadata/dataset/golden-formula-basic-computations.json
@@ -8,56 +8,64 @@
"field_length": -1,
"field_type": 5,
"field_precision": 0,
- "field_format": "####0;-####0",
- "field_name": "one"
+ "field_name": "one",
+ "field_format": "####0;-####0"
},
{
"field_comment": "",
"field_length": -1,
"field_type": 5,
"field_precision": 0,
- "field_format": "####0;-####0",
- "field_name": "three"
+ "field_name": "three",
+ "field_format": "####0;-####0"
},
{
"field_comment": "",
"field_length": -1,
"field_type": 5,
"field_precision": 0,
- "field_format": "####0;-####0",
- "field_name": "ten"
+ "field_name": "ten",
+ "field_format": "####0;-####0"
},
{
"field_comment": "",
"field_length": -1,
"field_type": 1,
"field_precision": -1,
- "field_format": "####0.0#########;-####0.0#########",
- "field_name": "two_and_a_half"
+ "field_name": "two_and_a_half",
+ "field_format": "####0.0#########;-####0.0#########"
},
{
"field_comment": "",
"field_length": -1,
"field_type": 1,
"field_precision": -1,
- "field_format": "####0.0#########;-####0.0#########",
- "field_name": "percentage"
+ "field_name": "percentage",
+ "field_format": "####0.0#########;-####0.0#########"
},
{
"field_comment": "",
"field_length": -1,
"field_type": 5,
"field_precision": 0,
- "field_format": "####0;-####0",
- "field_name": "eight"
+ "field_name": "eight",
+ "field_format": "####0;-####0"
},
{
"field_comment": "",
"field_length": -1,
"field_type": 1,
"field_precision": -1,
- "field_format": "####0.0#########;-####0.0#########",
- "field_name": "mixed_computation"
+ "field_name": "mixed_computation",
+ "field_format": "####0.0#########;-####0.0#########"
+ },
+ {
+ "field_comment": "",
+ "field_length": -1,
+ "field_type": 6,
+ "field_precision": -1,
+ "field_name": "big_num_computation",
+ "field_format": "#######.###"
}
],
"folder_name": ""
diff --git a/integration-tests/transforms/metadata/unit-test/0042-formula-basic-computations UNIT.json b/integration-tests/transforms/metadata/unit-test/0042-formula-basic-computations UNIT.json
index b508da8d44..2acf0b5628 100644
--- a/integration-tests/transforms/metadata/unit-test/0042-formula-basic-computations UNIT.json
+++ b/integration-tests/transforms/metadata/unit-test/0042-formula-basic-computations UNIT.json
@@ -33,6 +33,10 @@
{
"transform_field": "mixed_computation",
"data_set_field": "mixed_computation"
+ },
+ {
+ "transform_field": "big_num_computation",
+ "data_set_field": "big_num_computation"
}
],
"field_order": [
@@ -44,15 +48,15 @@
"eight",
"mixed_computation"
],
- "transform_name": "Verify",
- "data_set_name": "golden-formula-basic-computations"
+ "data_set_name": "golden-formula-basic-computations",
+ "transform_name": "Verify"
}
],
"input_data_sets": [],
"name": "0042-formula-basic-computations UNIT",
"description": "",
- "trans_test_tweaks": [],
"persist_filename": "",
+ "trans_test_tweaks": [],
"pipeline_filename": "./0042-formula-basic-computations.hpl",
"test_type": "UNIT_TEST"
}
\ No newline at end of file
diff --git a/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/util/FormulaParser.java b/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/util/FormulaParser.java
index fb59b2e254..871c64f66c 100644
--- a/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/util/FormulaParser.java
+++ b/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/util/FormulaParser.java
@@ -17,10 +17,12 @@
package org.apache.hop.pipeline.transforms.formula.util;
+import org.apache.hop.core.exception.HopValueException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.pipeline.transforms.formula.FormulaMetaFunction;
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
@@ -64,7 +66,7 @@ public class FormulaParser {
}
}
- public CellValue getFormulaValue() {
+ public CellValue getFormulaValue() throws HopValueException {
String parsedFormula = formula;
int fieldIndex = 65;
int colIndex = 0;
@@ -76,21 +78,19 @@ public class FormulaParser {
IValueMeta fieldMeta = rowMeta.getValueMeta(fieldPosition);
if (dataRow[fieldPosition] != null) {
if (fieldMeta.isBoolean()) {
- cell.setCellValue((Boolean) dataRow[fieldPosition]);
+ cell.setCellValue(rowMeta.getBoolean(dataRow, fieldPosition));
} else if (fieldMeta.isBigNumber()) {
- cell.setCellValue((RichTextString) dataRow[fieldPosition]);
+ cell.setCellValue(new HSSFRichTextString(rowMeta.getString(dataRow, fieldPosition)));
} else if (fieldMeta.isDate()) {
- cell.setCellValue((Date) dataRow[fieldPosition]);
+ cell.setCellValue(rowMeta.getDate(dataRow, fieldPosition));
} else if (fieldMeta.isInteger()) {
- cell.setCellValue((Long) dataRow[fieldPosition]);
+ cell.setCellValue(rowMeta.getInteger(dataRow, fieldPosition));
} else if (fieldMeta.isNumber()) {
- cell.setCellValue((Double) dataRow[fieldPosition]);
+ cell.setCellValue(rowMeta.getNumber(dataRow, fieldPosition));
} else if (fieldMeta.isString()) {
- cell.setCellValue((String) dataRow[fieldPosition]);
- } else if (fieldMeta.getType() == IValueMeta.TYPE_TIMESTAMP) {
- cell.setCellValue((Timestamp) dataRow[fieldPosition]);
+ cell.setCellValue(rowMeta.getString(dataRow, fieldPosition));
} else {
- cell.setCellValue((String) dataRow[fieldPosition]);
+ cell.setCellValue(rowMeta.getString(dataRow, fieldPosition));
}
}