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

Fix error when hyphen in table name #168

Merged
merged 3 commits into from
Sep 20, 2024
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
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"))
}
}
Loading