Repository: spark
Updated Branches:
refs/heads/master 5f8ff2fc9 -> 197f9018a
[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.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/197f9018
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/197f9018
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/197f9018
Branch: refs/heads/master
Commit: 197f9018a4641c8fc0725905ebfb535b61bed791
Parents: 5f8ff2f
Author: liuxian <[email protected]>
Authored: Wed May 24 17:32:02 2017 -0700
Committer: Xiao Li <[email protected]>
Committed: Wed May 24 17:32:02 2017 -0700
----------------------------------------------------------------------
.../catalyst/analysis/FunctionRegistry.scala | 6 ++++-
.../catalyst/expressions/mathExpressions.scala | 2 +-
.../test/resources/sql-tests/inputs/cast.sql | 2 ++
.../resources/sql-tests/results/cast.sql.out | 23 +++++++++++++++++++-
4 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/197f9018/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
----------------------------------------------------------------------
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
index d2042ad..7521a7e 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
@@ -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),
@@ -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))
}
/**
http://git-wip-us.apache.org/repos/asf/spark/blob/197f9018/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
----------------------------------------------------------------------
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
index bf46a39..754b5c4 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
@@ -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,
http://git-wip-us.apache.org/repos/asf/spark/blob/197f9018/sql/core/src/test/resources/sql-tests/inputs/cast.sql
----------------------------------------------------------------------
diff --git a/sql/core/src/test/resources/sql-tests/inputs/cast.sql
b/sql/core/src/test/resources/sql-tests/inputs/cast.sql
index 5fae571..629df59 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/cast.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/cast.sql
@@ -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.
http://git-wip-us.apache.org/repos/asf/spark/blob/197f9018/sql/core/src/test/resources/sql-tests/results/cast.sql.out
----------------------------------------------------------------------
diff --git a/sql/core/src/test/resources/sql-tests/results/cast.sql.out
b/sql/core/src/test/resources/sql-tests/results/cast.sql.out
index bfa29d7..4e6353b 100644
--- a/sql/core/src/test/resources/sql-tests/results/cast.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/cast.sql.out
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
--- Number of queries: 22
+-- Number of queries: 24
-- !query 0
@@ -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`.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]