Skip to content
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
11 changes: 11 additions & 0 deletions regression-test/data/ddl_p0/test_alter_view.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
1 1
1 5
2 1
2 10

-- !select --
1 60
2 70

Binary file not shown.
69 changes: 69 additions & 0 deletions regression-test/suites/alter_p2/test_alter_table_property.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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_alter_table_property") {
String tableName = "test_alter_table_property_table"
sql "DROP TABLE IF EXISTS ${tableName}"
sql """
CREATE TABLE IF NOT EXISTS ${tableName}
(
id LARGEINT NOT NULL,
value LARGEINT SUM DEFAULT "0"
)
AGGREGATE KEY(`id`)
PARTITION BY RANGE(`id`)
(
PARTITION p1 VALUES LESS THAN ("100")
)
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES
(
"replication_allocation" = "tag.location.default: 1"
)
"""
sql "INSERT INTO ${tableName} VALUES (50, 100)"

def queryReplicaCount = { partitionName ->
def result = sql "ADMIN SHOW REPLICA DISTRIBUTION FROM ${tableName} PARTITION ${partitionName}"
int sum = 0
for (row in result) {
sum += row[1].toInteger()
}
sum
}

assertEquals(1, queryReplicaCount("p1"))

sql """ ALTER TABLE ${tableName} ADD PARTITION p2 VALUES LESS THAN ("200") """
assertEquals(1, queryReplicaCount("p2"))

sql """ ALTER TABLE ${tableName} SET ( "default.replication_allocation" = "tag.location.default: 2" ) """
sql """ ALTER TABLE ${tableName} ADD PARTITION p3 VALUES LESS THAN ("300") """
assertEquals(2, queryReplicaCount("p3"))

sql """ ALTER TABLE ${tableName} MODIFY PARTITION p1 SET ( "replication_allocation" = "tag.location.default: 2" ) """
for (i = 0; i < 300; i++) {
if (queryReplicaCount("p1") != 2) {
Thread.sleep(3000)
}
}
assertEquals(2, queryReplicaCount("p1"))
assertEquals(1, queryReplicaCount("p2"))

sql "DROP TABLE ${tableName}"
}

63 changes: 63 additions & 0 deletions regression-test/suites/ddl_p0/test_alter_view.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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_alter_view") {
String tableName = "test_alter_view_table";
String viewName = "test_alter_view_view";
sql " DROP TABLE IF EXISTS ${tableName}"
sql """
CREATE TABLE IF NOT EXISTS ${tableName}
(
c1 BIGINT NOT NULL,
c2 BIGINT NOT NULL,
c3 BIGINT NOT NULL
)
UNIQUE KEY (`c1`, `c2`)
DISTRIBUTED BY HASH(`c1`) BUCKETS 1
PROPERTIES
(
"replication_num" = "1"
)
"""
sql """
CREATE VIEW IF NOT EXISTS ${viewName} (k1, k2)
AS
SELECT c1 as k1, c2 as k2 FROM ${tableName}
"""

sql """
INSERT INTO ${tableName} VALUES
(1, 1, 10),
(1, 5, 50),
(2, 1, 20),
(2, 10, 50)
"""

qt_select " SELECT * FROM ${viewName} "

sql """
ALTER VIEW ${viewName} (k1, k2)
AS
SELECT c1 as k1, sum(c3) as k2 FROM ${tableName} GROUP BY c1
"""

qt_select " SELECT * FROM ${viewName} "

sql "DROP VIEW ${viewName}"
sql "DROP TABLE ${tableName}"
}

88 changes: 88 additions & 0 deletions regression-test/suites/schema_change_p0/test_rename_rollup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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_rename_rollup") {
def tableName = "rename_rollup_test"
def getRollupJobState = { tbName ->
def jobStateResult = sql """ SHOW ALTER TABLE ROLLUP WHERE TableName='${tbName}' ORDER BY CreateTime DESC LIMIT 1 """
return jobStateResult[0][8]
}
sql """ DROP TABLE IF EXISTS ${tableName} """
sql """
CREATE TABLE IF NOT EXISTS ${tableName} (
`user_id` LARGEINT NOT NULL COMMENT "用户id",
`date` DATE NOT NULL COMMENT "数据灌入日期时间",
`city` VARCHAR(20) COMMENT "用户所在城市",
`age` SMALLINT COMMENT "用户年龄",
`sex` TINYINT COMMENT "用户性别",
`cost` BIGINT SUM DEFAULT "0" COMMENT "用户总消费",
`max_dwell_time` INT MAX DEFAULT "0" COMMENT "用户最大停留时间",
`min_dwell_time` INT MIN DEFAULT "99999" COMMENT "用户最小停留时间",
`hll_col` HLL HLL_UNION NOT NULL COMMENT "HLL列",
`bitmap_col` Bitmap BITMAP_UNION NOT NULL COMMENT "bitmap列")
AGGREGATE KEY(`user_id`, `date`, `city`, `age`, `sex`) DISTRIBUTED BY HASH(`user_id`)
BUCKETS 8
PROPERTIES ( "replication_num" = "1", "light_schema_change" = "true" );
"""
qt_desc """ desc ${tableName} """

def resRoll = "null"
def rollupName = "rollup_cost"
sql "ALTER TABLE ${tableName} ADD ROLLUP ${rollupName}(`user_id`, `cost`);"
int max_try_time = 3000
while (max_try_time--){
String result = getRollupJobState(tableName)
if (result == "FINISHED") {
sleep(3000)
break
} else {
sleep(100)
if (max_try_time < 1){
assertEquals(1,2)
}
}
}

sql """ INSERT INTO ${tableName} VALUES
(1, '2017-10-01', 'Beijing', 10, 1, 1, 30, 20, hll_hash(1), to_bitmap(1))
"""
sql """ INSERT INTO ${tableName} VALUES
(1, '2017-10-02', 'Beijing', 10, 1, 1, 31, 19, hll_hash(2), to_bitmap(2))
"""
sql """ sync """

qt_select """ select * from ${tableName} order by user_id """

qt_select """ select user_id, sum(cost) from ${tableName} group by user_id order by user_id """

sql """ ALTER TABLE ${tableName} RENAME ROLLUP ${rollupName} new_${rollupName}"""

sql """ INSERT INTO ${tableName} VALUES
(2, '2017-10-01', 'Beijing', 10, 1, 1, 31, 21, hll_hash(2), to_bitmap(2))
"""
sql """ INSERT INTO ${tableName} VALUES
(2, '2017-10-02', 'Beijing', 10, 1, 1, 32, 20, hll_hash(3), to_bitmap(3))
"""
qt_desc """ desc ${tableName} ALL"""

qt_select""" select * from ${tableName} order by user_id """

qt_select """ select user_id, sum(cost) from ${tableName} group by user_id order by user_id """

sql """ DROP TABLE ${tableName} """
}