Uploaded image for project: 'Pig'
  1. Pig
  2. PIG-4673

Built In UDF - REPLACE_MULTI : For a given string, search and replace all occurrences of search keys with replacement values.

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: site
    • Fix Version/s: 0.16.0
    • Component/s: piggybank
    • Labels:
    • Hadoop Flags:
      Reviewed
    • Release Note:
      Built In UDF - REPLACE_MULTI : Method which take a tuple having source string as first parameter and a map having search key and replacement values. Method will replace all occurrences of search key in source string with the replacement values.

      Description

      Lets say we have a string = 'A1B2C3D4'. Our objective is to replace A with 1, B with 2, C with 3 and D with 4 to derive 11223344 string.

      Using existing REPLACE method

      REPLACE(REPLACE(REPLACE(REPLACE('A1B2C3D4','A','1'),'B','2'),'C','3'),'D','4')

      With proposed UDF : REPLACE_MULTI method

      General Syntax :

      REPLACE_MULTI ( sourceString, [ search1#replacement1, ... ] )

      REPLACE_MULTI ( 'A1B2C3D4', [ 'A'#'1','B'#'2', 'C'#'3', 'D'#'4' ] )

      Advantage :

      1. Function calls are reduced.
      2. Ease to code and better readable.

      Let me know your thoughts/ inputs on having this UDF in Piggy Bank. Will take this up based on this.

        Attachments

        1. PIG-4673-1.patch
          11 kB
          Daniel Dai
        2. PIG-4673-fix-test-failure.patch
          10 kB
          Rohini Palaniswamy
        3. replace_multi_udf.patch
          45 kB
          Murali Rao

          Activity

            People

            • Assignee:
              murali.k.h.rao@gmail.com Murali Rao
              Reporter:
              murali.k.h.rao@gmail.com Murali Rao
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: