|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +suite("test_hive_migrate_iceberg", "p2,external,iceberg,external_remote,external_remote_iceberg") { |
| 19 | + |
| 20 | + String enabled = context.config.otherConfigs.get("enableExternalIcebergTest") |
| 21 | + if (enabled == null || !enabled.equalsIgnoreCase("true")) { |
| 22 | + logger.info("disable iceberg test enableExternalIcebergTest = false") |
| 23 | + return |
| 24 | + } |
| 25 | + |
| 26 | + enabled = context.config.otherConfigs.get("enableExternalEmrTest") |
| 27 | + if (enabled == null || !enabled.equalsIgnoreCase("true")) { |
| 28 | + logger.info("disable iceberg test enableExternalEmrTest = false") |
| 29 | + return |
| 30 | + } |
| 31 | + String props = context.config.otherConfigs.get("emrCatalogCommonProp") |
| 32 | + String catalog_name = "test_hive_migrate_iceberg" |
| 33 | + sql """drop catalog if exists ${catalog_name}""" |
| 34 | + sql """create catalog if not exists ${catalog_name} properties ( |
| 35 | + "type" = "iceberg", |
| 36 | + "iceberg.catalog.type" = "hms", |
| 37 | + ${props} |
| 38 | + );""" |
| 39 | + logger.info("catalog " + catalog_name + " created") |
| 40 | + sql """switch ${catalog_name};""" |
| 41 | + logger.info("switched to catalog " + catalog_name) |
| 42 | + sql """ use regression;""" |
| 43 | + |
| 44 | + for (String table : ["hive_migrate_orc", "hive_migrate_parquet"]) { |
| 45 | + // Basic query |
| 46 | + qt_all """ select * FROM ${table} ORDER BY id""" |
| 47 | + |
| 48 | + // Test array column (arr_col) |
| 49 | + qt_arr_col_size """select id, ARRAY_SIZE(arr_col) AS arr_size FROM ${table} ORDER BY id""" |
| 50 | + qt_arr_col_contains_1 """select * FROM ${table} WHERE ARRAY_CONTAINS(arr_col, 1) ORDER BY id""" |
| 51 | + qt_arr_col_size_3 """select * FROM ${table} WHERE ARRAY_SIZE(arr_col) = 3 ORDER BY id""" |
| 52 | + |
| 53 | + // Test map column (map_col) |
| 54 | + qt_map_col_a """select * FROM ${table} WHERE map_col['a'] = 10 ORDER BY id""" |
| 55 | + qt_map_col_keys """select id, MAP_KEYS(map_col) AS map_keys FROM ${table} ORDER BY id""" |
| 56 | + qt_map_col_contains_x """select * FROM ${table} WHERE ARRAY_CONTAINS(MAP_KEYS(map_col), 'x') ORDER BY id""" |
| 57 | + |
| 58 | + // Test struct column (new_struct_col) |
| 59 | + qt_struct_name_alice """select * FROM ${table} WHERE STRUCT_ELEMENT(new_struct_col, 'new_name') = 'Alice' ORDER BY id""" |
| 60 | + qt_struct_age_over_28 """select * FROM ${table} WHERE STRUCT_ELEMENT(new_struct_col, 'age') > 28 ORDER BY id""" |
| 61 | + qt_struct_name_like_c """select * FROM ${table} WHERE STRUCT_ELEMENT(new_struct_col, 'new_name') LIKE 'C%' ORDER BY id""" |
| 62 | + |
| 63 | + // Test array of struct column (arr_struct_col) |
| 64 | + qt_arr_struct_city_beijing """select * FROM ${table} WHERE STRUCT_ELEMENT(arr_struct_col[1], 'city') = 'Beijing' ORDER BY id""" |
| 65 | + qt_arr_struct_size_2 """select * FROM ${table} WHERE ARRAY_SIZE(arr_struct_col) = 2 ORDER BY id""" |
| 66 | + |
| 67 | + // Test map of array column (map_array_col) |
| 68 | + qt_map_array_k1 """select * FROM ${table} WHERE ARRAY_CONTAINS(MAP_KEYS(map_array_col), 'k1') ORDER BY id""" |
| 69 | + qt_map_array_contains_1 """select * FROM ${table} WHERE ARRAY_CONTAINS(MAP_VALUES(map_array_col)[1], 1) ORDER BY id""" |
| 70 | + |
| 71 | + // Complex nested query |
| 72 | + qt_complex_1 """select id, new_name, STRUCT_ELEMENT(new_struct_col, 'age') AS age, ARRAY_SIZE(arr_col) AS arr_size FROM ${table} WHERE STRUCT_ELEMENT(new_struct_col, 'age') > 28 ORDER BY id""" |
| 73 | + |
| 74 | + } |
| 75 | + sql """drop catalog if exists ${catalog_name}""" |
| 76 | + |
| 77 | +} |
| 78 | +/* |
| 79 | +
|
| 80 | +use regression; |
| 81 | +CREATE TABLE hive_migrate_parquet ( |
| 82 | + id INT, |
| 83 | + name string, |
| 84 | + arr_col ARRAY<INT>, |
| 85 | + map_col MAP<STRING, INT>, |
| 86 | + struct_col STRUCT<name:STRING, age:INT>, |
| 87 | + arr_struct_col ARRAY<STRUCT<city:STRING, zip:INT>>, |
| 88 | + map_array_col MAP<STRING, ARRAY<INT>> |
| 89 | +) STORED AS PARQUET; |
| 90 | +
|
| 91 | +INSERT INTO TABLE hive_migrate_parquet VALUES ( |
| 92 | + 1, |
| 93 | + 'a', |
| 94 | + array(1,2,3), |
| 95 | + map('a',10,'b',20), |
| 96 | + named_struct('name','Alice','age',25), |
| 97 | + array(named_struct('city','Beijing','zip',100000), |
| 98 | + named_struct('city','Shanghai','zip',200000)), |
| 99 | + map('x', array(1,2), 'y', array(3,4)) |
| 100 | +),( |
| 101 | + 2, |
| 102 | + 'b', |
| 103 | + array(4,5), |
| 104 | + map('c',30,'d',40), |
| 105 | + named_struct('name','Bob','age',30), |
| 106 | + array(named_struct('city','Shenzhen','zip',518000)), |
| 107 | + map('k1', array(5,6)) |
| 108 | +); |
| 109 | +
|
| 110 | +CALL iceberg_emr.system.migrate( |
| 111 | + schema_name => 'regression', |
| 112 | + table_name => 'hive_migrate_parquet'); |
| 113 | +
|
| 114 | +
|
| 115 | +INSERT INTO iceberg_emr.regression.hive_migrate_parquet VALUES |
| 116 | +( |
| 117 | + 3, |
| 118 | + 'c', |
| 119 | + ARRAY[6,7,8,9], |
| 120 | + MAP(ARRAY['e'], ARRAY[50]), |
| 121 | + ROW('Cindy', 28), |
| 122 | + ARRAY[ |
| 123 | + ROW('Guangzhou', 510000) |
| 124 | + ], |
| 125 | + MAP( |
| 126 | + ARRAY['k2'], |
| 127 | + ARRAY[ARRAY[7,8,9]] |
| 128 | + ) |
| 129 | +); |
| 130 | +
|
| 131 | +alter table iceberg_emr.regression.hive_migrate_parquet rename column name to new_name; |
| 132 | +alter table iceberg_emr.regression.hive_migrate_parquet rename column struct_col.name to new_name; |
| 133 | +alter table iceberg_emr.regression.hive_migrate_parquet rename column struct_col to new_struct_col; |
| 134 | +
|
| 135 | +INSERT INTO iceberg_emr.regression.hive_migrate_parquet VALUES ( |
| 136 | + 4, |
| 137 | + 'd', |
| 138 | + ARRAY[10], |
| 139 | + MAP(ARRAY['x','z'], ARRAY[7,10]), |
| 140 | + ROW('David', 35), |
| 141 | + ARRAY[ROW('Chengdu', 610000),ROW('Chengdu2', 610002)], |
| 142 | + MAP(ARRAY['kkk','dddd'], ARRAY[ARRAY[71,81,91],ARRAY[70,80,90]]) |
| 143 | +); |
| 144 | +*/ |
| 145 | + |
| 146 | + |
0 commit comments