[ 
https://issues.apache.org/jira/browse/BEAM-5965?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Work on BEAM-5965 stopped by Rui Wang.
--------------------------------------
> RPAD
> ----
>
>                 Key: BEAM-5965
>                 URL: https://issues.apache.org/jira/browse/BEAM-5965
>             Project: Beam
>          Issue Type: Sub-task
>          Components: dsl-sql
>            Reporter: Rui Wang
>            Assignee: Rui Wang
>            Priority: Major
>
> RPAD(original_value, return_length[, pattern])
> Returns a value that consists of original_value appended with pattern. The 
> return_length is an INT64 that specifies the length of the returned value. If 
> original_value is BYTES, return_length is the number of bytes. If 
> original_value is STRING, return_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_value, return_length, or pattern is NULL, this function returns 
> NULL.
> This function returns an error if:
> return_length is negative
> pattern is empty
> Return type
> STRING or BYTES
> Examples
> SELECT t, len, FORMAT("%T", RPAD(t, len)) AS RPAD FROM UNNEST([
>   STRUCT('abc' AS t, 5 AS len),
>   ('abc', 2),
>   ('例子', 4)
> ]);
> t     len     RPAD
> abc   5       "abc  "
> abc   2       "ab"
> 例子    4       "例子  "
> SELECT t, len, pattern, FORMAT("%T", RPAD(t, len, pattern)) AS RPAD FROM 
> UNNEST([
>   STRUCT('abc' AS t, 8 AS len, 'def' AS pattern),
>   ('abc', 5, '-'),
>   ('例子', 5, '中文')
> ]);
> t     len     pattern RPAD
> abc   8       def     "abcdefde"
> abc   5       -       "abc--"
> 例子    5       中文      "例子中文中"
> SELECT FORMAT("%T", t) AS t, len, FORMAT("%T", RPAD(t, len)) AS RPAD FROM 
> UNNEST([
>   STRUCT(b'abc' AS t, 5 AS len),
>   (b'abc', 2),
>   (b'\xab\xcd\xef', 4)
> ]);
> t     len     RPAD
> b"abc"        5       b"abc  "
> b"abc"        2       b"ab"
> b"\xab\xcd\xef"       4       b"\xab\xcd\xef "
> SELECT
>   FORMAT("%T", t) AS t,
>   len,
>   FORMAT("%T", pattern) AS pattern,
>   FORMAT("%T", RPAD(t, len, pattern)) AS RPAD
> FROM UNNEST([
>   STRUCT(b'abc' AS t, 8 AS len, b'def' AS pattern),
>   (b'abc', 5, b'-'),
>   (b'\xab\xcd\xef', 5, b'\x00')
> ]);
> t     len     pattern RPAD
> b"abc"        8       b"def"  b"abcdefde"
> b"abc"        5       b"-"    b"abc--"
> b"\xab\xcd\xef"       5       b"\x00" b"\xab\xcd\xef\x00\x00"



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to