Forum Discussion
Can you clarify in what way they are different?
- akidave8 years agoEmployee
A document should not be modified once it has been written to the output view. Making a copy of the document avoids issues. Change the loop to create a new wrapper Map
for item in sourceTables: wrapper = java.util.HashMap(in_doc) wrapper['query'] = "update iods_staging.{} set record_inserted = true;".format(item) self.output.write(wrapper)
- aditya_sharma8 years agoNew Contributor III
Hi Akidave,
Thanks you so much for your solution. However, I would really appreciate if you could explain me more why we should not modify the document once it has been written to the output view.
Thanks again.
Aditya
- akidave8 years agoEmployee
If a snap writes a document to output view and then modifies the document, the downstream snap might pick up the updated document value, not the document originally written. For performance reasons, a deep copy is not done automatically when the document is written to the output view.
Creating a Map in the script works in this case since the Script is changing only the top level keys. If the Script was changing the contents of the nested map, then a deep copy would be required in the Script
- aditya_sharma8 years agoNew Contributor III
Hi Dmiller,
Please find below output from script snap and mapper output. Mapper output has two update statements same which is incorrect, it has to be same like script.
Script Snap:
“query”: “update iods_staging.stg_sf_account_dim_institution set record_inserted = true;”
“query”: “update iods_staging.stg_sf_accountdistict_dim_institution set record_inserted = true;”
“query”: “update iods_staging.stg_sf_recordtype_dim_institution set record_inserted = true;”Mapper Output:
“query”
“update iods_staging.stg_sf_account_dim_institution set record_inserted = true;”
“update iods_staging.stg_sf_recordtype_dim_institution set record_inserted = true;”
“update iods_staging.stg_sf_recordtype_dim_institution set record_inserted = true;”Thanks
Aditya- dmiller8 years agoFormer Employee
Is there a reason you need the Mapper after the Script Snap? Do you plan to modify other information?
If so and there are items like query that should not be modified, then select the Pass through option and don’t specify them in the mapping table.
- aditya_sharma8 years agoNew Contributor III
Hi Dmiller,
In my real mapping I am not using mapper after script, mapper is used to show the output after validation complete.
Thanks
Aditya