|
18 | 18 | import org.apache.doris.regression.suite.Suite |
19 | 19 |
|
20 | 20 | // create table with nested data type, now default complex data include array, map, struct |
21 | | -Suite.metaClass.create_table_with_nested_type = { int maxDepth, String tbName /* param */ -> |
| 21 | +Suite.metaClass.create_table_with_nested_type = { int max_depth, def type_arr, String tb_name /* param */ -> |
22 | 22 | Suite suite = delegate as Suite |
23 | 23 |
|
24 | | - maxDepth = maxDepth > 9 ? 9 : maxDepth |
| 24 | + try { |
| 25 | + if (type_arr.size() != max_depth) { |
| 26 | + throw new Exception("level not equal type_arr size") |
| 27 | + } |
| 28 | + } catch (Exception e) { |
| 29 | + logger.info(e.message) |
| 30 | + return |
| 31 | + } |
| 32 | + |
| 33 | + def cur_depth = type_arr.size() |
| 34 | + max_depth = max_depth > 9 ? 9 : max_depth |
| 35 | + max_depth = max_depth < 1 ? 1 : max_depth |
25 | 36 |
|
26 | | - def dataTypeArr = ["boolean", "tinyint(4)", "smallint(6)", "int(11)", "bigint(20)", "largeint(40)", "float", |
| 37 | +// def datatype_arr = ["boolean", "tinyint(4)", "smallint(6)", "int(11)", "bigint(20)", "largeint(40)", "float", |
| 38 | +// "double", "decimal(20, 3)", "decimalv3(20, 3)", "date", "datetime", "datev2", "datetimev2(0)", |
| 39 | +// "char(15)", "varchar(100)", "text", "hll","bitmap", "QUANTILE_STATE"] |
| 40 | + def datatype_arr = ["boolean", "tinyint(4)", "smallint(6)", "int(11)", "bigint(20)", "largeint(40)", "float", |
27 | 41 | "double", "decimal(20, 3)", "decimalv3(20, 3)", "date", "datetime", "datev2", "datetimev2(0)", |
28 | 42 | "char(15)", "varchar(100)", "text"] |
29 | | - def colNameArr = ["c_bool", "c_tinyint", "c_smallint", "c_int", "c_bigint", "c_largeint", "c_float", |
| 43 | + def col_name_arr = ["c_bool", "c_tinyint", "c_smallint", "c_int", "c_bigint", "c_largeint", "c_float", |
30 | 44 | "c_double", "c_decimal", "c_decimalv3", "c_date", "c_datetime", "c_datev2", "c_datetimev2", |
31 | 45 | "c_char", "c_varchar", "c_string"] |
32 | | - def complexDataTypeArr = ["array", "map", "struct"] |
33 | | -// def tbName = "test" |
| 46 | + def complex_datatype_arr = ["array", "map", "struct"] |
| 47 | + def base_struct_scala = "col1:int(11),col2:tinyint(4),col3:smallint(6),col4:boolean,col5:bigint(20),col6:largeint(40)," + |
| 48 | + "col7:float,col8:double,col9:decimal(20, 3),col10:decimalv3(20, 3),col11:date,col12:datetime,col13:datev2,col14:datetimev2(0)," + |
| 49 | + "col15:char(15),col16:varchar(100),col17:text" |
| 50 | + |
34 | 51 | def colCount = 1 |
35 | | - def memo = new String[20] |
36 | | - def r = new Random() |
37 | 52 |
|
38 | 53 | def getDataType |
39 | | - getDataType = { dataType, level -> |
40 | | - if (memo[level] != null) { |
41 | | - return memo[level]; |
42 | | - } |
| 54 | + getDataType = { i, level -> |
43 | 55 |
|
44 | 56 | StringBuilder res = new StringBuilder(); |
45 | | - def data_r = r.nextInt(3); |
| 57 | + def data_r = type_arr[cur_depth - level] |
46 | 58 |
|
47 | 59 | if (level == 1) { |
48 | 60 | if (data_r == 0) { |
49 | | - res.append(complexDataTypeArr[data_r]+"<"+dataType+">"); |
| 61 | + res.append(complex_datatype_arr[data_r]+"<"+ datatype_arr[i] +">"); |
50 | 62 | } else if (data_r == 1) { |
51 | | - res.append(complexDataTypeArr[data_r]+"<"+dataType+"," +dataType+">"); |
| 63 | + if (i == 16) { |
| 64 | + res.append(complex_datatype_arr[data_r]+"<"+ datatype_arr[i] +"," + datatype_arr[0] +">"); |
| 65 | + } else if (i == 17 || i == 18 || i == 19) { |
| 66 | + res.append(complex_datatype_arr[data_r]+"<int(11)," + datatype_arr[i] +">"); |
| 67 | + } else { |
| 68 | + res.append(complex_datatype_arr[data_r]+"<"+ datatype_arr[i] +"," + datatype_arr[i+1] +">"); |
| 69 | + } |
52 | 70 | } else if (data_r == 2) { |
53 | | - res.append(complexDataTypeArr[data_r]+"<col_"+colCount+":" + dataType +">"); |
54 | | - colCount++; |
| 71 | + res.append(complex_datatype_arr[data_r]+"<"+ base_struct_scala +">"); |
55 | 72 | } |
56 | 73 | } else { |
57 | 74 | level--; |
58 | 75 | if (data_r == 0) { |
59 | | - res.append(complexDataTypeArr[data_r]+"<"+getDataType(dataType, level)+">"); |
| 76 | + res.append(complex_datatype_arr[data_r]+"<"+getDataType(i, level)+">"); |
60 | 77 | } else if (data_r == 1) { |
61 | | -// String str = getDataType(dataType, level); |
62 | | - res.append(complexDataTypeArr[data_r]+"<"+getDataType(dataType, level)+"," +getDataType(dataType, level)+">") |
| 78 | + if (i == 17 || i == 18 || i == 19) { |
| 79 | + res.append(complex_datatype_arr[data_r]+"<int(11)," + getDataType(i, level) +">"); |
| 80 | + } else { |
| 81 | + res.append(complex_datatype_arr[data_r]+"<"+datatype_arr[i]+"," +getDataType(i, level)+">") |
| 82 | + } |
| 83 | + |
63 | 84 | } else if (data_r == 2) { |
64 | | - res.append(complexDataTypeArr[data_r]+"<col_"+colCount+":" + getDataType(dataType, level) +">"); |
| 85 | + res.append(complex_datatype_arr[data_r]+"<col_"+colCount+":" + getDataType(i, level) +">"); |
65 | 86 | colCount++; |
66 | 87 | } |
67 | 88 | } |
68 | | - memo[level] = res.toString() |
69 | | - return memo[level]; |
| 89 | + return res.toString() |
70 | 90 | } |
71 | 91 |
|
72 | | - def stmt = "CREATE TABLE IF NOT EXISTS " + tbName + "(\n" + |
| 92 | + def stmt = "CREATE TABLE IF NOT EXISTS " + tb_name + "(\n" + |
73 | 93 | "`k1` bigint(11) NULL,\n" |
74 | | - String strTmp = "`" + colNameArr[0] + "` " + getDataType(dataTypeArr[0], maxDepth) + " NULL,\n"; |
75 | | - stmt += strTmp |
76 | | - for (int i = 1; i < dataTypeArr.size(); i++) { |
77 | | - String changeDataType = strTmp.replaceAll(colNameArr[0], colNameArr[i]) |
78 | | - changeDataType = changeDataType.replaceAll(dataTypeArr[0], dataTypeArr[i]) |
79 | | - stmt += changeDataType |
| 94 | + |
| 95 | + for (int i = 0; i < datatype_arr.size(); i++) { |
| 96 | + String strTmp = "`" + col_name_arr[i] + "` " + getDataType(i, max_depth) + " NULL,\n"; |
| 97 | + stmt += strTmp |
80 | 98 | } |
| 99 | + |
81 | 100 | stmt = stmt.substring(0, stmt.length()-2) |
82 | 101 | stmt += ") ENGINE=OLAP\n" + |
83 | 102 | "DUPLICATE KEY(`k1`)\n" + |
84 | 103 | "COMMENT 'OLAP'\n" + |
85 | 104 | "DISTRIBUTED BY HASH(`k1`) BUCKETS 10\n" + |
86 | 105 | "PROPERTIES(\"replication_num\" = \"1\");" |
87 | | - logger.info(stmt) |
88 | 106 | return stmt |
89 | 107 | } |
90 | 108 |
|
91 | 109 | logger.info("Added 'create_table_with_nested_type' function to Suite") |
92 | 110 |
|
| 111 | +Suite.metaClass.get_create_table_with_nested_type { int depth, String tb_name -> |
| 112 | + |
| 113 | + List<List<Integer>> res = new ArrayList<>(); |
| 114 | + List<Integer> track = new ArrayList(); |
| 115 | + |
| 116 | +// int depth = 1; |
| 117 | + |
| 118 | + List<Integer> nums = new ArrayList<>([0, 1, 2]); |
| 119 | + |
| 120 | + def backtrack |
| 121 | + backtrack = { |
| 122 | + if (track.size() == depth) { |
| 123 | + List<Integer> copied = new ArrayList<>(track); |
| 124 | + res.add(copied); |
| 125 | + return; |
| 126 | + } |
| 127 | + |
| 128 | + for (int i = 0; i < nums.size(); i++) { |
| 129 | + track.add(nums.get(i)); |
| 130 | + backtrack(); |
| 131 | + track.remove(track.size() - 1); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + backtrack(); |
| 136 | + for (int i = 0; i < res.size; i++) { |
| 137 | + def date_type_str = "" |
| 138 | + for (int j = 0; j < res[i].size; j++) { |
| 139 | + date_type_str += res[i][j] + " " |
| 140 | + } |
| 141 | + logger.info(date_type_str) |
| 142 | + def result = create_table_with_nested_type(depth, res[i], tb_name) |
| 143 | + logger.info(result) |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +logger.info("Added 'get_create_table_with_nested_type' function to Suite") |
0 commit comments