Skip to content

Commit

Permalink
Ignore isblank check when looking at json fragments, fixes apache#3577
Browse files Browse the repository at this point in the history
add test
  • Loading branch information
hansva committed Oct 29, 2024
1 parent c77da04 commit b72ab84
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 1 deletion.
185 changes: 185 additions & 0 deletions integration-tests/json/0006-enhanced-json-output-json-fragment.hpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<pipeline>
<info>
<name>0006-enhanced-json-output-json-fragment</name>
<name_sync_with_filename>Y</name_sync_with_filename>
<description/>
<extended_description/>
<pipeline_version/>
<pipeline_type>Normal</pipeline_type>
<pipeline_status>0</pipeline_status>
<parameters>
</parameters>
<capture_transform_performance>N</capture_transform_performance>
<transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
<transform_performance_capturing_size_limit/>
<created_user/>
<created_date>2014/03/03 20:27:52.905</created_date>
<modified_user>-</modified_user>
<modified_date>2008/05/14 08:28:56.657</modified_date>
</info>
<notepads>
</notepads>
<order>
<hop>
<from>Data grid</from>
<to>Enhanced JSON Output</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Enhanced JSON Output</from>
<to>Dummy (do nothing)</to>
<enabled>Y</enabled>
</hop>
</order>
<transform>
<name>Data grid</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<data>
<line>
<item>value1</item>
<item>value2</item>
<item>{"name":"John", "age":30, "car":null}</item>
</line>
</data>
<fields>
<field>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
<name>part_1</name>
<type>String</type>
</field>
<field>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
<name>part_2</name>
<type>String</type>
</field>
<field>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
<name>json_fragment</name>
<type>String</type>
</field>
</fields>
<attributes/>
<GUI>
<xloc>144</xloc>
<yloc>80</yloc>
</GUI>
</transform>
<transform>
<name>Enhanced JSON Output</name>
<type>EnhancedJsonOutput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<outputValue>outputValue</outputValue>
<jsonBloc>result</jsonBloc>
<operation_type>outputvalue</operation_type>
<use_arrays_with_single_instance>N</use_arrays_with_single_instance>
<use_single_item_per_group>N</use_single_item_per_group>
<json_prittified>N</json_prittified>
<encoding>UTF-8</encoding>
<addtoresult>N</addtoresult>
<file>
<name>${PROJECT_HOME}/output/testfile.js</name>
<split_output_after>0</split_output_after>
<extention>json</extention>
<append>N</append>
<split>N</split>
<haspartno>N</haspartno>
<add_date>N</add_date>
<add_time>N</add_time>
<create_parent_folder>Y</create_parent_folder>
<doNotOpenNewFileInit>N</doNotOpenNewFileInit>
</file>
<additional_fields>
<json_size_field/>
</additional_fields>
<key_fields>
</key_fields>
<fields>
<field>
<name>part_1</name>
<element>part_1</element>
<json_fragment>N</json_fragment>
<is_without_enclosing>N</is_without_enclosing>
<remove_if_blank>N</remove_if_blank>
</field>
<field>
<name>part_2</name>
<element>part_2</element>
<json_fragment>N</json_fragment>
<is_without_enclosing>N</is_without_enclosing>
<remove_if_blank>N</remove_if_blank>
</field>
<field>
<name>json_fragment</name>
<element>json_fragment</element>
<json_fragment>Y</json_fragment>
<is_without_enclosing>N</is_without_enclosing>
<remove_if_blank>N</remove_if_blank>
</field>
</fields>
<attributes/>
<GUI>
<xloc>384</xloc>
<yloc>80</yloc>
</GUI>
</transform>
<transform>
<name>Dummy (do nothing)</name>
<type>Dummy</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<attributes/>
<GUI>
<xloc>576</xloc>
<yloc>80</yloc>
</GUI>
</transform>
<transform_error_handling>
</transform_error_handling>
<attributes/>
</pipeline>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
outputValue
"{""result"":{""part_1"":""value1"",""part_2"":""value2"",""json_fragment"":{""name"":""John"",""age"":30,""car"":null}}}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<workflow>
<name>main-0006-enhanced-json-output-json-fragment</name>
<name_sync_with_filename>Y</name_sync_with_filename>
<description/>
<extended_description/>
<workflow_version/>
<created_user>-</created_user>
<created_date>2020/12/09 13:24:02.438</created_date>
<modified_user>-</modified_user>
<modified_date>2020/12/09 13:24:02.438</modified_date>
<parameters>
</parameters>
<actions>
<action>
<name>START</name>
<description/>
<type>SPECIAL</type>
<attributes/>
<DayOfMonth>1</DayOfMonth>
<hour>12</hour>
<intervalMinutes>60</intervalMinutes>
<intervalSeconds>0</intervalSeconds>
<minutes>0</minutes>
<repeat>N</repeat>
<schedulerType>0</schedulerType>
<weekDay>1</weekDay>
<parallel>N</parallel>
<xloc>64</xloc>
<yloc>64</yloc>
<attributes_hac/>
</action>
<action>
<name>Run Pipeline Unit Tests</name>
<description/>
<type>RunPipelineTests</type>
<attributes/>
<test_names>
<test_name>
<name>0006-enhanced-json-output-json-fragment UNIT</name>
</test_name>
</test_names>
<parallel>N</parallel>
<xloc>320</xloc>
<yloc>64</yloc>
<attributes_hac/>
</action>
</actions>
<hops>
<hop>
<from>START</from>
<to>Run Pipeline Unit Tests</to>
<enabled>Y</enabled>
<evaluation>Y</evaluation>
<unconditional>Y</unconditional>
</hop>
</hops>
<notepads>
</notepads>
<attributes/>
</workflow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"base_filename": "golden-enhanced-json-fragment.csv",
"name": "golden-enhanced-json-fragment",
"description": "",
"dataset_fields": [
{
"field_comment": "",
"field_length": -1,
"field_type": 2,
"field_precision": -1,
"field_name": "outputValue",
"field_format": ""
}
],
"folder_name": "${HOP_DATASETS_FOLDER}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"variableValues": [],
"database_replacements": [],
"autoOpening": true,
"basePath": "",
"golden_data_sets": [
{
"field_mappings": [
{
"transform_field": "outputValue",
"data_set_field": "outputValue"
}
],
"field_order": [
"outputValue"
],
"data_set_name": "golden-enhanced-json-fragment",
"transform_name": "Dummy (do nothing)"
}
],
"input_data_sets": [],
"name": "0006-enhanced-json-output-json-fragment UNIT",
"description": "",
"persist_filename": "",
"trans_test_tweaks": [],
"pipeline_filename": "./0006-enhanced-json-output-json-fragment.hpl",
"test_type": "UNIT_TEST"
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void manageRowItems(Object[] row) throws HopException {
break;
default:
String value = data.inputRowMeta.getString(row, data.fieldIndexes[i]);
if (putBlank) {
if (putBlank && !outputField.isJSONFragment()) {
itemNode.put(jsonAttributeName, value);
} else if (value != null) {
if (outputField.isJSONFragment()) {
Expand Down

0 comments on commit b72ab84

Please sign in to comment.