Skip to content

Commit

Permalink
More MySQL Improvements (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Dec 19, 2024
1 parent 50930d8 commit 2783cac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/antlr/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func visit(tree antlr.Tree) ([]Event, error) {
case *generated.RenameTableContext:
return processRenameTable(ctx)
case
*generated.CreateEventContext,
*generated.DropEventContext,
*generated.EmptyStatement_Context,
*generated.TruncateTableContext,
*generated.AdministrationStatementContext,
Expand Down
8 changes: 5 additions & 3 deletions lib/mysql/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ func ParseColumnDataType(originalS string, optionalSQLMode []string) (DataType,
s = s[:collateIdx]
}

if charSetIdx := strings.Index(s, " character set"); charSetIdx != -1 {
// Strip character set
s = s[:charSetIdx]
for _, charSetPermutation := range []string{" character set", " charset"} {
if charSetIdx := strings.Index(s, charSetPermutation); charSetIdx != -1 {
// Strip character set
s = s[:charSetIdx]
}
}

parenIndex := strings.Index(s, "(")
Expand Down
7 changes: 7 additions & 0 deletions lib/mysql/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ func TestParseColumnDataType(t *testing.T) {
assert.Equal(t, Varchar, dataType)
assert.Equal(t, &Opts{Size: typing.ToPtr(255)}, opts)
}
{
// Using charset instead
dataType, opts, err := ParseColumnDataType(`varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci`, nil)
assert.NoError(t, err)
assert.Equal(t, Varchar, dataType)
assert.Equal(t, &Opts{Size: typing.ToPtr(255)}, opts)
}
}
{
// Decimal
Expand Down
6 changes: 5 additions & 1 deletion sources/mysql/streaming/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func (s *SchemaAdapter) ApplyDDL(unixTs int64, query string) error {
}

func (s *SchemaAdapter) applyDDL(unixTs int64, result antlr.Event) error {
if _, ok := result.(antlr.CreateTableEvent); ok {
switch result.(type) {
case antlr.DropTableEvent:
delete(s.adapters, result.GetTable())
return nil
case antlr.CreateTableEvent:
var cols []Column
for _, col := range result.GetColumns() {
cols = append(cols, Column{
Expand Down

0 comments on commit 2783cac

Please sign in to comment.