You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/01/10 09:51:00 UTC

[jira] [Commented] (FLINK-6892) Add L/RPAD supported in SQL

    [ https://issues.apache.org/jira/browse/FLINK-6892?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16319975#comment-16319975 ] 

ASF GitHub Bot commented on FLINK-6892:
---------------------------------------

Github user twalthr commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4127#discussion_r160629246
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala ---
    @@ -104,9 +103,84 @@ object ScalarFunctions {
         }
         if (base <= 1.0) {
           throw new IllegalArgumentException(s"base of 'log(base, x)' must be > 1, but base = $base")
    -    }
    -    else {
    +    } else {
           Math.log(x) / Math.log(base)
         }
       }
    +
    +  /**
    +    * Returns the string str, left-padded with the string pad to a length of len characters.
    +    * If str is longer than len, the return value is shortened to len characters.
    +    */
    +  def lpad(base: String, len: Integer, pad: String): String = {
    +    if (base == null || len == null || pad == null) {
    --- End diff --
    
    `addSqlFunctionMethod` already checks for null in the arguments so we can use primitive integer here and remove this checks.


> Add L/RPAD supported in SQL
> ---------------------------
>
>                 Key: FLINK-6892
>                 URL: https://issues.apache.org/jira/browse/FLINK-6892
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Table API & SQL
>    Affects Versions: 1.4.0
>            Reporter: sunjincheng
>            Assignee: sunjincheng
>
> L/RPAD(str,len,padstr) Returns the string str, left/right-padded with the string padstr to a length of len characters. If str is longer than len, the return value is shortened to len characters.
> * Syntax:
> LPAD(str,len,padstr) 
> * Arguments
> **str: -
> **len: -
> **padstr: -
> * Return Types
>   String
> * Example:
>   LPAD('hi',4,'??') -> '??hi'
>   LPAD('hi',1,'??') -> 'h'
>   RPAD('hi',4,'??') -> 'hi??'
>   RPAD('hi',1,'??') -> 'h'
> * See more:
> ** [MySQL| https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_lpad]



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)