Skip to content

Commit

Permalink
[SPARK-20749][SQL][FOLLOWUP] Support character_length
Browse files Browse the repository at this point in the history
## 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 <[email protected]>

Closes apache#18330 from wangyum/SPARK-20749-character_length.
  • Loading branch information
wangyum authored and gatorsmile committed Jun 19, 2017
1 parent 110ce1f commit ce49428
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions sql/core/src/test/resources/sql-tests/inputs/operators.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions sql/core/src/test/resources/sql-tests/results/operators.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 55
-- Number of queries: 56


-- !query 0
Expand Down Expand Up @@ -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

0 comments on commit ce49428

Please sign in to comment.