[SPARK-20749][SQL][FOLLOWUP] Support character_length

## What changes were proposed in this pull request?

The function `char_length` is shorthand for `character_length` function. Both Hive and Postgresql support `character_length`,  This PR add support for `character_length`.

Ref:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-StringFunctions
https://www.postgresql.org/docs/current/static/functions-string.html

## How was this patch tested?

unit tests

Author: Yuming Wang <wgyumg@gmail.com>

Closes #18330 from wangyum/SPARK-20749-character_length.
This commit is contained in:
Yuming Wang 2017-06-18 18:56:53 -07:00 committed by Xiao Li
parent 110ce1f27b
commit ce49428ef7
4 changed files with 19 additions and 5 deletions

View file

@ -307,6 +307,7 @@ object FunctionRegistry {
expression[Base64]("base64"),
expression[BitLength]("bit_length"),
expression[Length]("char_length"),
expression[Length]("character_length"),
expression[Concat]("concat"),
expression[ConcatWs]("concat_ws"),
expression[Decode]("decode"),

View file

@ -1209,6 +1209,10 @@ case class Substring(str: Expression, pos: Expression, len: Expression)
Examples:
> SELECT _FUNC_('Spark SQL');
9
> SELECT CHAR_LENGTH('Spark SQL');
9
> SELECT CHARACTER_LENGTH('Spark SQL');
9
""")
// scalastyle:on line.size.limit
case class Length(child: Expression) extends UnaryExpression with ImplicitCastInputTypes {

View file

@ -84,6 +84,7 @@ select mod(7, 2), mod(7, 0), mod(0, 2), mod(7, null), mod(null, 2), mod(null, nu
-- length
select BIT_LENGTH('abc');
select CHAR_LENGTH('abc');
select CHARACTER_LENGTH('abc');
select OCTET_LENGTH('abc');
-- abs

View file

@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 55
-- Number of queries: 56
-- !query 0
@ -439,16 +439,24 @@ struct<length(abc):int>
-- !query 53
select OCTET_LENGTH('abc')
select CHARACTER_LENGTH('abc')
-- !query 53 schema
struct<octetlength(abc):int>
struct<length(abc):int>
-- !query 53 output
3
-- !query 54
select abs(-3.13), abs('-2.19')
select OCTET_LENGTH('abc')
-- !query 54 schema
struct<abs(-3.13):decimal(3,2),abs(CAST(-2.19 AS DOUBLE)):double>
struct<octetlength(abc):int>
-- !query 54 output
3
-- !query 55
select abs(-3.13), abs('-2.19')
-- !query 55 schema
struct<abs(-3.13):decimal(3,2),abs(CAST(-2.19 AS DOUBLE)):double>
-- !query 55 output
3.13 2.19