Skip to content

Commit

Permalink
Remove useless CreateTable (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
w41ter authored Jun 3, 2024
1 parent 020743d commit b2bdf07
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
11 changes: 2 additions & 9 deletions pkg/ccr/base/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,11 @@ func (s *Spec) CreateDatabase() error {
return nil
}

func (s *Spec) CreateTable(createTable *record.CreateTable) error {
sql := createTable.Sql
log.Infof("createTableSql: %s", sql)
// HACK: for drop table
return s.DbExec(sql)
}

func (s *Spec) CreateTableOrView(createTable *record.CreateTable, srcDatabase string) error {
// Creating table will only occur when sync db.
// When create view, the db name of sql is source db name, we should use dest db name to create view
createSql := createTable.Sql
viewRegex := regexp.MustCompile("(?i)^CREATE(\\s+)VIEW")
viewRegex := regexp.MustCompile(`(?i)^CREATE(\s+)VIEW`)
isCreateView := viewRegex.MatchString(createSql)
if isCreateView {
log.Debugf("create view, use dest db name to replace source db name")
Expand All @@ -428,7 +421,7 @@ func (s *Spec) CreateTableOrView(createTable *record.CreateTable, srcDatabase st
originalName := "`internal`.`" + strings.TrimSpace(srcDatabase) + "`."
replaceName := "`internal`.`" + strings.TrimSpace(s.Database) + "`."
createTable.Sql = strings.ReplaceAll(createTable.Sql, originalName, replaceName)
log.Debugf("original create view sql is %s, after repalce, now sql is %s", createSql, createTable.Sql)
log.Debugf("original create view sql is %s, after replace, now sql is %s", createSql, createTable.Sql)
}

sql := createTable.Sql
Expand Down
1 change: 0 additions & 1 deletion pkg/ccr/base/specer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Specer interface {
GetAllViewsFromTable(tableName string) ([]string, error)
ClearDB() error
CreateDatabase() error
CreateTable(createTable *record.CreateTable) error
CreateTableOrView(createTable *record.CreateTable, srcDatabase string) error
CheckDatabaseExists() (bool, error)
CheckTableExists() (bool, error)
Expand Down

0 comments on commit b2bdf07

Please sign in to comment.