Skip to content

Commit 3447e73

Browse files
committed
Add prettyNames for from_json, to_json, from_csv, and schema_of_json
1 parent 1e6c1d8 commit 3447e73

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,6 @@ case class CsvToStructs(
117117
}
118118

119119
override def inputTypes: Seq[AbstractDataType] = StringType :: Nil
120+
121+
override def prettyName: String = "from_csv"
120122
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ case class JsonToStructs(
610610
case _: MapType => "entries"
611611
case _ => super.sql
612612
}
613+
614+
override def prettyName: String = "from_json"
613615
}
614616

615617
/**
@@ -730,6 +732,8 @@ case class StructsToJson(
730732
override def nullSafeEval(value: Any): Any = converter(value)
731733

732734
override def inputTypes: Seq[AbstractDataType] = TypeCollection(ArrayType, StructType) :: Nil
735+
736+
override def prettyName: String = "to_json"
733737
}
734738

735739
/**
@@ -774,6 +778,8 @@ case class SchemaOfJson(
774778

775779
UTF8String.fromString(dt.catalogString)
776780
}
781+
782+
override def prettyName: String = "schema_of_json"
777783
}
778784

779785
object JsonExprUtils {

sql/core/src/test/resources/sql-tests/results/csv-functions.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
-- !query 0
66
select from_csv('1, 3.14', 'a INT, f FLOAT')
77
-- !query 0 schema
8-
struct<csvtostructs(1, 3.14):struct<a:int,f:float>>
8+
struct<from_csv(1, 3.14):struct<a:int,f:float>>
99
-- !query 0 output
1010
{"a":1,"f":3.14}
1111

1212

1313
-- !query 1
1414
select from_csv('26/08/2015', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'))
1515
-- !query 1 schema
16-
struct<csvtostructs(26/08/2015):struct<time:timestamp>>
16+
struct<from_csv(26/08/2015):struct<time:timestamp>>
1717
-- !query 1 output
1818
{"time":2015-08-26 00:00:00.0}
1919

sql/core/src/test/resources/sql-tests/results/json-functions.sql.out

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,63 +44,63 @@ Usage: to_json(expr[, options]) - Returns a JSON string with a given struct valu
4444
-- !query 2
4545
select to_json(named_struct('a', 1, 'b', 2))
4646
-- !query 2 schema
47-
struct<structstojson(named_struct(a, 1, b, 2)):string>
47+
struct<to_json(named_struct(a, 1, b, 2)):string>
4848
-- !query 2 output
4949
{"a":1,"b":2}
5050

5151

5252
-- !query 3
5353
select to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'))
5454
-- !query 3 schema
55-
struct<structstojson(named_struct(time, to_timestamp('2015-08-26', 'yyyy-MM-dd'))):string>
55+
struct<to_json(named_struct(time, to_timestamp('2015-08-26', 'yyyy-MM-dd'))):string>
5656
-- !query 3 output
5757
{"time":"26/08/2015"}
5858

5959

6060
-- !query 4
6161
select to_json(array(named_struct('a', 1, 'b', 2)))
6262
-- !query 4 schema
63-
struct<structstojson(array(named_struct(a, 1, b, 2))):string>
63+
struct<to_json(array(named_struct(a, 1, b, 2))):string>
6464
-- !query 4 output
6565
[{"a":1,"b":2}]
6666

6767

6868
-- !query 5
6969
select to_json(map(named_struct('a', 1, 'b', 2), named_struct('a', 1, 'b', 2)))
7070
-- !query 5 schema
71-
struct<structstojson(map(named_struct(a, 1, b, 2), named_struct(a, 1, b, 2))):string>
71+
struct<to_json(map(named_struct(a, 1, b, 2), named_struct(a, 1, b, 2))):string>
7272
-- !query 5 output
7373
{"[1,2]":{"a":1,"b":2}}
7474

7575

7676
-- !query 6
7777
select to_json(map('a', named_struct('a', 1, 'b', 2)))
7878
-- !query 6 schema
79-
struct<structstojson(map(a, named_struct(a, 1, b, 2))):string>
79+
struct<to_json(map(a, named_struct(a, 1, b, 2))):string>
8080
-- !query 6 output
8181
{"a":{"a":1,"b":2}}
8282

8383

8484
-- !query 7
8585
select to_json(map('a', 1))
8686
-- !query 7 schema
87-
struct<structstojson(map(a, 1)):string>
87+
struct<to_json(map(a, 1)):string>
8888
-- !query 7 output
8989
{"a":1}
9090

9191

9292
-- !query 8
9393
select to_json(array(map('a',1)))
9494
-- !query 8 schema
95-
struct<structstojson(array(map(a, 1))):string>
95+
struct<to_json(array(map(a, 1))):string>
9696
-- !query 8 output
9797
[{"a":1}]
9898

9999

100100
-- !query 9
101101
select to_json(array(map('a',1), map('b',2)))
102102
-- !query 9 schema
103-
struct<structstojson(array(map(a, 1), map(b, 2))):string>
103+
struct<to_json(array(map(a, 1), map(b, 2))):string>
104104
-- !query 9 output
105105
[{"a":1},{"b":2}]
106106

@@ -164,15 +164,15 @@ Usage: from_json(jsonStr, schema[, options]) - Returns a struct value with the g
164164
-- !query 15
165165
select from_json('{"a":1}', 'a INT')
166166
-- !query 15 schema
167-
struct<jsontostructs({"a":1}):struct<a:int>>
167+
struct<from_json({"a":1}):struct<a:int>>
168168
-- !query 15 output
169169
{"a":1}
170170

171171

172172
-- !query 16
173173
select from_json('{"time":"26/08/2015"}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'))
174174
-- !query 16 schema
175-
struct<jsontostructs({"time":"26/08/2015"}):struct<time:timestamp>>
175+
struct<from_json({"time":"26/08/2015"}):struct<time:timestamp>>
176176
-- !query 16 output
177177
{"time":2015-08-26 00:00:00.0}
178178

@@ -271,118 +271,118 @@ struct<entries:map<string,int>>
271271
-- !query 27
272272
select from_json('{"a":1, "b":"2"}', 'struct<a:int,b:string>')
273273
-- !query 27 schema
274-
struct<jsontostructs({"a":1, "b":"2"}):struct<a:int,b:string>>
274+
struct<from_json({"a":1, "b":"2"}):struct<a:int,b:string>>
275275
-- !query 27 output
276276
{"a":1,"b":"2"}
277277

278278

279279
-- !query 28
280280
select schema_of_json('{"c1":0, "c2":[1]}')
281281
-- !query 28 schema
282-
struct<schemaofjson({"c1":0, "c2":[1]}):string>
282+
struct<schema_of_json({"c1":0, "c2":[1]}):string>
283283
-- !query 28 output
284284
struct<c1:bigint,c2:array<bigint>>
285285

286286

287287
-- !query 29
288288
select from_json('{"c1":[1, 2, 3]}', schema_of_json('{"c1":[0]}'))
289289
-- !query 29 schema
290-
struct<jsontostructs({"c1":[1, 2, 3]}):struct<c1:array<bigint>>>
290+
struct<from_json({"c1":[1, 2, 3]}):struct<c1:array<bigint>>>
291291
-- !query 29 output
292292
{"c1":[1,2,3]}
293293

294294

295295
-- !query 30
296296
select from_json('[1, 2, 3]', 'array<int>')
297297
-- !query 30 schema
298-
struct<jsontostructs([1, 2, 3]):array<int>>
298+
struct<from_json([1, 2, 3]):array<int>>
299299
-- !query 30 output
300300
[1,2,3]
301301

302302

303303
-- !query 31
304304
select from_json('[1, "2", 3]', 'array<int>')
305305
-- !query 31 schema
306-
struct<jsontostructs([1, "2", 3]):array<int>>
306+
struct<from_json([1, "2", 3]):array<int>>
307307
-- !query 31 output
308308
NULL
309309

310310

311311
-- !query 32
312312
select from_json('[1, 2, null]', 'array<int>')
313313
-- !query 32 schema
314-
struct<jsontostructs([1, 2, null]):array<int>>
314+
struct<from_json([1, 2, null]):array<int>>
315315
-- !query 32 output
316316
[1,2,null]
317317

318318

319319
-- !query 33
320320
select from_json('[{"a": 1}, {"a":2}]', 'array<struct<a:int>>')
321321
-- !query 33 schema
322-
struct<jsontostructs([{"a": 1}, {"a":2}]):array<struct<a:int>>>
322+
struct<from_json([{"a": 1}, {"a":2}]):array<struct<a:int>>>
323323
-- !query 33 output
324324
[{"a":1},{"a":2}]
325325

326326

327327
-- !query 34
328328
select from_json('{"a": 1}', 'array<struct<a:int>>')
329329
-- !query 34 schema
330-
struct<jsontostructs({"a": 1}):array<struct<a:int>>>
330+
struct<from_json({"a": 1}):array<struct<a:int>>>
331331
-- !query 34 output
332332
[{"a":1}]
333333

334334

335335
-- !query 35
336336
select from_json('[null, {"a":2}]', 'array<struct<a:int>>')
337337
-- !query 35 schema
338-
struct<jsontostructs([null, {"a":2}]):array<struct<a:int>>>
338+
struct<from_json([null, {"a":2}]):array<struct<a:int>>>
339339
-- !query 35 output
340340
[null,{"a":2}]
341341

342342

343343
-- !query 36
344344
select from_json('[{"a": 1}, {"b":2}]', 'array<map<string,int>>')
345345
-- !query 36 schema
346-
struct<jsontostructs([{"a": 1}, {"b":2}]):array<map<string,int>>>
346+
struct<from_json([{"a": 1}, {"b":2}]):array<map<string,int>>>
347347
-- !query 36 output
348348
[{"a":1},{"b":2}]
349349

350350

351351
-- !query 37
352352
select from_json('[{"a": 1}, 2]', 'array<map<string,int>>')
353353
-- !query 37 schema
354-
struct<jsontostructs([{"a": 1}, 2]):array<map<string,int>>>
354+
struct<from_json([{"a": 1}, 2]):array<map<string,int>>>
355355
-- !query 37 output
356356
NULL
357357

358358

359359
-- !query 38
360360
select to_json(array('1', '2', '3'))
361361
-- !query 38 schema
362-
struct<structstojson(array(1, 2, 3)):string>
362+
struct<to_json(array(1, 2, 3)):string>
363363
-- !query 38 output
364364
["1","2","3"]
365365

366366

367367
-- !query 39
368368
select to_json(array(array(1, 2, 3), array(4)))
369369
-- !query 39 schema
370-
struct<structstojson(array(array(1, 2, 3), array(4))):string>
370+
struct<to_json(array(array(1, 2, 3), array(4))):string>
371371
-- !query 39 output
372372
[[1,2,3],[4]]
373373

374374

375375
-- !query 40
376376
select schema_of_json('{"c1":1}', map('primitivesAsString', 'true'))
377377
-- !query 40 schema
378-
struct<schemaofjson({"c1":1}):string>
378+
struct<schema_of_json({"c1":1}):string>
379379
-- !query 40 output
380380
struct<c1:string>
381381

382382

383383
-- !query 41
384384
select schema_of_json('{"c1":01, "c2":0.1}', map('allowNumericLeadingZeros', 'true', 'prefersDecimal', 'true'))
385385
-- !query 41 schema
386-
struct<schemaofjson({"c1":01, "c2":0.1}):string>
386+
struct<schema_of_json({"c1":01, "c2":0.1}):string>
387387
-- !query 41 output
388388
struct<c1:bigint,c2:decimal(1,1)>

sql/core/src/test/resources/sql-tests/results/typeCoercion/native/stringCastAndExpressions.sql.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,6 @@ NULL
256256
-- !query 31
257257
select from_json(a, 'a INT') from t
258258
-- !query 31 schema
259-
struct<jsontostructs(a):struct<a:int>>
259+
struct<from_json(a):struct<a:int>>
260260
-- !query 31 output
261261
NULL

0 commit comments

Comments
 (0)