Skip to content

Commit 3f82d65

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 <liu.xian3@zte.com.cn> Closes #17698 from 10110346/wip_lx_0418. (cherry picked from commit 197f901) Signed-off-by: Xiao Li <gatorsmile@gmail.com>
1 parent ae65d30 commit 3f82d65

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
@@ -430,6 +430,8 @@ object FunctionRegistry {
430430
expression[StructsToJson]("to_json"),
431431
expression[JsonToStructs]("from_json"),
432432

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

518522
/**

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
@@ -966,7 +966,7 @@ case class Logarithm(left: Expression, right: Expression)
966966
*
967967
* @param child expr to be round, all [[NumericType]] is allowed as Input
968968
* @param scale new scale to be round to, this should be a constant int at runtime
969-
* @param mode rounding mode (e.g. HALF_UP, HALF_UP)
969+
* @param mode rounding mode (e.g. HALF_UP, HALF_EVEN)
970970
* @param modeStr rounding mode string name (e.g. "ROUND_HALF_UP", "ROUND_HALF_EVEN")
971971
*/
972972
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)