Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5451

Implement LPAD() and RPAD() functions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.33.0
    • None

    Description

      Adding in LPAD() and RPAD()for BIG_QUERY as per https://g3doc.corp.google.com/company/teams/googlesql/reference/string_functions.md?cl=head#lpad and https://g3doc.corp.google.com/company/teams/googlesql/reference/string_functions.md?cl=head#rpad describes

       

      LPAD(original_value, return_length[, pattern])

      Returns a STRING or BYTES value that consists of original_value prepended with pattern. The return_length is an INT64 that specifies the length of the returned value. If original_value is of type BYTESreturn_length is the number of bytes. If original_value is of type STRINGreturn_length is the number of characters.

      The default value of pattern is a blank space.

      Both original_value and pattern must be the same data type.

      If return_length is less than or equal to the original_value length, this function returns the original_value value, truncated to the value of return_length. For example, LPAD('hello world', 7); returns 'hello w'.

      If original_valuereturn_length, or pattern is NULL, this function returns NULL.

      This function returns an error if:

      • return_length is negative
      • pattern is empty

       

      LPAD Examples:

      LPAD('12345', 8, 'a') -> "aaa12345"

      LPAD('12345', 8) -> "   12345"

      LPAD('12345', 8, 'ab') -> "aba12345"

      LPAD('12345', 8, 'a') -> "aaa12345"

      LPAD('12345', -3) -> error

      LPAD('12345', 3, '') -> error

       


       

      RPAD(original_value, return_length[, pattern])

       

      Returns a STRING or BYTES value that consists of original_value appended with pattern. The return_length parameter is an INT64 that specifies the length of the returned value. If original_value is BYTESreturn_length is the number of bytes. If original_value is STRINGreturn_length is the number of characters.

      The default value of pattern is a blank space.

      Both original_value and pattern must be the same data type.

      If return_length is less than or equal to the original_value length, this function returns the original_value value, truncated to the value of return_length. For example, RPAD('hello world', 7); returns 'hello w'.

      If original_valuereturn_length, or pattern is NULL, this function returns NULL.

      This function returns an error if:

      • return_length is negative
      • pattern is empty

       

      RPAD Examples:

      RPAD('12345', 8, 'a') -> "12345aaa"

      RPAD('12345', 8) -> "12345.  "

      RPAD('12345', 8, 'ab') -> "12345aba"

      RPAD('12345', 8, 'a') -> "12345aaa"

      RPAD('12345', -3) -> error

      RPAD('12345', 3, '') -> error

      Attachments

        Issue Links

          Activity

            People

              oliverlee Oliver Lee
              oliverlee Oliver Lee
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m