Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User defined and sys variables #10547

Merged
merged 18 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go/mysql/binlog_event_make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func TestTableMapEvent(t *testing.T) {

tableID := event.TableID(f)
if tableID != 0x102030405060 {
t.Fatalf("NewTableMapEvent().TableID returned %x", tableID)
t.Fatalf("NewTableMapEvent().ID returned %x", tableID)
}
gotTm, err := event.TableMap(f)
if err != nil {
Expand All @@ -310,9 +310,9 @@ func TestRowsEvent(t *testing.T) {
/*
Reason for nolint
Used in line 384 to 387
tableID = event.TableID(f)
tableID = event.ID(f)
if tableID != 0x102030405060 {
t.Fatalf("NewRowsEvent().TableID returned %x", tableID)
t.Fatalf("NewRowsEvent().ID returned %x", tableID)
}
*/
tableID := uint64(0x102030405060) //nolint
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestRowsEvent(t *testing.T) {

tableID = event.TableID(f)
if tableID != 0x102030405060 {
t.Fatalf("NewRowsEvent().TableID returned %x", tableID)
t.Fatalf("NewRowsEvent().ID returned %x", tableID)
}
gotRows, err := event.Rows(f, tm)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions go/test/utils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ limitations under the License.
package utils

import (
"os"
"reflect"
"testing"

"github.com/stretchr/testify/require"

"google.golang.org/protobuf/encoding/prototext"

"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -102,3 +105,18 @@ func MustMatchPB(t *testing.T, expected string, pb proto.Message) {

MustMatch(t, expectedPb, pb)
}

func MakeTestOutput(t *testing.T, dir, pattern string) string {
testOutputTempDir, err := os.MkdirTemp(dir, pattern)
require.NoError(t, err)

t.Cleanup(func() {
if !t.Failed() {
_ = os.RemoveAll(testOutputTempDir)
} else {
t.Logf("Errors found in plantests. If the output is correct, run `cp %s/* testdata/` to update test expectations", testOutputTempDir)
}
})

return testOutputTempDir
}
12 changes: 6 additions & 6 deletions go/vt/binlog/binlog_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (bls *Streamer) parseEvents(ctx context.Context, events <-chan mysql.Binlog
}

// Find and fill in the table schema.
tce.ti = bls.se.GetTable(sqlparser.NewTableIdent(tm.Name))
tce.ti = bls.se.GetTable(sqlparser.NewIdentifierCS(tm.Name))
if tce.ti == nil {
return pos, fmt.Errorf("unknown table %v in schema", tm.Name)
}
Expand Down Expand Up @@ -604,7 +604,7 @@ func (bls *Streamer) parseEvents(ctx context.Context, events <-chan mysql.Binlog
func (bls *Streamer) appendInserts(statements []FullBinlogStatement, tce *tableCacheEntry, rows *mysql.Rows) []FullBinlogStatement {
for i := range rows.Rows {
sql := sqlparser.NewTrackedBuffer(nil)
sql.Myprintf("INSERT INTO %v SET ", sqlparser.NewTableIdent(tce.tm.Name))
sql.Myprintf("INSERT INTO %v SET ", sqlparser.NewIdentifierCS(tce.tm.Name))

keyspaceIDCell, pkValues, err := writeValuesAsSQL(sql, tce, rows, i, tce.pkNames != nil)
if err != nil {
Expand Down Expand Up @@ -640,7 +640,7 @@ func (bls *Streamer) appendInserts(statements []FullBinlogStatement, tce *tableC
func (bls *Streamer) appendUpdates(statements []FullBinlogStatement, tce *tableCacheEntry, rows *mysql.Rows) []FullBinlogStatement {
for i := range rows.Rows {
sql := sqlparser.NewTrackedBuffer(nil)
sql.Myprintf("UPDATE %v SET ", sqlparser.NewTableIdent(tce.tm.Name))
sql.Myprintf("UPDATE %v SET ", sqlparser.NewIdentifierCS(tce.tm.Name))

keyspaceIDCell, pkValues, err := writeValuesAsSQL(sql, tce, rows, i, tce.pkNames != nil)
if err != nil {
Expand Down Expand Up @@ -683,7 +683,7 @@ func (bls *Streamer) appendUpdates(statements []FullBinlogStatement, tce *tableC
func (bls *Streamer) appendDeletes(statements []FullBinlogStatement, tce *tableCacheEntry, rows *mysql.Rows) []FullBinlogStatement {
for i := range rows.Rows {
sql := sqlparser.NewTrackedBuffer(nil)
sql.Myprintf("DELETE FROM %v WHERE ", sqlparser.NewTableIdent(tce.tm.Name))
sql.Myprintf("DELETE FROM %v WHERE ", sqlparser.NewIdentifierCS(tce.tm.Name))

keyspaceIDCell, pkValues, err := writeIdentifiersAsSQL(sql, tce, rows, i, tce.pkNames != nil)
if err != nil {
Expand Down Expand Up @@ -743,7 +743,7 @@ func writeValuesAsSQL(sql *sqlparser.TrackedBuffer, tce *tableCacheEntry, rs *my
if valueIndex > 0 {
sql.WriteString(", ")
}
sql.Myprintf("%v", sqlparser.NewColIdent(tce.ti.Fields[c].Name))
sql.Myprintf("%v", sqlparser.NewIdentifierCI(tce.ti.Fields[c].Name))
sql.WriteByte('=')

if rs.Rows[rowIndex].NullColumns.Bit(valueIndex) {
Expand Down Expand Up @@ -808,7 +808,7 @@ func writeIdentifiersAsSQL(sql *sqlparser.TrackedBuffer, tce *tableCacheEntry, r
if valueIndex > 0 {
sql.WriteString(" AND ")
}
sql.Myprintf("%v", sqlparser.NewColIdent(tce.ti.Fields[c].Name))
sql.Myprintf("%v", sqlparser.NewIdentifierCI(tce.ti.Fields[c].Name))

if rs.Rows[rowIndex].NullIdentifyColumns.Bit(valueIndex) {
// This column is represented, but its value is NULL.
Expand Down
4 changes: 2 additions & 2 deletions go/vt/binlog/binlog_streamer_rbr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestStreamerParseRBREvents(t *testing.T) {
// We only use the Columns.
se := schema.NewEngineForTests()
se.SetTableForTests(&schema.Table{
Name: sqlparser.NewTableIdent("vt_a"),
Name: sqlparser.NewIdentifierCS("vt_a"),
Fields: []*querypb.Field{{
Name: "id",
Type: querypb.Type_INT64,
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestStreamerParseRBRNameEscapes(t *testing.T) {
// Create a schema.Engine for this test using keyword names.
se := schema.NewEngineForTests()
se.SetTableForTests(&schema.Table{
Name: sqlparser.NewTableIdent("insert"),
Name: sqlparser.NewIdentifierCS("insert"),
Fields: []*querypb.Field{{
Name: "update",
Type: querypb.Type_INT64,
Expand Down
6 changes: 3 additions & 3 deletions go/vt/schemadiff/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func colWithMaskedName(col *sqlparser.ColumnDefinition) string {
col = sqlparser.CloneRefOfColumnDefinition(col)
col.Name = sqlparser.NewColIdent("mask")
col.Name = sqlparser.NewIdentifierCI("mask")
return sqlparser.CanonicalString(col)

}
Expand Down Expand Up @@ -57,8 +57,8 @@ func (c *columnDetails) nextColName() string {
return c.nextCol.col.Name.String()
}

func getColName(colIdent *sqlparser.ColIdent) *sqlparser.ColName {
return &sqlparser.ColName{Name: *colIdent}
func getColName(id *sqlparser.IdentifierCI) *sqlparser.ColName {
return &sqlparser.ColName{Name: *id}
}

type ModifyColumnDiff struct {
Expand Down
10 changes: 5 additions & 5 deletions go/vt/schemadiff/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (c *CreateTableEntity) normalizeKeys() {
suggestedKeyName = fmt.Sprintf("%s_%d", colName, enumerate)
}
// OK we found a free slot!
key.Info.Name = sqlparser.NewColIdent(suggestedKeyName)
key.Info.Name = sqlparser.NewIdentifierCI(suggestedKeyName)
keyNameExists[strings.ToLower(suggestedKeyName)] = true
}

Expand Down Expand Up @@ -565,7 +565,7 @@ func (c *CreateTableEntity) normalizeUnnamedConstraints() {
suggestedCheckName = fmt.Sprintf(nameFormat, c.CreateTable.Table.Name.String(), enumerate)
}
// OK we found a free slot!
constraint.Name = sqlparser.NewColIdent(suggestedCheckName)
constraint.Name = sqlparser.NewIdentifierCI(suggestedCheckName)
constraintNameExists[strings.ToLower(suggestedCheckName)] = true
}
}
Expand Down Expand Up @@ -948,7 +948,7 @@ func (c *CreateTableEntity) isRangePartitionsRotation(
for _, p := range droppedPartitions1 {
partitionSpec := &sqlparser.PartitionSpec{
Action: sqlparser.DropAction,
Names: []sqlparser.ColIdent{p.Name},
Names: []sqlparser.IdentifierCI{p.Name},
}
partitionSpecs = append(partitionSpecs, partitionSpec)
}
Expand Down Expand Up @@ -1113,7 +1113,7 @@ func (c *CreateTableEntity) diffKeys(alterTable *sqlparser.AlterTable,
t2KeysMap[key.Info.Name.String()] = key
}

dropKeyStatement := func(name sqlparser.ColIdent) *sqlparser.DropKey {
dropKeyStatement := func(name sqlparser.IdentifierCI) *sqlparser.DropKey {
dropKey := &sqlparser.DropKey{}
if strings.EqualFold(dropKey.Name.String(), "PRIMARY") {
dropKey.Type = sqlparser.PrimaryKeyType
Expand Down Expand Up @@ -2086,6 +2086,6 @@ func (c *CreateTableEntity) identicalOtherThanName(other *CreateTableEntity) boo
// tableWithMaskedName returns the CREATE TABLE statement but with table's name replaced with a constant arbitrary name
func tableWithMaskedName(createTable *sqlparser.CreateTable) string {
createTable = sqlparser.CloneRefOfCreateTable(createTable)
createTable.Table.Name = sqlparser.NewTableIdent("mask")
createTable.Table.Name = sqlparser.NewIdentifierCS("mask")
return sqlparser.CanonicalString(createTable)
}
4 changes: 2 additions & 2 deletions go/vt/sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,12 @@ func TableFromStatement(sql string) (TableName, error) {

// GetTableName returns the table name from the SimpleTableExpr
// only if it's a simple expression. Otherwise, it returns "".
func GetTableName(node SimpleTableExpr) TableIdent {
func GetTableName(node SimpleTableExpr) IdentifierCS {
if n, ok := node.(TableName); ok && n.Qualifier.IsEmpty() {
return n.Name
}
// sub-select or '.' expression
return NewTableIdent("")
return NewIdentifierCS("")
}

// IsColName returns true if the Expr is a *ColName.
Expand Down
16 changes: 8 additions & 8 deletions go/vt/sqlparser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,30 @@ func TestAndExpressions(t *testing.T) {
greaterThanExpr := &ComparisonExpr{
Operator: GreaterThanOp,
Left: &ColName{
Name: NewColIdent("val"),
Name: NewIdentifierCI("val"),
Qualifier: TableName{
Name: NewTableIdent("a"),
Name: NewIdentifierCS("a"),
},
},
Right: &ColName{
Name: NewColIdent("val"),
Name: NewIdentifierCI("val"),
Qualifier: TableName{
Name: NewTableIdent("b"),
Name: NewIdentifierCS("b"),
},
},
}
equalExpr := &ComparisonExpr{
Operator: EqualOp,
Left: &ColName{
Name: NewColIdent("id"),
Name: NewIdentifierCI("id"),
Qualifier: TableName{
Name: NewTableIdent("a"),
Name: NewIdentifierCS("a"),
},
},
Right: &ColName{
Name: NewColIdent("id"),
Name: NewIdentifierCI("id"),
Qualifier: TableName{
Name: NewTableIdent("b"),
Name: NewIdentifierCS("b"),
},
},
}
Expand Down
Loading