Skip to content

Commit

Permalink
Improved 8694 E2E test and for loop in renameFields
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Sep 2, 2021
1 parent 6e97c45 commit 93a5e93
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
19 changes: 19 additions & 0 deletions go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,25 @@ ts12 TIMESTAMP DEFAULT LOCALTIME()
exec(t, conn, "drop table function_default")
}

func TestRenameFieldsOnOLAP(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()

_ = exec(t, conn, "set workload = olap")
defer func() {
exec(t, conn, "set workload = oltp")
}()

qr := exec(t, conn, "show tables")
assert.Equal(t, `[[VARCHAR("aggr_test")] [VARCHAR("t1")] [VARCHAR("t1_id2_idx")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t3")] [VARCHAR("t3_id7_idx")] [VARCHAR("t4")] [VARCHAR("t4_id2_idx")] [VARCHAR("t5_null_vindex")] [VARCHAR("t6")] [VARCHAR("t6_id2_idx")] [VARCHAR("t7_fk")] [VARCHAR("t7_xxhash")] [VARCHAR("t7_xxhash_idx")] [VARCHAR("t8")] [VARCHAR("vstream_test")]]`, fmt.Sprintf("%v", qr.Rows))
_ = exec(t, conn, "use mysql")
qr = exec(t, conn, "select @@workload")
assert.Equal(t, `[[VARBINARY("OLAP")]]`, fmt.Sprintf("%v", qr.Rows))
}

func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) {
t.Helper()
qr := exec(t, conn, query)
Expand Down
11 changes: 0 additions & 11 deletions go/vt/vtgate/endtoend/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,3 @@ func TestCreateAndDropDatabase(t *testing.T) {
})
}
}

func TestRenameFieldsOnOLAP(t *testing.T) {
// note that this is testing vttest and not vtgate
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()

_ = exec(t, conn, "set workload = olap")
qr := exec(t, conn, "show tables")
assert.Equal(t, `[[VARCHAR("aggr_test")] [VARCHAR("t1")] [VARCHAR("t1_id2_idx")] [VARCHAR("t1_last_insert_id")] [VARCHAR("t1_row_count")] [VARCHAR("t1_sharded")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("vstream_test")]]`, fmt.Sprintf("%v", qr.Rows))
}
9 changes: 3 additions & 6 deletions go/vt/vtgate/engine/rename_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ func (r *RenameFields) Execute(vcursor VCursor, bindVars map[string]*querypb.Bin
}

func (r *RenameFields) renameFields(qr *sqltypes.Result) {
if len(r.Indices) != len(qr.Fields) {
return
}
for ind, index := range r.Indices {
colName := r.Cols[ind]
qr.Fields[index].Name = colName
for i := 0; i < len(r.Indices) && i < len(qr.Fields); i++ {
colName := r.Cols[r.Indices[i]]
qr.Fields[i].Name = colName
}
}

Expand Down

0 comments on commit 93a5e93

Please sign in to comment.