Skip to content

Commit

Permalink
fix text/enum override
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Jun 15, 2021
1 parent 6ae9c51 commit dfd826e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
21 changes: 11 additions & 10 deletions go/vt/vttablet/onlineddl/vrepl.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,37 +221,38 @@ func (v *VRepl) applyColumnTypes(ctx context.Context, conn *dbconnpool.DBConnect
continue
}

column.Type = vrepl.UnknownColumnType
if strings.Contains(columnType, "unsigned") {
column.IsUnsigned = true
}
if strings.Contains(columnType, "mediumint") {
column.Type = vrepl.MediumIntColumnType
column.SetTypeIfUnknown(vrepl.MediumIntColumnType)
}
if strings.Contains(columnType, "timestamp") {
column.Type = vrepl.TimestampColumnType
column.SetTypeIfUnknown(vrepl.TimestampColumnType)
}
if strings.Contains(columnType, "datetime") {
column.Type = vrepl.DateTimeColumnType
column.SetTypeIfUnknown(vrepl.DateTimeColumnType)
}
if strings.Contains(columnType, "json") {
column.Type = vrepl.JSONColumnType
column.SetTypeIfUnknown(vrepl.JSONColumnType)
}
if strings.Contains(columnType, "float") {
column.Type = vrepl.FloatColumnType
column.SetTypeIfUnknown(vrepl.FloatColumnType)
}
if strings.HasPrefix(columnType, "enum") {
column.Type = vrepl.EnumColumnType
column.SetTypeIfUnknown(vrepl.EnumColumnType)
column.EnumValues = schema.ParseEnumValues(columnType)
}
if strings.HasPrefix(columnType, "binary") {
column.Type = vrepl.BinaryColumnType
column.SetTypeIfUnknown(vrepl.BinaryColumnType)
column.BinaryOctetLength = columnOctetLength
}
if charset := row.AsString("CHARACTER_SET_NAME", ""); charset != "" {
column.Charset = charset
}
if collation := row.AsString("COLLATION_NAME", ""); collation != "" {
column.Type = vrepl.StringColumnType
column.SetTypeIfUnknown(vrepl.StringColumnType)
column.Collation = collation
}
}
Expand Down Expand Up @@ -425,6 +426,8 @@ func (v *VRepl) generateFilterQuery(ctx context.Context) error {
sb.WriteString(", ")
}
switch {
case sourceCol.EnumToTextConversion:
sb.WriteString(fmt.Sprintf("CONCAT(%s)", escapeName(name)))
case sourceCol.Type == vrepl.JSONColumnType:
sb.WriteString(fmt.Sprintf("convert(%s using utf8mb4)", escapeName(name)))
case sourceCol.Type == vrepl.StringColumnType:
Expand Down Expand Up @@ -453,8 +456,6 @@ func (v *VRepl) generateFilterQuery(ctx context.Context) error {
}
// We will always read strings as utf8mb4.
sb.WriteString(fmt.Sprintf("convert(%s using utf8mb4)", escapeName(name)))
case sourceCol.EnumToTextConversion:
sb.WriteString(fmt.Sprintf("CONCAT(%s)", escapeName(name)))
default:
sb.WriteString(escapeName(name))
}
Expand Down
7 changes: 7 additions & 0 deletions go/vt/vttablet/onlineddl/vrepl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ type Column struct {
BinaryOctetLength uint64
}

// SetTypeIfUnknown will set a new column type only if the current type is unknown, otherwise silently skip
func (c *Column) SetTypeIfUnknown(t ColumnType) {
if c.Type == UnknownColumnType {
c.Type = t
}
}

// NewColumns creates a new column array from non empty names
func NewColumns(names []string) []Column {
result := []Column{}
Expand Down

0 comments on commit dfd826e

Please sign in to comment.