aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/resources/sql-tests/results/json-functions.sql.out
blob: 315e1730ce7dff9bed96a5cfb1d8aa7f3e09494e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 17


-- !query 0
describe function to_json
-- !query 0 schema
struct<function_desc:string>
-- !query 0 output
Class: org.apache.spark.sql.catalyst.expressions.StructsToJson
Function: to_json
Usage: to_json(expr[, options]) - Returns a json string with a given struct value


-- !query 1
describe function extended to_json
-- !query 1 schema
struct<function_desc:string>
-- !query 1 output
Class: org.apache.spark.sql.catalyst.expressions.StructsToJson
Extended Usage:
    Examples:
      > SELECT to_json(named_struct('a', 1, 'b', 2));
       {"a":1,"b":2}
      > SELECT to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
       {"time":"26/08/2015"}
      > SELECT to_json(array(named_struct('a', 1, 'b', 2));
       [{"a":1,"b":2}]
  
Function: to_json
Usage: to_json(expr[, options]) - Returns a json string with a given struct value


-- !query 2
select to_json(named_struct('a', 1, 'b', 2))
-- !query 2 schema
struct<structstojson(named_struct(a, 1, b, 2)):string>
-- !query 2 output
{"a":1,"b":2}


-- !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<structstojson(named_struct(time, to_timestamp('2015-08-26', 'yyyy-MM-dd'))):string>
-- !query 3 output
{"time":"26/08/2015"}


-- !query 4
select to_json(array(named_struct('a', 1, 'b', 2)))
-- !query 4 schema
struct<structstojson(array(named_struct(a, 1, b, 2))):string>
-- !query 4 output
[{"a":1,"b":2}]


-- !query 5
select to_json(named_struct('a', 1, 'b', 2), named_struct('mode', 'PERMISSIVE'))
-- !query 5 schema
struct<>
-- !query 5 output
org.apache.spark.sql.AnalysisException
Must use a map() function for options;; line 1 pos 7


-- !query 6
select to_json(named_struct('a', 1, 'b', 2), map('mode', 1))
-- !query 6 schema
struct<>
-- !query 6 output
org.apache.spark.sql.AnalysisException
A type of keys and values in map() must be string, but got MapType(StringType,IntegerType,false);; line 1 pos 7


-- !query 7
select to_json()
-- !query 7 schema
struct<>
-- !query 7 output
org.apache.spark.sql.AnalysisException
Invalid number of arguments for function to_json; line 1 pos 7


-- !query 8
describe function from_json
-- !query 8 schema
struct<function_desc:string>
-- !query 8 output
Class: org.apache.spark.sql.catalyst.expressions.JsonToStructs
Function: from_json
Usage: from_json(jsonStr, schema[, options]) - Returns a struct value with the given `jsonStr` and `schema`.


-- !query 9
describe function extended from_json
-- !query 9 schema
struct<function_desc:string>
-- !query 9 output
Class: org.apache.spark.sql.catalyst.expressions.JsonToStructs
Extended Usage:
    Examples:
      > SELECT from_json('{"a":1, "b":0.8}', 'a INT, b DOUBLE');
       {"a":1, "b":0.8}
      > SELECT from_json('{"time":"26/08/2015"}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
       {"time":"2015-08-26 00:00:00.0"}
  
Function: from_json
Usage: from_json(jsonStr, schema[, options]) - Returns a struct value with the given `jsonStr` and `schema`.


-- !query 10
select from_json('{"a":1}', 'a INT')
-- !query 10 schema
struct<jsontostructs({"a":1}):struct<a:int>>
-- !query 10 output
{"a":1}


-- !query 11
select from_json('{"time":"26/08/2015"}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'))
-- !query 11 schema
struct<jsontostructs({"time":"26/08/2015"}):struct<time:timestamp>>
-- !query 11 output
{"time":2015-08-26 00:00:00.0}


-- !query 12
select from_json('{"a":1}', 1)
-- !query 12 schema
struct<>
-- !query 12 output
org.apache.spark.sql.AnalysisException
Expected a string literal instead of 1;; line 1 pos 7


-- !query 13
select from_json('{"a":1}', 'a InvalidType')
-- !query 13 schema
struct<>
-- !query 13 output
org.apache.spark.sql.AnalysisException

DataType invalidtype() is not supported.(line 1, pos 2)

== SQL ==
a InvalidType
--^^^
; line 1 pos 7


-- !query 14
select from_json('{"a":1}', 'a INT', named_struct('mode', 'PERMISSIVE'))
-- !query 14 schema
struct<>
-- !query 14 output
org.apache.spark.sql.AnalysisException
Must use a map() function for options;; line 1 pos 7


-- !query 15
select from_json('{"a":1}', 'a INT', map('mode', 1))
-- !query 15 schema
struct<>
-- !query 15 output
org.apache.spark.sql.AnalysisException
A type of keys and values in map() must be string, but got MapType(StringType,IntegerType,false);; line 1 pos 7


-- !query 16
select from_json()
-- !query 16 schema
struct<>
-- !query 16 output
org.apache.spark.sql.AnalysisException
Invalid number of arguments for function from_json; line 1 pos 7