From 3370865b0ebe9b04c6671631aee5917b41ceba9c Mon Sep 17 00:00:00 2001 From: hyukjinkwon Date: Sat, 20 Oct 2018 10:15:53 +0800 Subject: [PATCH] [SPARK-25785][SQL] Add prettyNames for from_json, to_json, from_csv, and schema_of_json ## What changes were proposed in this pull request? This PR adds `prettyNames` for `from_json`, `to_json`, `from_csv`, and `schema_of_json` so that appropriate names are used. ## How was this patch tested? Unit tests Closes #22773 from HyukjinKwon/minor-prettyNames. Authored-by: hyukjinkwon Signed-off-by: hyukjinkwon --- .../catalyst/expressions/csvExpressions.scala | 2 + .../expressions/jsonExpressions.scala | 6 +++ .../sql-tests/results/csv-functions.sql.out | 4 +- .../sql-tests/results/json-functions.sql.out | 50 +++++++++---------- .../native/stringCastAndExpressions.sql.out | 2 +- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/csvExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/csvExpressions.scala index a63b6245c4..853b1ea6a5 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/csvExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/csvExpressions.scala @@ -117,4 +117,6 @@ case class CsvToStructs( } override def inputTypes: Seq[AbstractDataType] = StringType :: Nil + + override def prettyName: String = "from_csv" } diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala index 9f2848365b..b4815b47d1 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala @@ -610,6 +610,8 @@ case class JsonToStructs( case _: MapType => "entries" case _ => super.sql } + + override def prettyName: String = "from_json" } /** @@ -730,6 +732,8 @@ case class StructsToJson( override def nullSafeEval(value: Any): Any = converter(value) override def inputTypes: Seq[AbstractDataType] = TypeCollection(ArrayType, StructType) :: Nil + + override def prettyName: String = "to_json" } /** @@ -774,6 +778,8 @@ case class SchemaOfJson( UTF8String.fromString(dt.catalogString) } + + override def prettyName: String = "schema_of_json" } object JsonExprUtils { diff --git a/sql/core/src/test/resources/sql-tests/results/csv-functions.sql.out b/sql/core/src/test/resources/sql-tests/results/csv-functions.sql.out index 15dbe36bc0..f19f34a773 100644 --- a/sql/core/src/test/resources/sql-tests/results/csv-functions.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/csv-functions.sql.out @@ -5,7 +5,7 @@ -- !query 0 select from_csv('1, 3.14', 'a INT, f FLOAT') -- !query 0 schema -struct> +struct> -- !query 0 output {"a":1,"f":3.14} @@ -13,7 +13,7 @@ struct> -- !query 1 select from_csv('26/08/2015', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy')) -- !query 1 schema -struct> +struct> -- !query 1 output {"time":2015-08-26 00:00:00.0} diff --git a/sql/core/src/test/resources/sql-tests/results/json-functions.sql.out b/sql/core/src/test/resources/sql-tests/results/json-functions.sql.out index 77e9000401..868eee81ac 100644 --- a/sql/core/src/test/resources/sql-tests/results/json-functions.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/json-functions.sql.out @@ -44,7 +44,7 @@ Usage: to_json(expr[, options]) - Returns a JSON string with a given struct valu -- !query 2 select to_json(named_struct('a', 1, 'b', 2)) -- !query 2 schema -struct +struct -- !query 2 output {"a":1,"b":2} @@ -52,7 +52,7 @@ struct -- !query 3 select to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy')) -- !query 3 schema -struct +struct -- !query 3 output {"time":"26/08/2015"} @@ -60,7 +60,7 @@ struct +struct -- !query 4 output [{"a":1,"b":2}] @@ -68,7 +68,7 @@ struct -- !query 5 select to_json(map(named_struct('a', 1, 'b', 2), named_struct('a', 1, 'b', 2))) -- !query 5 schema -struct +struct -- !query 5 output {"[1,2]":{"a":1,"b":2}} @@ -76,7 +76,7 @@ struct +struct -- !query 6 output {"a":{"a":1,"b":2}} @@ -84,7 +84,7 @@ struct -- !query 7 select to_json(map('a', 1)) -- !query 7 schema -struct +struct -- !query 7 output {"a":1} @@ -92,7 +92,7 @@ struct -- !query 8 select to_json(array(map('a',1))) -- !query 8 schema -struct +struct -- !query 8 output [{"a":1}] @@ -100,7 +100,7 @@ struct -- !query 9 select to_json(array(map('a',1), map('b',2))) -- !query 9 schema -struct +struct -- !query 9 output [{"a":1},{"b":2}] @@ -164,7 +164,7 @@ Usage: from_json(jsonStr, schema[, options]) - Returns a struct value with the g -- !query 15 select from_json('{"a":1}', 'a INT') -- !query 15 schema -struct> +struct> -- !query 15 output {"a":1} @@ -172,7 +172,7 @@ struct> -- !query 16 select from_json('{"time":"26/08/2015"}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy')) -- !query 16 schema -struct> +struct> -- !query 16 output {"time":2015-08-26 00:00:00.0} @@ -271,7 +271,7 @@ struct> -- !query 27 select from_json('{"a":1, "b":"2"}', 'struct') -- !query 27 schema -struct> +struct> -- !query 27 output {"a":1,"b":"2"} @@ -279,7 +279,7 @@ struct> -- !query 28 select schema_of_json('{"c1":0, "c2":[1]}') -- !query 28 schema -struct +struct -- !query 28 output struct> @@ -287,7 +287,7 @@ struct> -- !query 29 select from_json('{"c1":[1, 2, 3]}', schema_of_json('{"c1":[0]}')) -- !query 29 schema -struct>> +struct>> -- !query 29 output {"c1":[1,2,3]} @@ -295,7 +295,7 @@ struct>> -- !query 30 select from_json('[1, 2, 3]', 'array') -- !query 30 schema -struct> +struct> -- !query 30 output [1,2,3] @@ -303,7 +303,7 @@ struct> -- !query 31 select from_json('[1, "2", 3]', 'array') -- !query 31 schema -struct> +struct> -- !query 31 output NULL @@ -311,7 +311,7 @@ NULL -- !query 32 select from_json('[1, 2, null]', 'array') -- !query 32 schema -struct> +struct> -- !query 32 output [1,2,null] @@ -319,7 +319,7 @@ struct> -- !query 33 select from_json('[{"a": 1}, {"a":2}]', 'array>') -- !query 33 schema -struct>> +struct>> -- !query 33 output [{"a":1},{"a":2}] @@ -327,7 +327,7 @@ struct>> -- !query 34 select from_json('{"a": 1}', 'array>') -- !query 34 schema -struct>> +struct>> -- !query 34 output [{"a":1}] @@ -335,7 +335,7 @@ struct>> -- !query 35 select from_json('[null, {"a":2}]', 'array>') -- !query 35 schema -struct>> +struct>> -- !query 35 output [null,{"a":2}] @@ -343,7 +343,7 @@ struct>> -- !query 36 select from_json('[{"a": 1}, {"b":2}]', 'array>') -- !query 36 schema -struct>> +struct>> -- !query 36 output [{"a":1},{"b":2}] @@ -351,7 +351,7 @@ struct>> -- !query 37 select from_json('[{"a": 1}, 2]', 'array>') -- !query 37 schema -struct>> +struct>> -- !query 37 output NULL @@ -359,7 +359,7 @@ NULL -- !query 38 select to_json(array('1', '2', '3')) -- !query 38 schema -struct +struct -- !query 38 output ["1","2","3"] @@ -367,7 +367,7 @@ struct -- !query 39 select to_json(array(array(1, 2, 3), array(4))) -- !query 39 schema -struct +struct -- !query 39 output [[1,2,3],[4]] @@ -375,7 +375,7 @@ struct -- !query 40 select schema_of_json('{"c1":1}', map('primitivesAsString', 'true')) -- !query 40 schema -struct +struct -- !query 40 output struct @@ -383,6 +383,6 @@ struct -- !query 41 select schema_of_json('{"c1":01, "c2":0.1}', map('allowNumericLeadingZeros', 'true', 'prefersDecimal', 'true')) -- !query 41 schema -struct +struct -- !query 41 output struct diff --git a/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/stringCastAndExpressions.sql.out b/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/stringCastAndExpressions.sql.out index 8ed2820244..ba9bf76513 100644 --- a/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/stringCastAndExpressions.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/stringCastAndExpressions.sql.out @@ -256,6 +256,6 @@ NULL -- !query 31 select from_json(a, 'a INT') from t -- !query 31 schema -struct> +struct> -- !query 31 output NULL