You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/07/28 06:37:44 UTC

[GitHub] yanghua commented on a change in pull request #6432: [FLINK-9970] Add ASCII/CHR function for table/sql API

yanghua commented on a change in pull request #6432: [FLINK-9970] Add ASCII/CHR function for table/sql API
URL: https://github.com/apache/flink/pull/6432#discussion_r205934831
 
 

 ##########
 File path: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/functions/ScalarFunctions.scala
 ##########
 @@ -196,9 +196,35 @@ object ScalarFunctions {
     new String(data)
   }
 
+  /**
+    * Returns the numeric value of the leftmost character of the string str.
+    * Returns 0 if str is the empty string. Returns NULL if str is NULL.
+    */
+  def ascii(str: String): String = {
+    if (str == null) {
+      null
+    } else if (str.equals("")) {
+      ""
+    } else {
+      str.charAt(0).toByte.toString
+    }
+  }
+
   /**
     * Returns the base string decoded with base64.
     */
   def fromBase64(str: String): String = new String(Base64.decodeBase64(str))
 
+  /**
+    * Returns string contains a character which converts from a ASCII integer.
+    * If the ASCII less then 0 or greater than 255, return null.
+    */
+  def chr(ascii: Integer): String = {
 
 Review comment:
   hi @hequn8128 others has accepted and fixed except this. can you give a hint? you mean:
   
   * one function and the parameter support multiple types? if support I can you Either[Type1, Type2], but more than two, how to handle this? I am not very familiar with Scala.
   
   * multiple functions, one support a single type?
   
   * assume supported these types, the `OperandTypes.NUMERIC` can represent them?
   
   ```scala
   val CHR = new SqlFunction(
       "CHR",
       SqlKind.OTHER_FUNCTION,
       ReturnTypes.cascade(ReturnTypes.explicit(SqlTypeName.VARCHAR), SqlTypeTransforms.TO_NULLABLE),
       null,
       OperandTypes.NUMERIC,
       SqlFunctionCategory.STRING
     )
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services