Skip to content

Commit

Permalink
test: failing unit test for type aggregation (#15518)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Dirkjan Bussink <[email protected]>
Co-authored-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
systay and dbussink authored Mar 19, 2024
1 parent 01752b7 commit b3f6121
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 34 deletions.
4 changes: 2 additions & 2 deletions go/vt/vtgate/evalengine/api_type_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (ta *typeAggregation) add(tt sqltypes.Type, f typeFlag) {
ta.timestamp++
case sqltypes.Geometry:
ta.geometry++
case sqltypes.Blob:
case sqltypes.Blob, sqltypes.Text:
ta.blob++
default:
return
Expand Down Expand Up @@ -209,7 +209,7 @@ func (ta *typeAggregation) result() sqltypes.Type {
If all temporal types are DATE, TIME, or TIMESTAMP, the result is DATE, TIME, or TIMESTAMP, respectively.
Otherwise, for a mix of temporal types, the result is DATETIME.
If all types are GEOMETRY, the result is GEOMETRY.
If any type is BLOB, the result is BLOB.
If any type is BLOB, the result is BLOB. This also applies to TEXT.
For all other type combinations, the result is VARCHAR.
Literal NULL operands are ignored for type aggregation.
*/
Expand Down
54 changes: 28 additions & 26 deletions go/vt/vtgate/evalengine/api_type_aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,34 @@ import (
"vitess.io/vitess/go/sqltypes"
)

var aggregationCases = []struct {
types []sqltypes.Type
result sqltypes.Type
}{
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Int32, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Decimal, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Int32, sqltypes.Decimal}, sqltypes.Decimal},
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Int32, sqltypes.Int64}, sqltypes.Int64},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Int16, sqltypes.Int8}, sqltypes.Int32},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Uint16, sqltypes.Uint8}, sqltypes.Int32},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Uint16, sqltypes.Uint32}, sqltypes.Int64},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Uint16, sqltypes.Uint64}, sqltypes.Decimal},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Bit, sqltypes.Bit}, sqltypes.Bit},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Int32, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Decimal, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Int32, sqltypes.Decimal}, sqltypes.Decimal},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Int32, sqltypes.Int64}, sqltypes.Int64},
{[]sqltypes.Type{sqltypes.Char, sqltypes.VarChar}, sqltypes.VarChar},
{[]sqltypes.Type{sqltypes.Char, sqltypes.Char}, sqltypes.VarChar},
{[]sqltypes.Type{sqltypes.Char, sqltypes.VarChar, sqltypes.VarBinary}, sqltypes.VarBinary},
{[]sqltypes.Type{sqltypes.Char, sqltypes.Char, sqltypes.Set, sqltypes.Enum}, sqltypes.VarChar},
{[]sqltypes.Type{sqltypes.TypeJSON, sqltypes.TypeJSON}, sqltypes.TypeJSON},
{[]sqltypes.Type{sqltypes.Geometry, sqltypes.Geometry}, sqltypes.Geometry},
}

