Skip to content

Commit 197f901

Browse files
10110346gatorsmile
authored andcommitted
[SPARK-20403][SQL] Modify the instructions of some functions
## What changes were proposed in this pull request? 1. add instructions of 'cast' function When using 'show functions' and 'desc function cast' command in spark-sql 2. Modify the instructions of functions,such as boolean,tinyint,smallint,int,bigint,float,double,decimal,date,timestamp,binary,string ## How was this patch tested? Before modification: spark-sql>desc function boolean; Function: boolean Class: org.apache.spark.sql.catalyst.expressions.Cast Usage: boolean(expr AS type) - Casts the value `expr` to the target data type `type`. After modification: spark-sql> desc function boolean; Function: boolean Class: org.apache.spark.sql.catalyst.expressions.Cast Usage: boolean(expr) - Casts the value `expr` to the target data type `boolean`. spark-sql> desc function cast Function: cast Class: org.apache.spark.sql.catalyst.expressions.Cast Usage: cast(expr AS type) - Casts the value `expr` to the target data type `type`. Author: liuxian <[email protected]> Closes #17698 from 10110346/wip_lx_0418.
1 parent 5f8ff2f commit 197f901

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ object FunctionRegistry {
431431
expression[StructsToJson]("to_json"),
432432
expression[JsonToStructs]("from_json"),
433433

434+
// cast
435+
expression[Cast]("cast"),
434436
// Cast aliases (SPARK-16730)
435437
castAlias("boolean", BooleanType),
436438
castAlias("tinyint", ByteType),
@@ -513,7 +515,9 @@ object FunctionRegistry {
513515
}
514516
Cast(args.head, dataType)
515517
}
516-
(name, (expressionInfo[Cast](name), builder))
518+
val clazz = scala.reflect.classTag[Cast].runtimeClass
519+
val usage = "_FUNC_(expr) - Casts the value `expr` to the target data type `_FUNC_`."
520+
(name, (new ExpressionInfo(clazz.getCanonicalName, null, name, usage, null), builder))
517521
}
518522

519523
/**

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ case class Logarithm(left: Expression, right: Expression)
982982
*
983983
* @param child expr to be round, all [[NumericType]] is allowed as Input
984984
* @param scale new scale to be round to, this should be a constant int at runtime
985-
* @param mode rounding mode (e.g. HALF_UP, HALF_UP)
985+
* @param mode rounding mode (e.g. HALF_UP, HALF_EVEN)
986986
* @param modeStr rounding mode string name (e.g. "ROUND_HALF_UP", "ROUND_HALF_EVEN")
987987
*/
988988
abstract class RoundBase(child: Expression, scale: Expression,

sql/core/src/test/resources/sql-tests/inputs/cast.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ SELECT CAST('-9223372036854775809' AS long);
4040
SELECT CAST('9223372036854775807' AS long);
4141
SELECT CAST('9223372036854775808' AS long);
4242

43+
DESC FUNCTION boolean;
44+
DESC FUNCTION EXTENDED boolean;
4345
-- TODO: migrate all cast tests here.

sql/core/src/test/resources/sql-tests/results/cast.sql.out

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Automatically generated by SQLQueryTestSuite
2-
-- Number of queries: 22
2+
-- Number of queries: 24
33

44

55
-- !query 0
@@ -176,3 +176,24 @@ SELECT CAST('9223372036854775808' AS long)
176176
struct<CAST(9223372036854775808 AS BIGINT):bigint>
177177
-- !query 21 output
178178
NULL
179+
180+
181+
-- !query 22
182+
DESC FUNCTION boolean
183+
-- !query 22 schema
184+
struct<function_desc:string>
185+
-- !query 22 output
186+
Class: org.apache.spark.sql.catalyst.expressions.Cast
187+
Function: boolean
188+
Usage: boolean(expr) - Casts the value `expr` to the target data type `boolean`.
189+
190+
191+
-- !query 23
192+
DESC FUNCTION EXTENDED boolean
193+
-- !query 23 schema
194+
struct<function_desc:string>
195+
-- !query 23 output
196+
Class: org.apache.spark.sql.catalyst.expressions.Cast
197+
Extended Usage:N/A.
198+
Function: boolean
199+
Usage: boolean(expr) - Casts the value `expr` to the target data type `boolean`.

0 commit comments

Comments
 (0)