Skip to content

Commit

Permalink
Fix error when hyphen in table name (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsy3993 authored Sep 20, 2024
1 parent a9d2603 commit ba270e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/ccr/base/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ func (s *Spec) CreateSnapshotAndWaitForDone(tables []string) (string, error) {
return "", err
}

backupSnapshotSql := fmt.Sprintf("BACKUP SNAPSHOT %s.%s TO `__keep_on_local__` ON ( %s ) PROPERTIES (\"type\" = \"full\")", utils.FormatKeywordName(s.Database), snapshotName, tableRefs)
backupSnapshotSql := fmt.Sprintf("BACKUP SNAPSHOT %s.%s TO `__keep_on_local__` ON ( %s ) PROPERTIES (\"type\" = \"full\")", utils.FormatKeywordName(s.Database), utils.FormatKeywordName(snapshotName), tableRefs)
log.Debugf("backup snapshot sql: %s", backupSnapshotSql)
_, err = db.Exec(backupSnapshotSql)
if err != nil {
Expand Down
40 changes: 39 additions & 1 deletion regression-test/suites/table-sync/test_keyword_name.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ suite("test_keyword_name") {
.evaluate(new File("${context.config.suitePath}/../common", "helper.groovy"))

def tableName = "roles"
def newTableName = "test-hyphen"
def syncerAddress = "127.0.0.1:9190"
def test_num = 0
def insert_num = 5
def opPartitonName = "less0"
Expand Down Expand Up @@ -51,6 +53,21 @@ suite("test_keyword_name") {
"binlog.enable" = "true"
);
"""

sql "DROP TABLE IF EXISTS `${newTableName}` FORCE"
target_sql "DROP TABLE IF EXISTS `${newTableName}` FORCE"
sql """
CREATE TABLE `${newTableName}` (
id INT,
name VARCHAR(10)
)
UNIQUE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"binlog.enable" = "true"
);
"""
// sql """ALTER TABLE ${tableName} set ("binlog.enable" = "true")"""

sql """
Expand All @@ -65,20 +82,41 @@ suite("test_keyword_name") {
(7, 'warlock', 'horde', '2018-12-04 16:11:28'),
(8, 'hunter', 'horde', NULL);
"""
sql """
INSERT INTO `${newTableName}` VALUES
(1, 'a'),
(2, 'b'),
(3, 'c');
"""

// delete the exists ccr job first.
helper.ccrJobDelete(tableName)
helper.ccrJobCreate(tableName)

assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30))

httpTest {
uri "/create_ccr"
endpoint syncerAddress
def bodyJson = get_ccr_body "${newTableName}"
body "${bodyJson}"
op "post"
result response
}
assertTrue(checkRestoreFinishTimesOf("${newTableName}", 30))

logger.info("=== Test 1: Check keyword name table ===")
// def checkShowTimesOf = { sqlString, myClosure, times, func = "sql" -> Boolean
assertTrue(helper.checkShowTimesOf("""
SHOW CREATE TABLE `TEST_${context.dbName}`.`${tableName}`
""",
exist, 30, "target"))

assertTrue(checkShowTimesOf("""
SHOW CREATE TABLE `TEST_${context.dbName}`.`${newTableName}`
""",
exist, 30, "target"))

logger.info("=== Test 2: Add new partition ===")
sql """
ALTER TABLE `${tableName}` ADD PARTITION p2
Expand Down Expand Up @@ -111,4 +149,4 @@ suite("test_keyword_name") {
SELECT * FROM `TEST_${context.dbName}`.`${tableName}`
""",
notExist, 30, "target"))
}
}

0 comments on commit ba270e0

Please sign in to comment.