Table of Contents

Search

  1. Preface
  2. Transformations
  3. Source transformation
  4. Target transformation
  5. Access Policy transformation
  6. Aggregator transformation
  7. B2B transformation
  8. Cleanse transformation
  9. Data Masking transformation
  10. Data Services transformation
  11. Deduplicate transformation
  12. Expression transformation
  13. Filter transformation
  14. Hierarchy Builder transformation
  15. Hierarchy Parser transformation
  16. Hierarchy Processor transformation
  17. Input transformation
  18. Java transformation
  19. Java transformation API reference
  20. Joiner transformation
  21. Labeler transformation
  22. Lookup transformation
  23. Machine Learning transformation
  24. Mapplet transformation
  25. Normalizer transformation
  26. Output transformation
  27. Parse transformation
  28. Python transformation
  29. Rank transformation
  30. Router transformation
  31. Rule Specification transformation
  32. Sequence transformation
  33. Sorter transformation
  34. SQL transformation
  35. Structure Parser transformation
  36. Transaction Control transformation
  37. Union transformation
  38. Velocity transformation
  39. Verifier transformation
  40. Web Services transformation

Transformations

Transformations

Example: Use a window to calculate expiration dates

Example: Use a window to calculate expiration dates

You are a banker with information about the financial plans of two of your customers. Each plan has an associated start date.
For each customer, you want to know the expiration date for the current plan based on the activation date of the next plan. The previous plan ends when a new plan starts, so the end date for the previous plan is the start date of the next plan minus one day.
The following table lists the customer codes, the associated plan codes, and the start date of each plan:
CustomerCode
PlanCode
StartDate
C1
00001
2014-10-01
C2
00002
2014-10-01
C2
00002
2014-11-01
C1
00004
2014-10-25
C1
00001
2014-09-01
C1
00003
2014-10-10
To calculate expiration dates, complete the following tasks:
  1. Define partition and order keys.
    You configure the following window properties to partition the data by customer code and order the data by ascending start date:
    Property
    Value
    Description
    Frame
    Not specified.
    The LEAD function will access rows based on the offset argument and ignore the frame.
    Partition key
    CustomerCode
    Groups the rows according to customer code so that calculations are based on individual customers.
    Order key
    StartDate Ascending
    Arranges the data chronologically by ascending start date.
    The following table lists the data grouped by customer code and ordered by start date:
    CustomerCode
    PlanCode
    StartDate
    C1
    00001
    2014-09-01
    C1
    00002
    2014-10-01
    C1
    00003
    2014-10-10
    C1
    00004
    2014-10-25
    C2
    00001
    2014-10-01
    C2
    00002
    2014-11-01
  2. Define a window function.
    You define a LEAD function to access the subsequent row for every input.
    You configure an expression field that performs the following calculation:
    LEAD ( StartDate, 1, '01-Jan-2100' )
    For more information about the LEAD function, see
    Function Reference
    .
  3. Define an ADD_TO_DATE function.
    You use an ADD_TO_DATE function to subtract one day from the date you accessed.
    You configure an expression field that performs the following calculation:
    ADD_TO_DATE ( LEAD ( StartDate, 1, '01-Jan-2100' ), 'DD', -1, )
    By subtracting one day from the start date of the next plan, you find the end date of the current plan.
    The following table lists the end dates of each plan:
    CustomerCode
    PlanCode
    StartDate
    EndDate
    C1
    00001
    2014-09-01
    2014-09-30
    C1
    00002
    2014-10-01
    2014-10-09
    C1
    00003
    2014-10-10
    2014-10-24
    C1
    00004
    2014-10-25
    2099-12-31*
    C2
    00001
    2014-10-01
    2014-10-31
    C2
    00002
    2014-11-01
    2099-12-31*
    *The LEAD function returned the default value because these plans have not yet ended. The rows were outside the partition, so the ADD_TO_DATE function subtracted one day from 01-Jan-2100, returning 2099-12-31.

0 COMMENTS

We’d like to hear from you!