895 lines
16 KiB
Plaintext
895 lines
16 KiB
Plaintext
########### ../t/update_crud_itemmerge_o.test #############
|
|
### #
|
|
### This test runs aims to run UPDATE ITEM_MERGE operation statement #
|
|
### variant with mysqlxtest client. #
|
|
### Test covers #
|
|
### - update with different operators #
|
|
### - update multiple rows #
|
|
### - update with rollback transaction #
|
|
### - update insert with different array indexes #
|
|
### #
|
|
########################################################################
|
|
#
|
|
|
|
--echo =============================================
|
|
--echo CRUD UPDATE ITEM_MERGE SCENARIOS
|
|
--echo =============================================
|
|
--echo
|
|
|
|
--echo ================================================================================
|
|
--echo PREAMBLE
|
|
--echo ================================================================================
|
|
|
|
--source include/xplugin_preamble.inc
|
|
|
|
create user updateitemmerge@localhost identified by 'updateitemmerge';
|
|
grant all on *.* to updateitemmerge@localhost;
|
|
CREATE SCHEMA mysqlxcoll;
|
|
|
|
## TEST STARTS HERE
|
|
--echo ================================================================================
|
|
--echo TEST START
|
|
--echo ================================================================================
|
|
|
|
--write_file $MYSQL_TMP_DIR/mysqlx-update_collection_itemmerge.tmp
|
|
|
|
-->stmtadmin create_collection {"schema":"mysqlxcoll","name":"maincoll"}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
SET SQL_SAFE_UPDATES = 0;
|
|
USE mysqlxcoll;
|
|
INSERT INTO maincoll (doc) values ('{"_id": "1", "name": ["Victor"], "last_name": ["Otero"],"amount": [4.99]}');
|
|
INSERT INTO maincoll (doc) values ('{"_id": "2", "name": ["Gonzalo"], "last_name": ["Chrystens"],"amount": [120.57]}');
|
|
INSERT INTO maincoll (doc) values ('{"_id": "3", "name": ["Abraham"], "last_name": ["Vega"],"amount": [74.56]}');
|
|
INSERT INTO maincoll (doc) values ('{"_id": "4", "name": ["Jennifer"], "last_name": ["Leon"],"amount": [387.14]}');
|
|
INSERT INTO maincoll (doc) values ('{"_id": "5", "name": ["Jhonny"], "last_name": ["Test"],"amount": [125.45]}');
|
|
-->endsql
|
|
|
|
-->echo Update merge String value into Array using == Operator for criteria
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_STRING v_string { value: "{\"name\":\"Vic\", \"last_name\":\"Ote\"}" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with == operator and Quotes
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_STRING v_string { value: "{\"reference\":\"from Mexico\"}" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with > operator for multiple docs
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: ">"
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"3"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:"{\"name\":\"> with id 3\",\"applied_operator\":\"> with id 3\"}"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with < operator for multiple docs
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "<"
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"2"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_STRING v_string { value: "{\"name\":\"< with id 2\",\"applied_operator\":\"< with id 2\"}" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with <= operator for multiple docs
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "<="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"2"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_STRING v_string { value: "{\"name\":\"<= with id 2\",\"applied_operator\":\"<= with id 2\"}" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with >= operator for multiple docs
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: ">="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"3"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount":256.57, "name": ">= with id 3"}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with != operator for multiple docs
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "!="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"4"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount":24.8752643, "last_name": "!= 4"}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update item_merge a NULL
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"2"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"name": null}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update item_merge a String into a only numbers member
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"2"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount": "String"}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with order clause update last _id in desc order (_id = 5)
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "!="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"0"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
limit {
|
|
row_count: 1
|
|
}
|
|
order {
|
|
expr {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
direction: DESC
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount": 1234.567}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with order clause update first two _id in asc order (_id = 1,2)
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "!="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"0"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
limit {
|
|
row_count: 2
|
|
}
|
|
order {
|
|
expr {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
direction: ASC
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount": 9876.543}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update item_merge a number into a only String member
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"name": 199896}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
START TRANSACTION;
|
|
-->endsql
|
|
|
|
-->echo Update transaction rollback
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount": 452.253}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
ROLLBACK;
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update transaction commit
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount": 452.253}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->recvresult
|
|
|
|
-->sql
|
|
COMMIT;
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with non existing doc member
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'iamnotadoc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount": 987.24}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->expecterror 1054
|
|
-->recvresult
|
|
|
|
-->sql
|
|
select * from maincoll;
|
|
-->endsql
|
|
|
|
-->echo Update with item_merge with } missing at the end
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_STRING v_string { value: "{\"reference\":\"from Mexico\"" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->expecterror 3141
|
|
-->recvresult
|
|
|
|
-->echo Update with item_merge with } missing at the start
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_STRING v_string { value: "\"reference\":\"from Mexico\"}" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->expecterror 3141
|
|
-->recvresult
|
|
|
|
-->echo Update with missing comma
|
|
Mysqlx.Crud.Update {
|
|
collection {
|
|
name: "maincoll"
|
|
schema: "mysqlxcoll"
|
|
}
|
|
data_model: TABLE
|
|
criteria {
|
|
type: OPERATOR
|
|
operator {
|
|
name: "=="
|
|
param {
|
|
type: IDENT
|
|
identifier {
|
|
name: "_id"
|
|
}
|
|
}
|
|
param {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS
|
|
v_octets {value:"1"}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
operation {
|
|
source {
|
|
name: 'doc'
|
|
}
|
|
operation: ITEM_MERGE
|
|
value {
|
|
type: LITERAL
|
|
literal {
|
|
type: V_OCTETS v_octets {value:'{"amount": 987.24 "name": "Name"}'}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-->expecterror 3141
|
|
-->recvresult
|
|
|
|
## Cleanup
|
|
-->echo ================================================================================
|
|
-->echo CLEAN UP
|
|
-->echo ================================================================================
|
|
-->sql
|
|
DROP USER updateitemmerge@localhost;
|
|
SET SQL_SAFE_UPDATES = 1;
|
|
-->endsql
|
|
EOF
|
|
|
|
--exec $MYSQLXTEST -u updateitemmerge --password='updateitemmerge' --file=$MYSQL_TMP_DIR/mysqlx-update_collection_itemmerge.tmp 2>&1
|
|
|
|
## Cleanup
|
|
DROP SCHEMA if EXISTS mysqlxcoll;
|
|
--remove_file $MYSQL_TMP_DIR/mysqlx-update_collection_itemmerge.tmp
|
|
|