Skip to content

Commit

Permalink
Add test files for tsql_openjson_with_get_subjsonb engine crash fix
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Owen <owjco@amazon.com>
  • Loading branch information
Jake Owen committed Jul 2, 2024
1 parent d0d06d9 commit cc65951
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/JDBC/expected/BABEL-3820-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
drop procedure openjson_3820_p1
go

drop procedure openjson_3820_p2
go

drop procedure openjson_3820_p3
go

drop procedure openjson_3820_p4
go

drop procedure openjson_3820_p5
go

drop procedure openjson_3820_p6
go

drop procedure openjson_3820_p7
go

drop procedure openjson_3820_p8
go

drop procedure openjson_3820_p9
go


drop procedure openjson_3820_p10
go

drop procedure openjson_3820_p11
go
106 changes: 106 additions & 0 deletions test/JDBC/expected/BABEL-3820-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- Test strict mode where path does not exist
-- Expect error
CREATE PROCEDURE openjson_3820_p1
AS
BEGIN
SELECT * FROM OPENJSON('{}') WITH(field int 'strict$.field')
END;
GO

-- Test lax mode where path does not exist
-- Expect empty result and no error
CREATE PROCEDURE openjson_3820_p2
AS
BEGIN
DECLARE @json_p2 NVarChar(max)=N'{"someKey" : "someValue"}';
SELECT * from OPENJSON(@json_p2,'$.somePathWhichDoesNotExists') WITH (id VARCHAR(100) '$')
END;
GO

-- Test strict mode where path does not exist
-- Expect an error for no path
CREATE PROCEDURE openjson_3820_p3
AS
BEGIN
DECLARE @json_p3 NVarChar(max)=N'{"someKey" : "someValue"}';
SELECT * from OPENJSON(@json_p3,'strict $.somePathWhichDoesNotExists') WITH (id VARCHAR(100) '$')
END;
GO

-- Test standard OPENJSON call
-- Expect result
CREATE PROCEDURE openjson_3820_p4
AS
BEGIN
DECLARE @json_p4 NVarChar(max)=N'{"obj":{"a":1}}';
SELECT * FROM OPENJSON(@json_p4, 'strict $.obj') WITH (a char(20))
END;
GO

-- Test strict mode where path does not exist
-- Expect error in strict mode
CREATE PROCEDURE openjson_3820_p5
AS
BEGIN
SELECT * FROM OPENJSON(N'[{"Item": {"Price":2024.9940}}]') WITH(field int 'strict $.field')
END;
GO

-- Test lax mode where path does not exist
-- Expect empty result because path does not exist
CREATE PROCEDURE openjson_3820_p6
AS
BEGIN
DECLARE @json_p6 NVARCHAR(4000) = N'{"to":{"sub-object":["en-GB", "en-UK","de-AT","es-AR","sr-Cyrl"]}}';
SELECT [key], value FROM OPENJSON(@json_p6,'lax$.path.to."sub-object"')
END;
GO

-- Test OPENJSON strict call where path exists
-- Expect json result
CREATE PROCEDURE openjson_3820_p7
AS
BEGIN
DECLARE @json_p7 NVARCHAR(4000) = N'{"path": {"to":{"sub-object":["en-GB", "en-UK","de-AT","es-AR","sr-Cyrl"]}}}';
SELECT [key], value FROM OPENJSON(@json_p7,'strict $.path.to."sub-object"')
END;
GO

-- Test OPENJSON strict call where path exists, strict is mixed case,
-- and no space between "strict" and the path. Expect json result
CREATE PROCEDURE openjson_3820_p8
AS
BEGIN
DECLARE @json_p8 NVARCHAR(4000) = N'{"path": {"to":{"sub-object":["en-GB", "en-UK","de-AT","es-AR","sr-Cyrl"]}}}';
SELECT [key], value FROM OPENJSON(@json_p8,'sTrIct$.path.to."sub-object"')
END;
GO

-- Test OPENJSON strict with incorrect path
-- Expect error
CREATE PROCEDURE openjson_3820_p9
AS
BEGIN
DECLARE @json_p9 NVARCHAR(4000) = N'{"to":{"sub-object":["en-GB", "en-UK","de-AT","es-AR","sr-Cyrl"]}}';
SELECT [key], value FROM OPENJSON(@json_p9,'strict $.path.to."sub-object"')
END;
GO

-- Test OPENJSON with incorrect path
-- Expect empty result
CREATE PROCEDURE openjson_3820_p10
AS
BEGIN
DECLARE @json_p10 NVARCHAR(4000) = N'{"to":{"sub-object":["en-GB", "en-UK","de-AT","es-AR","sr-Cyrl"]}}';
SELECT [key], value FROM OPENJSON(@json_p10,'$.path.to."sub-object"')
END;
GO

-- Test strict mode where path does not exist
-- Expect error in strict mode
CREATE PROCEDURE openjson_3820_p11
AS
BEGIN
SELECT * FROM OPENJSON(N'{}') WITH(field int 'strict $.field')
END;
GO
120 changes: 120 additions & 0 deletions test/JDBC/expected/BABEL-3820-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
-- Test strict mode where path does not exist
-- Expect error
exec openjson_3820_p1
go
~~START~~
int
~~ERROR (Code: 33557097)~~

~~ERROR (Message: JSON object does not contain key "field")~~


-- Test lax mode where path does not exist
-- Expect empty result and no error
exec openjson_3820_p2
go
~~START~~
varchar
<NULL>
~~END~~


-- Test strict mode where path does not exist
-- Expect an error for no path
exec openjson_3820_p3
go
~~START~~
varchar
~~ERROR (Code: 33557097)~~

~~ERROR (Message: JSON object does not contain key "somePathWhichDoesNotExists")~~


-- Test standard OPENJSON call
-- Expect result
exec openjson_3820_p4
go
~~START~~
char
1
~~END~~


-- Test strict mode where path does not exist
-- Expect error in strict mode
exec openjson_3820_p5
go
~~START~~
int
~~ERROR (Code: 33557097)~~

~~ERROR (Message: JSON object does not contain key "field")~~


-- Test lax mode where path does not exist
-- Expect empty result because path does not exist
exec openjson_3820_p6
go
~~START~~
nvarchar#!#nvarchar
~~END~~


-- Test OPENJSON strict call where path exists
-- Expect json result
exec openjson_3820_p7
go
~~START~~
nvarchar#!#nvarchar
0#!#en-GB
1#!#en-UK
2#!#de-AT
3#!#es-AR
4#!#sr-Cyrl
~~END~~


-- Test OPENJSON strict call where path exists, strict is mixed case,
-- and no space between "strict" and the path. Expect json result
exec openjson_3820_p8
go
~~START~~
nvarchar#!#nvarchar
0#!#en-GB
1#!#en-UK
2#!#de-AT
3#!#es-AR
4#!#sr-Cyrl
~~END~~


-- Test OPENJSON strict with incorrect path
-- Expect error
exec openjson_3820_p9
go
~~START~~
nvarchar#!#nvarchar
~~ERROR (Code: 33557097)~~

~~ERROR (Message: JSON object does not contain key "path")~~


-- Test OPENJSON with incorrect path
-- Expect empty result
exec openjson_3820_p10
go
~~START~~
nvarchar#!#nvarchar
~~END~~


-- Test strict mode where path does not exist
-- Expect error in strict mode
exec openjson_3820_p11
go
~~START~~
int
~~ERROR (Code: 33557097)~~

~~ERROR (Message: JSON object does not contain key "field")~~

33 changes: 33 additions & 0 deletions test/JDBC/input/openjson/BABEL-3820-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
drop procedure openjson_3820_p1
go

drop procedure openjson_3820_p2
go

drop procedure openjson_3820_p3
go

drop procedure openjson_3820_p4
go

drop procedure openjson_3820_p5
go

drop procedure openjson_3820_p6
go

drop procedure openjson_3820_p7
go

drop procedure openjson_3820_p8
go

drop procedure openjson_3820_p9
go


drop procedure openjson_3820_p10
go

drop procedure openjson_3820_p11
go
Loading

0 comments on commit cc65951

Please sign in to comment.