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

SPRINTF function to format strings using a printf-style template

VotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Hide
      The SPRINTF function formats strings with printf-style templates: SPRINTF('%6s|%-8s|%2$,10d %2$8x %3$1TFT%<tT%<tz', 'yay', 1234567, ToMilliSeconds(CurrentTime())) => ' yay|1234567 | 1,234,567 12d687 2014-05-15T08:22:26-0500'.
      Show
      The SPRINTF function formats strings with printf-style templates: SPRINTF('%6s|%-8s|%2$,10d %2$8x %3$1TFT%<tT%<tz', 'yay', 1234567, ToMilliSeconds(CurrentTime())) => ' yay|1234567 | 1,234,567 12d687 2014-05-15T08:22:26-0500'.

    Description

      Pig should provide a function to format output using java.util.Formatter (printf-style) templates.

      SPRINTF(
          '%6s|%-8s|%2$,10d %2$8x %3$1TFT%<tT%<tz', 
          'yay', 1234567, ToMilliSeconds(CurrentTime()))
      --  '   yay|1234567 | 1,234,567   12d687 2014-05-15T08:22:26-0500'
      

      I've written a UDF implementing SPRINTF(...), a variable-arguments function that accepts a string and any number of objects and returns a string. It counts on the java.util.Formatter to do its type-conversion, which works quite well. It doesn't appreciates pig's Dates for datetime formats ('%t'), but is quite happy to use epoch milliseconds for these as shown above.

      Patch forthcoming.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mrflip Flip Kromer
            mrflip Flip Kromer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment