Skip to content

Commit

Permalink
Merge pull request #2911 from sramazzina/2908
Browse files Browse the repository at this point in the history
fix #2908
  • Loading branch information
hansva committed May 17, 2023
2 parents 8c29029 + 393d7e7 commit 6d3853a
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ integration-tests/spreadsheet/files/exel-multi-part_2.xlsx
integration-tests/spreadsheet/files/exel-multi-part_3.xlsx

integration-tests/spreadsheet/files/exel-multi-part_4.xlsx

integration-tests/json/output
146 changes: 146 additions & 0 deletions integration-tests/json/0005-enhanced-json-output-empty-stream.hpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?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>0005-enhanced-json-output-empty-stream</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>Generate rows</from>
<to>Enhanced JSON Output</to>
<enabled>Y</enabled>
</hop>
</order>
<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>writetofile</operation_type>
<use_arrays_with_single_instance>N</use_arrays_with_single_instance>
<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>some</name>
<element>some</element>
<json_fragment>N</json_fragment>
<is_without_enclosing>N</is_without_enclosing>
<remove_if_blank>N</remove_if_blank>
</field>
<field>
<name>metadata</name>
<element>metadata</element>
<json_fragment>N</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>Generate rows</name>
<type>RowGenerator</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<length>-1</length>
<name>some</name>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
<type>String</type>
</field>
<field>
<length>-1</length>
<name>metadata</name>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
<type>String</type>
</field>
</fields>
<interval_in_ms>5000</interval_in_ms>
<last_time_field>FiveSecondsAgo</last_time_field>
<limit>0</limit>
<never_ending>N</never_ending>
<row_time_field>now</row_time_field>
<attributes/>
<GUI>
<xloc>96</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,92 @@
<?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-0005-enhanced-json-output-empty-stream</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>0005-enhanced-json-output-empty-stream.hpl</name>
<description/>
<type>PIPELINE</type>
<attributes/>
<add_date>N</add_date>
<add_time>N</add_time>
<clear_files>N</clear_files>
<clear_rows>N</clear_rows>
<create_parent_folder>N</create_parent_folder>
<exec_per_row>N</exec_per_row>
<filename>${PROJECT_HOME}/0005-enhanced-json-output-empty-stream.hpl</filename>
<logext/>
<logfile/>
<loglevel>Basic</loglevel>
<parameters>
<pass_all_parameters>Y</pass_all_parameters>
</parameters>
<params_from_previous>N</params_from_previous>
<run_configuration>local</run_configuration>
<set_append_logfile>N</set_append_logfile>
<set_logfile>N</set_logfile>
<wait_until_finished>Y</wait_until_finished>
<parallel>N</parallel>
<xloc>304</xloc>
<yloc>64</yloc>
<attributes_hac/>
</action>
</actions>
<hops>
<hop>
<from>START</from>
<to>0005-enhanced-json-output-empty-stream.hpl</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
Expand Up @@ -83,13 +83,11 @@ public boolean init() {
// Init global json items array only if output to file is needed
data.jsonItems = new ArrayList<>();
data.isWriteToFile = true;
if (!meta.isDoNotOpenNewFileInit()) {
if (data.isWriteToFile && !openNewFile()) {
logError(BaseMessages.getString(PKG, "JsonOutput.Error.OpenNewFile", buildFilename()));
stopAll();
setErrors(1);
return false;
}
if (!meta.isDoNotOpenNewFileInit() && data.isWriteToFile && !openNewFile()) {
logError(BaseMessages.getString(PKG, "JsonOutput.Error.OpenNewFile", buildFilename()));
stopAll();
setErrors(1);
return false;
}
}

Expand All @@ -107,7 +105,7 @@ public boolean processRow() throws HopException {
if (r == null) {
// no more input to be expected...
// Let's output the remaining unsafe data
outPutRow(prevRow);
outputRow(prevRow);
// only attempt writing to file when the first row is not empty
if (data.isWriteToFile && !first) writeJsonFile();
setOutputDone();
Expand All @@ -133,7 +131,7 @@ public void manageRowItems(Object[] row) throws HopException {
if (!sameGroup(prevRow, row) && data.jsonKeyGroupItems.size() > 0) {
// Output the new row
logDebug("Record Num: " + data.nrRow + " - Generating JSON chunk");
outPutRow(prevRow);
outputRow(prevRow);
data.jsonKeyGroupItems = new ArrayList<>();
}

Expand Down Expand Up @@ -190,7 +188,8 @@ else if (!outputField.isRemoveIfBlank())
itemNode.put(getJsonAttributeName(outputField), jsonNode);
}
} catch (IOException e) {
throw new HopTransformException(BaseMessages.getString(PKG, "JsonOutput.Error.Casting"), e);
throw new HopTransformException(
BaseMessages.getString(PKG, "JsonOutput.Error.Casting"), e);
}
} else {
itemNode.put(getJsonAttributeName(outputField), value);
Expand Down Expand Up @@ -228,7 +227,7 @@ private String getKeyJsonAttributeName(JsonOutputKeyField field) {
}

@SuppressWarnings("unchecked")
private void outPutRow(Object[] rowData) throws HopException {
private void outputRow(Object[] rowData) throws HopException {
// We can now output an object
ObjectNode globalItemNode = null;

Expand Down
Loading

0 comments on commit 6d3853a

Please sign in to comment.