polardbxengine/mysql-test/suite/x/r/crud_doc_expr_array.result

1003 lines
23 KiB
Plaintext

=============================================
CRUD DOC ARRAY EXPRESIONS SCENARIOS
=============================================
================================================================================
PREAMBLE
================================================================================
================================================================================
TEST START
================================================================================
RUN DROP SCHEMA IF EXISTS xtest
0 rows affected
RUN CREATE SCHEMA xtest
1 rows affected
command ok
Inserting array into collection
send Mysqlx.Crud.Insert {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
row {
field {
type: OBJECT
object {
fld {
key: "_id"
value {
type: LITERAL
literal {
type: V_OCTETS
v_octets {
value: "1"
}
}
}
}
fld {
key: "first"
value {
type: LITERAL
literal {
type: V_OCTETS
v_octets {
value: "ten"
}
}
}
}
fld {
key: "second"
value {
type: LITERAL
literal {
type: V_OCTETS
v_octets {
value: "twenty"
}
}
}
}
fld {
key: "third"
value {
type: LITERAL
literal {
type: V_OCTETS
v_octets {
value: "thirty"
}
}
}
}
fld {
key: "units"
value {
type: ARRAY
array {
value {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 1
}
}
value {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 2
}
}
value {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 3
}
}
value {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 4
}
}
value {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 5
}
}
}
}
}
}
}
}
}
1 rows affected
RUN SELECT * FROM xtest.xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "second": "twenty"} 1
0 rows affected
Inserting array into collection with all the datatypes
send Mysqlx.Crud.Insert {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
row {
field {
type: OBJECT
object {
fld {
key: "_id"
value {
type: LITERAL
literal {
type: V_OCTETS
v_octets {
value: "2"
}
}
}
}
fld {
key: "first"
value {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "ten again"
}
}
}
}
fld {
key: "second"
value {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "twenty again"
}
}
}
}
fld {
key: "third"
value {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "thirty again"
}
}
}
}
fld {
key: "units"
value {
type: ARRAY
array {
value {
type: LITERAL
literal {
type: V_SINT
v_signed_int: 1
}
}
value {
type: LITERAL
literal {
type: V_UINT
v_unsigned_int: 2
}
}
value {
type: LITERAL
literal {
type: V_DOUBLE
v_double: 3.13
}
}
value {
type: LITERAL
literal {
type: V_FLOAT
v_float: 4.34
}
}
value {
type: LITERAL
literal {
type: V_BOOL
v_bool: true
}
}
value {
type: LITERAL
literal {
type: V_NULL
}
}
value {
type: LITERAL
literal {
type: V_STRING
v_string {
value: "extrainfo"
}
}
}
}
}
}
}
}
}
}
1 rows affected
RUN SELECT * FROM xtest.xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "second": "twenty"} 1
{"_id": "2", "first": "ten again", "third": "thirty again", "units": [1, 2, 3.13, 4.34, true, null, "extrainfo"], "second": "twenty again"} 2
0 rows affected
Selecting array from collection
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: OBJECT
object {
fld {
key: "dozens"
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "first"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "second"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "third"
}
}
}
}
}
}
}
}
}
}
doc
{"dozens": ["ten", "twenty", "thirty"]}
{"dozens": ["ten again", "twenty again", "thirty again"]}
command ok
Selecting array from collection
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: OBJECT
object {
fld {
key: "UnitArray"
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
}
}
}
}
}
}
}
}
}
doc
{"UnitArray": [[1, 2, 3, 4, 5]]}
{"UnitArray": [[1, 2, 3.13, 4.34, true, null, "extrainfo"]]}
command ok
Selecting a value not available from collection to get null values
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: OBJECT
object {
fld {
key: "UnitArray"
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "notavailable"
}
}
}
}
}
}
}
}
}
}
doc
{"UnitArray": [null]}
{"UnitArray": [null]}
command ok
Selecting array from collection with alias
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "first"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "second"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "third"
}
}
}
}
}
alias: "dozens"
}
}
doc
{"dozens": ["ten", "twenty", "thirty"]}
{"dozens": ["ten again", "twenty again", "thirty again"]}
command ok
Selecting array from collection with alias
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
}
}
}
}
alias: "UnitArray"
}
}
doc
{"UnitArray": [[1, 2, 3, 4, 5]]}
{"UnitArray": [[1, 2, 3.13, 4.34, true, null, "extrainfo"]]}
command ok
Selecting a value not available from collection to get null values with alias
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "notavailable"
}
}
}
}
}
alias: "UnitArray_Null"
}
}
doc
{"UnitArray_Null": [null]}
{"UnitArray_Null": [null]}
command ok
RUN use xtest
0 rows affected
RUN select * from xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "second": "twenty"} 1
{"_id": "2", "first": "ten again", "third": "thirty again", "units": [1, 2, 3.13, 4.34, true, null, "extrainfo"], "second": "twenty again"} 2
0 rows affected
Selecting array with sub-array from collection with alias
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "first"
}
}
}
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 0
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 2
}
}
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "second"
}
}
}
}
}
alias: "numbers"
}
}
doc
{"numbers": ["ten", [1, 3], "twenty"]}
{"numbers": ["ten again", [1, 3.13], "twenty again"]}
command ok
Selecting array with sub-array including null values from collection with alias
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: ARRAY
array {
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 1
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 5
}
}
}
}
}
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 2
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 5
}
}
}
}
}
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 3
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
document_path {
type: ARRAY_INDEX
index: 5
}
}
}
}
}
}
}
alias: "Array_SubArray_Null"
}
}
doc
{"Array_SubArray_Null": [[2, null], [3, null], [4, null]]}
{"Array_SubArray_Null": [[2, null], [3.13, null], [4.34, null]]}
command ok
Updating collection by array
send Mysqlx.Crud.Update {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
operation {
source {
document_path {
type: MEMBER
value: "dozens"
}
}
operation: ITEM_SET
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "first"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "second"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "third"
}
}
}
}
}
}
}
2 rows affected
Rows matched: 2 Changed: 2 Warnings: 0
RUN SELECT * FROM xtest.xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "dozens": ["ten", "twenty", "thirty"], "second": "twenty"} 1
{"_id": "2", "first": "ten again", "third": "thirty again", "units": [1, 2, 3.13, 4.34, true, null, "extrainfo"], "dozens": ["ten again", "twenty again", "thirty again"], "second": "twenty again"} 2
0 rows affected
Updating collection by array with null values
send Mysqlx.Crud.Update {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
operation {
source {
document_path {
type: MEMBER
value: "NewArray"
}
}
operation: ITEM_SET
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "dozens"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "first"
}
}
}
}
}
}
}
2 rows affected
Rows matched: 2 Changed: 2 Warnings: 0
RUN SELECT * FROM xtest.xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "dozens": ["ten", "twenty", "thirty"], "second": "twenty", "NewArray": [[1, 2, 3, 4, 5], ["ten", "twenty", "thirty"], "ten"]} 1
{"_id": "2", "first": "ten again", "third": "thirty again", "units": [1, 2, 3.13, 4.34, true, null, "extrainfo"], "dozens": ["ten again", "twenty again", "thirty again"], "second": "twenty again", "NewArray": [[1, 2, 3.13, 4.34, true, null, "extrainfo"], ["ten again", "twenty again", "thirty again"], "ten again"]} 2
0 rows affected
Updating collection by array in a current member value
send Mysqlx.Crud.Update {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
operation {
source {
document_path {
type: MEMBER
value: "second"
}
}
operation: ITEM_REPLACE
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "dozens"
}
}
}
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "first"
}
}
}
}
}
}
}
2 rows affected
Rows matched: 2 Changed: 2 Warnings: 0
RUN SELECT * FROM xtest.xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "dozens": ["ten", "twenty", "thirty"], "second": [[1, 2, 3, 4, 5], ["ten", "twenty", "thirty"], "ten"], "NewArray": [[1, 2, 3, 4, 5], ["ten", "twenty", "thirty"], "ten"]} 1
{"_id": "2", "first": "ten again", "third": "thirty again", "units": [1, 2, 3.13, 4.34, true, null, "extrainfo"], "dozens": ["ten again", "twenty again", "thirty again"], "second": [[1, 2, 3.13, 4.34, true, null, "extrainfo"], ["ten again", "twenty again", "thirty again"], "ten again"], "NewArray": [[1, 2, 3.13, 4.34, true, null, "extrainfo"], ["ten again", "twenty again", "thirty again"], "ten again"]} 2
0 rows affected
Updating collection by appending an array in a current array member value
send Mysqlx.Crud.Update {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
operation {
source {
document_path {
type: MEMBER
value: "second"
}
}
operation: ARRAY_APPEND
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
}
}
}
}
}
}
2 rows affected
Rows matched: 2 Changed: 2 Warnings: 0
RUN SELECT * FROM xtest.xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "dozens": ["ten", "twenty", "thirty"], "second": [[1, 2, 3, 4, 5], ["ten", "twenty", "thirty"], "ten", [[1, 2, 3, 4, 5]]], "NewArray": [[1, 2, 3, 4, 5], ["ten", "twenty", "thirty"], "ten"]} 1
{"_id": "2", "first": "ten again", "third": "thirty again", "units": [1, 2, 3.13, 4.34, true, null, "extrainfo"], "dozens": ["ten again", "twenty again", "thirty again"], "second": [[1, 2, 3.13, 4.34, true, null, "extrainfo"], ["ten again", "twenty again", "thirty again"], "ten again", [[1, 2, 3.13, 4.34, true, null, "extrainfo"]]], "NewArray": [[1, 2, 3.13, 4.34, true, null, "extrainfo"], ["ten again", "twenty again", "thirty again"], "ten again"]} 2
0 rows affected
Updating collection by inserting an array in a current array member value using == criteria
send Mysqlx.Crud.Update {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
criteria {
type: OPERATOR
operator {
name: "=="
param {
type: IDENT
identifier {
name: "_id"
}
}
param {
type: LITERAL
literal {
type: V_OCTETS
v_octets {
value: "2"
}
}
}
}
}
operation {
source {
document_path {
type: MEMBER
value: "second"
}
document_path {
type: ARRAY_INDEX
index: 0
}
}
operation: ARRAY_INSERT
value {
type: ARRAY
array {
value {
type: IDENT
identifier {
document_path {
type: MEMBER
value: "units"
}
}
}
}
}
}
}
1 rows affected
Rows matched: 1 Changed: 1 Warnings: 0
RUN SELECT * FROM xtest.xcoll
doc _id
{"_id": "1", "first": "ten", "third": "thirty", "units": [1, 2, 3, 4, 5], "dozens": ["ten", "twenty", "thirty"], "second": [[1, 2, 3, 4, 5], ["ten", "twenty", "thirty"], "ten", [[1, 2, 3, 4, 5]]], "NewArray": [[1, 2, 3, 4, 5], ["ten", "twenty", "thirty"], "ten"]} 1
{"_id": "2", "first": "ten again", "third": "thirty again", "units": [1, 2, 3.13, 4.34, true, null, "extrainfo"], "dozens": ["ten again", "twenty again", "thirty again"], "second": [[[1, 2, 3.13, 4.34, true, null, "extrainfo"]], [1, 2, 3.13, 4.34, true, null, "extrainfo"], ["ten again", "twenty again", "thirty again"], "ten again", [[1, 2, 3.13, 4.34, true, null, "extrainfo"]]], "NewArray": [[1, 2, 3.13, 4.34, true, null, "extrainfo"], ["ten again", "twenty again", "thirty again"], "ten again"]} 2
0 rows affected
Error: empty array
send Mysqlx.Crud.Find {
collection {
name: "xcoll"
schema: "xtest"
}
data_model: DOCUMENT
projection {
source {
type: ARRAY
array {
}
}
}
}
Got expected error:
Mysqlx.Error {
severity: ERROR
code: 5120
msg: "Invalid projection target name"
sql_state: "HY000"
}
================================================================================
CLEAN UP
================================================================================
RUN drop schema if exists xtest
1 rows affected
Mysqlx.Ok {
msg: "bye!"
}
ok