Perform Lookups When your Target Values are Padded

22 December 2021
KingswaySoft Team

In our ETL development, we don't always receive the data in the exact format that we expect it to be. For instance, there might be cases that the incoming data is a string value while we expect an integer, or in some other cases, there are special characters in it we didn’t realize, or otherwise there might be unexpected whitespaces. This last case is the focus of this blog post. For example, you might think a value is ‘StringValue’, whereas it is actually ‘   StringValue’, or ‘StringValue   ‘, with a few leading or trailing spaces. This can occur when the data source forces a certain number of characters in a column, and pads the value in there with spaces to fill up the missing number of characters, and it is not very obvious when this happens during the ETL development, and it can cause frustrations. If we are counting on being able to match values between a source and these padded target values for lookup purpose, we will run into difficulties. Cleaning up the padded whitespaces would be the ideal solution if they are not part of the data, however, that may not always be the practical solution in an already defined ETL process, particularly when the padded values are saved in the target system. In this blog post, we will discuss the use case, and we will show you how to use our Premium Lookup component to perform the lookup without having to make actual changes to the source or target system data.

Use case

Let’s look at what might happen if we try to do a lookup in this case. For this purpose, we will use our Premium Lookup. As our source, we have a single record with a string field, firstname_unpadded = ‘Testctc’. In our lookup target, the value is ‘        Testctc’, which has several leading spaces. We feed our source and our lookup target into the Premium Lookup component and configure the Matched Rows and Unmatched Rows output.

DataFlow_PremiumLookup.PNG

To configure the Premium Lookup component, we simply map the input field to the lookup field. Here we have mapped the unpadded input field to the padded lookup, and keep the default “Match Type” as “Exact Match”:

Premium Lookup - General - Unpadded Source - Exact.png

In the Columns page, we can select these two columns to pass on:

Premium Lookup - Columns - Unpadded Source.png

When we execute this Data Flow now, we see that the values don’t match, as expected. The record is in the “Unmatched Rows” output.

DataFlow_UnPaddedResult.png

In this case, there are a couple of options that we will look at:  Removing padding from target, or Exact Lookup with Whitespace trimmed.

  • Remove padding from Target values - This solution assumes that the target values should not be padded, and would be equivalent to cleaning your data, whether it be in a database, a file, some ERP system, etc. You can use your method of choice for removing the padded whitespace. This is the recommended solution, assuming that the configuration allows for the padding to be trimmed and that the padding does not belong.
  • Exact Lookup with Whitespace trimmed - If for some reason you cannot trim the actual target values, then you can use the Premium Lookup component to compare the input to trimmed versions of the target values. For this we again use “Exact Match”, but this time click on the “Comparison Setting” ellipsis to open up the Settings window.  Here select “Trim Leading and Trailing Whitespace” and click OK.
    Premium Lookup - General - Unpadded Source - ExactWithTrim.png

When using the above feature shown in the second option, the Premium Lookup component will perform an in-memory trimming of the source data and target data before comparison. When we execute the package, the record will be matched regardless whether the source data or target data is padded or not. You can see that the unpadded firstname from the input Source was successfully matched to the padded target firstname after we have selected the “Trim Leading and Trailing Whitespace” option. This has greatly simplified the ETL process without having to actually modify the source or the target system data.

DataFlow_UnPaddedResult.png

Conclusion

The Premium Lookup component that comes along with our SSIS Productivity Pack can be used in many such scenarios where the data needs to be matched, but has anomalies in it. There are different match types that could be used for this purpose. You could merge and join the inputs and have a control on how exactly the match needs to be done, and what outputs are to be produced.

Archive

October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags