Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ object FunctionRegistry {
expression[StructsToJson]("to_json"),
expression[JsonToStructs]("from_json"),

// cast
expression[Cast]("cast"),
// Cast aliases (SPARK-16730)
castAlias("boolean", BooleanType),
castAlias("tinyint", ByteType),
Expand Down Expand Up @@ -513,7 +515,9 @@ object FunctionRegistry {
}
Cast(args.head, dataType)
}
(name, (expressionInfo[Cast](name), builder))
val clazz = scala.reflect.classTag[Cast].runtimeClass
val usage = "_FUNC_(expr) - Casts the value `expr` to the target data type `_FUNC_`."
(name, (new ExpressionInfo(clazz.getCanonicalName, null, name, usage, null), builder))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ case class Logarithm(left: Expression, right: Expression)
*
* @param child expr to be round, all [[NumericType]] is allowed as Input
* @param scale new scale to be round to, this should be a constant int at runtime
* @param mode rounding mode (e.g. HALF_UP, HALF_UP)
* @param mode rounding mode (e.g. HALF_UP, HALF_EVEN)
* @param modeStr rounding mode string name (e.g. "ROUND_HALF_UP", "ROUND_HALF_EVEN")
*/
abstract class RoundBase(child: Expression, scale: Expression,
Expand Down
2 changes: 2 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/cast.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ SELECT CAST('-9223372036854775809' AS long);
SELECT CAST('9223372036854775807' AS long);
SELECT CAST('9223372036854775808' AS long);

DESC FUNCTION boolean;
DESC FUNCTION EXTENDED boolean;
-- TODO: migrate all cast tests here.
23 changes: 22 additions & 1 deletion sql/core/src/test/resources/sql-tests/results/cast.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 22
-- Number of queries: 24


-- !query 0
Expand Down Expand Up @@ -176,3 +176,24 @@ SELECT CAST('9223372036854775808' AS long)
struct<CAST(9223372036854775808 AS BIGINT):bigint>
-- !query 21 output
NULL


-- !query 22
DESC FUNCTION boolean
-- !query 22 schema
struct<function_desc:string>
-- !query 22 output
Class: org.apache.spark.sql.catalyst.expressions.Cast
Function: boolean
Usage: boolean(expr) - Casts the value `expr` to the target data type `boolean`.


-- !query 23
DESC FUNCTION EXTENDED boolean
-- !query 23 schema
struct<function_desc:string>
-- !query 23 output
Class: org.apache.spark.sql.catalyst.expressions.Cast
Extended Usage:N/A.
Function: boolean
Usage: boolean(expr) - Casts the value `expr` to the target data type `boolean`.