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
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ public class OHTableSecondaryPartAppendTest {

@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
closeDistributedExecute();
dropTables(tableNames, group2tableNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public class OHTableSecondaryPartBatchGetTest {

@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
closeDistributedExecute();
dropTables(tableNames, group2tableNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public class OHTableSecondaryPartCheckAndMutateTest {

@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
closeDistributedExecute();
dropTables(tableNames, group2tableNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ public class OHTableSecondaryPartGetTest {

@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
closeDistributedExecute();
dropTables(tableNames, group2tableNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ public class OHTableSecondaryPartIncrementTest {

@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
closeDistributedExecute();
dropTables(tableNames, group2tableNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ public class OHTableSecondaryPartPutTest {

@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
dropTables(tableNames, group2tableNames);
closeDistributedExecute();
dropTables(tableNames, group2tableNames);
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public class OHTableSecondaryPartScanTest {

@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
closeDistributedExecute();
dropTables(tableNames, group2tableNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@


public class ObHTableSecondaryPartUtil {
public static void openDistributedExecute() throws Exception {
Connection conn = ObHTableTestUtil.getSysConnection();
String stmt = "ALTER SYSTEM SET _obkv_feature_mode = 'distributed_execute=on';";
conn.createStatement().execute(stmt);
}

public static void closeDistributedExecute() throws Exception {
Connection conn = ObHTableTestUtil.getSysConnection();
String stmt = "ALTER SYSTEM SET _obkv_feature_mode = 'distributed_execute=off';";
conn.createStatement().execute(stmt);
}

public static void createTables(TableTemplateManager.TableType type, List<String> tableNames, Map<String, List<String >> group2tableNames, boolean printSql) throws Exception {
Connection conn = ObHTableTestUtil.getConnection();
// single cf table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ static public Connection getConnection() {
}
}

static public Connection getSysConnection() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection(JDBC_URL, SYS_USER_NAME, SYS_PASSWORD);

return conn;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@FunctionalInterface
public interface CheckedConsumer<T> {
void accept(T t) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.EnumMap;
import java.util.Map;
public class TableTemplateManager {
public static final long PART_NUM = 3;
public static final String TABLE_GROUP_PREFIX = "test_group_";
public static final String COLUMN_FAMILY = "cf";
public enum TableType {
Expand All @@ -41,7 +42,7 @@ public enum TableType {
static {
// 普通表非分区表模版
SQL_TEMPLATES.put(TableType.NON_PARTITIONED_REGULAR,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `Q` varbinary(256) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
Expand All @@ -50,7 +51,7 @@ public enum TableType {
") TABLEGROUP = %s");
// 时序表非分区表模版
SQL_TEMPLATES.put(TableType.NON_PARTITIONED_TIME_SERIES,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
" `S` bigint(20) NOT NULL,\n" +
Expand All @@ -59,7 +60,7 @@ public enum TableType {
") TABLEGROUP = %s");
// 普通表一级分区模板
SQL_TEMPLATES.put(TableType.SINGLE_PARTITIONED_REGULAR,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `Q` varbinary(256) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
Expand All @@ -68,7 +69,7 @@ public enum TableType {
") TABLEGROUP = %s PARTITION BY KEY(`K`) PARTITIONS %d ");
// 时序表一级分区模板
SQL_TEMPLATES.put(TableType.SINGLE_PARTITIONED_TIME_SERIES,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
" `S` bigint(20) NOT NULL,\n" +
Expand All @@ -77,7 +78,7 @@ public enum TableType {
") TABLEGROUP = %s PARTITION BY KEY(`K`) PARTITIONS %d ");
// 普通表RANGE-KEY分区(使用K)
SQL_TEMPLATES.put(TableType.SECONDARY_PARTITIONED_RANGE_KEY,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `Q` varbinary(256) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
Expand All @@ -93,7 +94,7 @@ public enum TableType {

// 合并GEN类型的注释处理
SQL_TEMPLATES.put(TableType.SECONDARY_PARTITIONED_RANGE_KEY_GEN,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `Q` varbinary(256) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
Expand All @@ -109,7 +110,7 @@ public enum TableType {

// 普通表KEY-RANGE分区(使用K)
SQL_TEMPLATES.put(TableType.SECONDARY_PARTITIONED_KEY_RANGE,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `Q` varbinary(256) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
Expand All @@ -126,7 +127,7 @@ public enum TableType {

// 普通表KEY-RANGE分区(使用生成列)
SQL_TEMPLATES.put(TableType.SECONDARY_PARTITIONED_KEY_RANGE_GEN,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `Q` varbinary(256) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
Expand All @@ -143,7 +144,7 @@ public enum TableType {

// 时序表RANGE-KEY分区
SQL_TEMPLATES.put(TableType.SECONDARY_PARTITIONED_TIME_RANGE_KEY,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
" `S` bigint(20) NOT NULL,\n" +
Expand All @@ -159,7 +160,7 @@ public enum TableType {

// 时序表KEY-RANGE分区
SQL_TEMPLATES.put(TableType.SECONDARY_PARTITIONED_TIME_KEY_RANGE,
"CREATE TABLE `%s` (\n" +
"CREATE TABLE IF NOT EXISTS `%s` (\n" +
" `K` varbinary(1024) NOT NULL,\n" +
" `T` bigint(20) NOT NULL,\n" +
" `S` bigint(20) NOT NULL,\n" +
Expand Down Expand Up @@ -188,7 +189,7 @@ public static String getCreateTableSQL(TableType type, String tableName,
break;
case SINGLE_PARTITIONED_REGULAR:
case SINGLE_PARTITIONED_TIME_SERIES: // 合并相同处理逻辑
params = new Object[]{tableName, tableGroup, 97};
params = new Object[]{tableName, tableGroup, PART_NUM};
break;
case SECONDARY_PARTITIONED_RANGE_KEY:
case SECONDARY_PARTITIONED_RANGE_KEY_GEN:
Expand All @@ -200,7 +201,7 @@ public static String getCreateTableSQL(TableType type, String tableName,
getGeneratedColumn(type),
tableGroup,
isGen ? "K_PREFIX" : "K",
97,
PART_NUM,
timeRange.lowerBound1(),
timeRange.lowerBound1() + 86400000,
timeRange.lowerBound1() + 172800000
Expand All @@ -213,7 +214,7 @@ public static String getCreateTableSQL(TableType type, String tableName,
"",
tableGroup,
"K",
97,
PART_NUM,
timeRange.lowerBound1(),
timeRange.lowerBound1() + 86400000,
timeRange.lowerBound1() + 172800000
Expand Down Expand Up @@ -241,13 +242,13 @@ private static String getGeneratedColumn(TableType type) {
private static String getPartitionStrategy(TableType type) {
if (type.name().contains("RANGE_KEY")) {
return type.name().contains("GEN")
? "RANGE COLUMNS(`G`) SUBPARTITION BY KEY(`K_PREFIX`) SUBPARTITIONS 97"
: "RANGE COLUMNS(`G`) SUBPARTITION BY KEY(`K`) SUBPARTITIONS 97";
? "RANGE COLUMNS(`G`) SUBPARTITION BY KEY(`K_PREFIX`) SUBPARTITIONS " + PART_NUM
: "RANGE COLUMNS(`G`) SUBPARTITION BY KEY(`K`) SUBPARTITIONS "+ PART_NUM;
}
if (type.name().contains("KEY_RANGE")) {
return type.name().contains("GEN")
? "KEY(`K_PREFIX`) PARTITIONS 97 SUBPARTITION BY RANGE COLUMNS(`G`)"
: "KEY(`K`) PARTITIONS 97 SUBPARTITION BY RANGE COLUMNS(`G`)";
? "KEY(`K_PREFIX`) PARTITIONS "+ PART_NUM +" SUBPARTITION BY RANGE COLUMNS(`G`)"
: "KEY(`K`) PARTITIONS "+ PART_NUM +" SUBPARTITION BY RANGE COLUMNS(`G`)";
}
return "";
}
Expand Down