flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-6893) Add BIN supported in SQL
Date Tue, 18 Jul 2017 02:15:00 GMT

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

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

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

    https://github.com/apache/flink/pull/4128#discussion_r127866461
  
    --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala
---
    @@ -82,4 +82,24 @@ object ScalarFunctions {
         }
         sb.toString
       }
    +
    +  /**
    +    * Returns a string representation of the binary value of N, Returns NULL if N is
NULL.
    +    */
    +  def bin(n: Long): String = {
    +    if (null == n) {
    +      return null
    +    }
    +    val value = new Array[Byte](64)
    +    var num = n
    +    // Extract the bits of num into value[] from right to left
    +    var len: Int = 0
    +    do {
    +      len += 1
    +      value(value.length - len) = ('0' + (num & 1)).toByte
    +      num >>>= 1
    +    } while (num != 0)
    --- End diff --
    
    Use `Long.toBinaryString(long)` to parse it.


> Add BIN supported in SQL
> ------------------------
>
>                 Key: FLINK-6893
>                 URL: https://issues.apache.org/jira/browse/FLINK-6893
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Table API & SQL
>    Affects Versions: 1.4.0
>            Reporter: sunjincheng
>            Assignee: sunjincheng
>
> BIN(N) Returns a string representation of the binary value of N, where N is a longlong
(BIGINT) number. This is equivalent to CONV(N,10,2). Returns NULL if N is NULL.
> * Syntax:
> BIN(num)
> * Arguments
> **num: a long/bigint value
> * Return Types
>   String
> * Example:
>   BIN(12) -> '1100'
> * See more:
> ** [MySQL| https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_bin]



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

Mime
View raw message