func TestEvalengineTypeAggregations(t *testing.T) {
aggregationCases := []struct {
types []sqltypes.Type
result sqltypes.Type
}{
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Int32, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Decimal, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Int32, sqltypes.Decimal}, sqltypes.Decimal},
{[]sqltypes.Type{sqltypes.Int64, sqltypes.Int32, sqltypes.Int64}, sqltypes.Int64},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Int16, sqltypes.Int8}, sqltypes.Int32},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Uint16, sqltypes.Uint8}, sqltypes.Int32},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Uint16, sqltypes.Uint32}, sqltypes.Int64},
{[]sqltypes.Type{sqltypes.Int32, sqltypes.Uint16, sqltypes.Uint64}, sqltypes.Decimal},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Bit, sqltypes.Bit}, sqltypes.Bit},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Int32, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Decimal, sqltypes.Float64}, sqltypes.Float64},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Int32, sqltypes.Decimal}, sqltypes.Decimal},
{[]sqltypes.Type{sqltypes.Bit, sqltypes.Int32, sqltypes.Int64}, sqltypes.Int64},
{[]sqltypes.Type{sqltypes.Char, sqltypes.VarChar}, sqltypes.VarChar},
{[]sqltypes.Type{sqltypes.Char, sqltypes.Char}, sqltypes.VarChar},
{[]sqltypes.Type{sqltypes.Char, sqltypes.VarChar, sqltypes.VarBinary}, sqltypes.VarBinary},
{[]sqltypes.Type{sqltypes.Char, sqltypes.Char, sqltypes.Set, sqltypes.Enum}, sqltypes.VarChar},
{[]sqltypes.Type{sqltypes.TypeJSON, sqltypes.TypeJSON}, sqltypes.TypeJSON},
{[]sqltypes.Type{sqltypes.Geometry, sqltypes.Geometry}, sqltypes.Geometry},
{[]sqltypes.Type{sqltypes.Text, sqltypes.Text}, sqltypes.Blob},
{[]sqltypes.Type{sqltypes.Blob, sqltypes.Blob}, sqltypes.Blob},
}
collEnv := collations.MySQL8()
for i, tc := range aggregationCases {
t.Run(fmt.Sprintf("%d.%v", i, tc.result), func(t *testing.T) {
var typer TypeAggregator
Expand All @@ -60,7 +62,7 @@ func TestEvalengineTypeAggregations(t *testing.T) {
// this test only aggregates binary collations because textual collation
// aggregation is tested in the `mysql/collations` package

err := typer.Add(NewType(tt, collations.CollationBinaryID), collations.MySQL8())
err := typer.Add(NewType(tt, collations.CollationBinaryID), collEnv)
require.NoError(t, err)
}

Expand Down
11 changes: 5 additions & 6 deletions go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@
"17: utf8mb3_general_ci",
"18",
"19: utf8mb3_general_ci",
"(20:21)"
"20"
],
"ResultColumns": 21,
"Inputs": [
{
"OperatorType": "Concatenate",
Expand All @@ -180,8 +179,8 @@
"Name": "main",
"Sharded": false
},
"FieldQuery": "select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT, weight_string(TABLE_COMMENT) from information_schema.`tables` where 1 != 1",
"Query": "select distinct TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT, weight_string(TABLE_COMMENT) from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */",
"FieldQuery": "select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT from information_schema.`tables` where 1 != 1",
"Query": "select distinct TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */",
"SysTableTableSchema": "['user']",
"Table": "information_schema.`tables`"
},
Expand All @@ -192,8 +191,8 @@
"Name": "main",
"Sharded": false
},
"FieldQuery": "select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT, weight_string(TABLE_COMMENT) from information_schema.`tables` where 1 != 1",
"Query": "select distinct TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT, weight_string(TABLE_COMMENT) from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */",
"FieldQuery": "select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT from information_schema.`tables` where 1 != 1",
"Query": "select distinct TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, `ENGINE`, VERSION, `ROW_FORMAT`, TABLE_ROWS, `AVG_ROW_LENGTH`, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, `AUTO_INCREMENT`, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, `CHECKSUM`, CREATE_OPTIONS, TABLE_COMMENT from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */",
"SysTableTableSchema": "['main']",
"Table": "information_schema.`tables`"
}
Expand Down
43 changes: 43 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/union_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,49 @@
]
}
},
{
"comment": "test handling of TEXT column type handling",
"query": "select table_comment from information_schema.tables union select table_comment from information_schema.tables",
"plan": {
"QueryType": "SELECT",
"Original": "select table_comment from information_schema.tables union select table_comment from information_schema.tables",
"Instructions": {
"OperatorType": "Distinct",
"Collations": [
"0"
],
"Inputs": [
{
"OperatorType": "Concatenate",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "DBA",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"FieldQuery": "select table_comment from information_schema.`tables` where 1 != 1",
"Query": "select distinct table_comment from information_schema.`tables`",
"Table": "information_schema.`tables`"
},
{
"OperatorType": "Route",
"Variant": "DBA",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"FieldQuery": "select table_comment from information_schema.`tables` where 1 != 1",
"Query": "select distinct table_comment from information_schema.`tables`",
"Table": "information_schema.`tables`"
}
]
}
]
}
}
},
{
"comment": "UNION that needs to be reordered to be merged more aggressively. Gen4 is able to get it down to 2 routes",
"query": "select col from unsharded union select id from user union select col2 from unsharded union select col from user_extra",
Expand Down

0 comments on commit b3f6121

Please sign in to comment.