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

Add test for rollup and column #388

Merged
merged 1 commit into from
Jan 13, 2025
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
5 changes: 4 additions & 1 deletion regression-test/common/helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,16 @@ class Helper {
if (source == "sql") {
res = suite.sql_return_maparray "DESC ${table} ALL"
} else {
if (alias != null) {
table = alias
}
res = suite.target_sql_return_maparray "DESC ${table} ALL"
}

def map = Maps.newHashMap()
def index = ""
for (def row : res) {
if (row.IndexName != "") {
if (row.IndexName != "" && row.IndexName != table) {
index = row.IndexName
}
if (row.Field == "") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite('test_ds_rollup_add_drop') {
def helper = new GroovyShell(new Binding(['suite': delegate]))
.evaluate(new File("${context.config.suitePath}/../common", 'helper.groovy'))

if (helper.has_feature('feature_skip_rollup_binlogs')) {
logger.info('skip this suite because feature_skip_rollup_binlogs is enabled')
return
}

def tableName = 'tbl_' + helper.randomSuffix()
def test_num = 0
def insert_num = 5

sql """
CREATE TABLE if NOT EXISTS ${tableName}
(
`id` INT,
`col1` INT,
`col2` INT,
`col3` INT,
`col4` INT,
)
ENGINE=OLAP
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"binlog.enable" = "true"
)
"""
sql """
ALTER TABLE ${tableName}
ADD ROLLUP rollup_${tableName}_full (id, col2, col4)
"""

def rollupFullFinished = { res -> Boolean
for (List<Object> row : res) {
if ((row[5] as String).contains("rollup_${tableName}_full")) {
return true
}
}
return false
}
assertTrue(helper.checkShowTimesOf("""
SHOW ALTER TABLE ROLLUP
FROM ${context.dbName}
WHERE TableName = "${tableName}" AND State = "FINISHED"
""",
rollupFullFinished, 30))
sql """ALTER TABLE ${tableName} set ("binlog.enable" = "true")"""

logger.info('=== Test 1: full update rollup ===')
helper.ccrJobDelete()
helper.ccrJobCreate()

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

def hasRollupFull = { res -> Boolean
for (List<Object> row : res) {
if ((row[0] as String) == "rollup_${tableName}_full") {
return true
}
}

return false
}
assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL",
hasRollupFull, 30, 'target'))

logger.info('=== Test 2: incremental update rollup ===')
sql """
ALTER TABLE ${tableName}
ADD ROLLUP rollup_${tableName}_incr (id, col1, col3)
"""
def hasRollupIncremental = { res -> Boolean
for (List<Object> row : res) {
if ((row[0] as String) == "rollup_${tableName}_incr") {
return true
}
}
return false
}
assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL",
hasRollupIncremental, 30, 'target'))

logger.info('=== Test 3: drop rollup')
sql """
ALTER TABLE ${tableName} DROP ROLLUP rollup_${tableName}_incr
"""

def hasRollupIncrementalDropped = { res -> Boolean
for (List<Object> row : res) {
if ((row[0] as String) == "rollup_${tableName}_incr") {
return false
}
}
return true
}
assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL",
hasRollupIncrementalDropped, 30, 'target'))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_ds_rollup_rename") {
def helper = new GroovyShell(new Binding(['suite': delegate]))
.evaluate(new File("${context.config.suitePath}/../common", "helper.groovy"))

if (helper.has_feature("feature_skip_rollup_binlogs")) {
logger.info("skip this suite because feature_skip_rollup_binlogs is enabled")
return
}

def tableName = "tbl_" + helper.randomSuffix()
def test_num = 0
def insert_num = 5

sql """
CREATE TABLE if NOT EXISTS ${tableName}
(
`id` INT,
`col1` INT,
`col2` INT,
`col3` INT,
`col4` INT,
)
ENGINE=OLAP
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"binlog.enable" = "true"
)
"""
sql """
ALTER TABLE ${tableName}
ADD ROLLUP rollup_${tableName}_full (id, col2, col4)
"""

def rollupFullFinished = { res -> Boolean
for (List<Object> row : res) {
if ((row[5] as String).contains("rollup_${tableName}_full")) {
return true
}
}
return false
}
assertTrue(helper.checkShowTimesOf("""
SHOW ALTER TABLE ROLLUP
FROM ${context.dbName}
WHERE TableName = "${tableName}" AND State = "FINISHED"
""",
rollupFullFinished, 30))
sql """ALTER TABLE ${tableName} set ("binlog.enable" = "true")"""

logger.info("=== Test 1: full update rollup ===")
helper.ccrJobDelete()
helper.ccrJobCreate()

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

def hasRollupFull = { res -> Boolean
for (List<Object> row : res) {
if ((row[0] as String) == "rollup_${tableName}_full") {
return true
}
}

return false
}
assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL",
hasRollupFull, 30, "target"))

logger.info("=== Test 2: Rename rollup ===")
sql """
ALTER TABLE ${tableName}
RENAME ROLLUP rollup_${tableName}_full rollup_${tableName}_full_new
"""
def hasRollupFullNew = { res -> Boolean
for (List<Object> row : res) {
if ((row[0] as String) == "rollup_${tableName}_full_new") {
return true
}
}

return false
}
assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL",
hasRollupFullNew, 30, "target"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
suite("test_ds_rollup_col_add") {
def helper = new GroovyShell(new Binding(['suite': delegate]))
.evaluate(new File("${context.config.suitePath}/../common", "helper.groovy"))

def tableName = "tbl_" + helper.randomSuffix()
def test_num = 0
def insert_num = 5

def exist = { res -> Boolean
return res.size() != 0
}

def has_count = { count ->
return { res -> Boolean
res.size() == count
}
}

sql """
CREATE TABLE if NOT EXISTS ${tableName}
(
`id` INT,
`col1` INT,
`col2` INT,
`col3` INT,
`col4` INT,
)
ENGINE=OLAP
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"binlog.enable" = "true"
)
"""
sql """
ALTER TABLE ${tableName}
ADD ROLLUP rollup_${tableName} (id, col2, col4)
"""

assertTrue(helper.checkShowTimesOf("""
SHOW ALTER TABLE ROLLUP
FROM ${context.dbName}
WHERE TableName = "${tableName}" AND State = "FINISHED"
""",
has_count(1), 30))

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

logger.info("=== Test 1: add key column ===")
sql """
ALTER TABLE ${tableName}
ADD COLUMN `key` INT KEY DEFAULT "0"
TO rollup_${tableName}
"""

assertTrue(helper.checkShowTimesOf("""
SHOW ALTER TABLE COLUMN
FROM ${context.dbName}
WHERE TableName = "${tableName}"
AND IndexName = "rollup_${tableName}"
AND State = "FINISHED"
""",
has_count(1), 30))

assertTrue(helper.check_table_describe_times(tableName, 30))

logger.info("=== Test 2: add value column ===")
sql """
ALTER TABLE ${tableName}
ADD COLUMN `first_value` INT DEFAULT "0"
TO rollup_${tableName}
"""

assertTrue(helper.checkShowTimesOf("""
SHOW ALTER TABLE COLUMN
FROM ${context.dbName}
WHERE TableName = "${tableName}"
AND IndexName = "rollup_${tableName}"
AND State = "FINISHED"
""",
has_count(2), 30))
assertTrue(helper.check_table_describe_times(tableName, 30))
}
Loading
Loading