|
1 | | -package net.sf.jsqlparser.statement.from; |
| 1 | +package net.sf.jsqlparser.expression; |
2 | 2 |
|
3 | 3 | import net.sf.jsqlparser.JSQLParserException; |
4 | | -import net.sf.jsqlparser.expression.Function; |
5 | | -import net.sf.jsqlparser.expression.JsonTableFunction; |
6 | 4 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
7 | 5 | import net.sf.jsqlparser.statement.Statement; |
8 | 6 | import net.sf.jsqlparser.statement.select.FromItem; |
|
15 | 13 |
|
16 | 14 | import static org.assertj.core.api.Assertions.*; |
17 | 15 |
|
18 | | -public class JsonTableTest { |
| 16 | +public class JsonTableOracleTest { |
19 | 17 |
|
20 | 18 | @ParameterizedTest |
21 | 19 | @ValueSource(strings = { |
@@ -179,109 +177,22 @@ void testParsingTypeStrict() throws JSQLParserException { |
179 | 177 | .isEqualTo(JsonTableFunction.JsonTableParsingType.STRICT); |
180 | 178 | } |
181 | 179 |
|
182 | | - // @Test |
183 | | - // void testColumnTypeExists() throws JSQLParserException { |
184 | | - // String expression = "JSON_TABLE(document COLUMNS( hasValue EXISTS PATH '$.pathTest'))"; |
185 | | - // JsonTableFunction table = parseTable(expression); |
186 | | - // |
187 | | - // assertThat(table.getColumnsClause().getColumnDefinitions()).hasSize(1); |
188 | | - // |
189 | | - // JsonTableFunction.JsonTableColumnDefinition col = |
190 | | - // table.getColumnsClause().getColumnDefinitions().get(0); |
191 | | - // assertThat(col.getType()).isEqualTo(JsonTableColumnType.JSON_EXISTS); |
192 | | - // } |
193 | | - |
194 | | - // @Test |
195 | | - // void testBuilder() { |
196 | | - // Column c = new Column("document"); |
197 | | - // |
198 | | - // JsonTable table = new JsonTable().withExpression(c) |
199 | | - // .withPathExpression("$.subPath") |
200 | | - // .withFormatJson(true) |
201 | | - // .withType(JsonTableType.STRICT) |
202 | | - // .withOnEmptyType(JsonOnEmptyType.NULL) |
203 | | - // .withOnErrorType(JsonOnErrorType.ERROR) |
204 | | - // .withColumn(new JsonTableColumn().withName("id") |
205 | | - // .withType(JsonTableColumnType.ORDINALITY)); |
206 | | - // |
207 | | - // assertThat(table.toString()).isEqualTo( |
208 | | - // "JSON_TABLE(document FORMAT JSON, '$.subPath' ERROR ON ERROR TYPE(STRICT) NULL ON EMPTY |
209 | | - // COLUMNS(id FOR ORDINALITY))"); |
210 | | - // } |
211 | | - |
212 | | - // @Test |
213 | | - // void testValidSetters() { |
214 | | - // JsonTableFunction table = new JsonTableFunction(); |
215 | | - // |
216 | | - // JsonTableFunction.JsonTableOnEmptyClause onEmptyClause = new |
217 | | - // JsonTableFunction.JsonTableOnEmptyClause(); |
218 | | - // JsonTableFunction.JsonTableOnErrorClause onErrorClause = new |
219 | | - // JsonTableFunction.JsonTableOnErrorClause(true); |
220 | | - // |
221 | | - // assertThatNoException().isThrownBy(() -> { |
222 | | - // table.setOnEmptyClause(null); |
223 | | - // onEmptyClause.setType(JsonTableFunction.JsonTableOnEmptyType.NULL); |
224 | | - // onEmptyClause.setType(JsonTableFunction.JsonTableOnEmptyType.ERROR); |
225 | | - // |
226 | | - // onErrorClause.setOnErrorType(null); |
227 | | - // onErrorClause.setOnErrorType(JsonTableFunction.JsonTableOnErrorType); |
228 | | - // onErrorClause.setOnErrorType(JsonOnErrorType.ERROR); |
229 | | - // |
230 | | - // table.setType(null); |
231 | | - // table.setType(JsonTableType.LAX); |
232 | | - // table.setType(JsonTableType.STRICT); |
233 | | - // }); |
234 | | - // } |
235 | | - |
236 | | - // @Test |
237 | | - // void testInvalidSetters() { |
238 | | - // JsonTableFunction table = new JsonTable(); |
239 | | - // |
240 | | - // assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY)) |
241 | | - // .isInstanceOf(IllegalArgumentException.class); |
242 | | - // assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY_ARRAY)) |
243 | | - // .isInstanceOf(IllegalArgumentException.class); |
244 | | - // assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.EMPTY_OBJECT)) |
245 | | - // .isInstanceOf(IllegalArgumentException.class); |
246 | | - // assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.FALSE)) |
247 | | - // .isInstanceOf(IllegalArgumentException.class); |
248 | | - // assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.TRUE)) |
249 | | - // .isInstanceOf(IllegalArgumentException.class); |
250 | | - // assertThatThrownBy(() -> table.setOnEmptyType(JsonOnEmptyType.DEFAULT)) |
251 | | - // .isInstanceOf(IllegalArgumentException.class); |
252 | | - // |
253 | | - // assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY)) |
254 | | - // .isInstanceOf(IllegalArgumentException.class); |
255 | | - // assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY_ARRAY)) |
256 | | - // .isInstanceOf(IllegalArgumentException.class); |
257 | | - // assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.EMPTY_OBJECT)) |
258 | | - // .isInstanceOf(IllegalArgumentException.class); |
259 | | - // assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.FALSE)) |
260 | | - // .isInstanceOf(IllegalArgumentException.class); |
261 | | - // assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.TRUE)) |
262 | | - // .isInstanceOf(IllegalArgumentException.class); |
263 | | - // assertThatThrownBy(() -> table.setOnErrorType(JsonOnErrorType.DEFAULT)) |
264 | | - // .isInstanceOf(IllegalArgumentException.class); |
265 | | - // |
266 | | - // JsonTableColumn column = new JsonTableColumn(); |
267 | | - // |
268 | | - // assertThatThrownBy(() -> { |
269 | | - // column.setType(JsonTableColumnType.JSON_EXISTS); |
270 | | - // column.setFormatJson(true); |
271 | | - // }).isInstanceOf(IllegalArgumentException.class); |
272 | | - // assertThatThrownBy(() -> { |
273 | | - // column.setType(JsonTableColumnType.JSON_VALUE); |
274 | | - // column.setFormatJson(true); |
275 | | - // }).isInstanceOf(IllegalArgumentException.class); |
276 | | - // assertThatThrownBy(() -> { |
277 | | - // column.setType(JsonTableColumnType.ORDINALITY); |
278 | | - // column.setFormatJson(true); |
279 | | - // }).isInstanceOf(IllegalArgumentException.class); |
280 | | - // assertThatThrownBy(() -> { |
281 | | - // column.setType(JsonTableColumnType.JSON_NESTED_PATH); |
282 | | - // column.setFormatJson(true); |
283 | | - // }).isInstanceOf(IllegalArgumentException.class); |
284 | | - // } |
| 180 | + @Test |
| 181 | + void testColumnTypeExists() throws JSQLParserException { |
| 182 | + String expression = "JSON_TABLE(document COLUMNS( hasValue EXISTS PATH '$.pathTest'))"; |
| 183 | + JsonTableFunction table = parseTable(expression); |
| 184 | + |
| 185 | + assertThat(table.getColumnsClause().getColumnDefinitions()).hasSize(1); |
| 186 | + |
| 187 | + JsonTableFunction.JsonTableColumnDefinition col = |
| 188 | + table.getColumnsClause().getColumnDefinitions().get(0); |
| 189 | + assertThat(col).isInstanceOf(JsonTableFunction.JsonTableValueColumnDefinition.class); |
| 190 | + |
| 191 | + JsonTableFunction.JsonTableValueColumnDefinition valueCol = |
| 192 | + (JsonTableFunction.JsonTableValueColumnDefinition) col; |
| 193 | + |
| 194 | + assertThat(valueCol.isExists()).isTrue(); |
| 195 | + } |
285 | 196 |
|
286 | 197 | private JsonTableFunction parseTable(String jsonTableStr) throws JSQLParserException { |
287 | 198 | String sql = "SELECT * FROM " + jsonTableStr; |
|
0 commit comments