You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by twalthr <gi...@git.apache.org> on 2017/07/18 14:44:31 UTC

[GitHub] flink pull request #4127: [FLINK-6892][table]Add L/RPAD supported in SQL

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

    https://github.com/apache/flink/pull/4127#discussion_r127995434
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala ---
    @@ -82,4 +82,102 @@ object ScalarFunctions {
         }
         sb.toString
       }
    +
    +  /**
    +    * 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) {
    +      return null
    +    }
    +    var data = "".getBytes
    +    if (data.length < len) {
    +      data = new Array[Byte](len)
    +    }
    +    val baseBytes = base.getBytes
    +    val padBytes = pad.getBytes
    +
    +    // The length of the padding needed
    +    val pos = Math.max(len - base.length, 0)
    +
    +    // Copy the padding
    +    var i = 0
    +
    +    while (i < pos) {
    +      {
    --- End diff --
    
    Is this code auto-generated? It looks weird.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---