1414// KIND, either express or implied. See the License for the
1515// specific language governing permissions and limitations
1616// under the License.
17+
18+ import java.util.concurrent.ThreadLocalRandom
19+
1720import static groovy.test.GroovyAssert.shouldFail;
1821suite(" iceberg_on_hms_and_filesystem_and_dlf" , " p2,external,new_catalog_property" ) {
1922
@@ -33,7 +36,8 @@ suite("iceberg_on_hms_and_filesystem_and_dlf", "p2,external,new_catalog_property
3336 switch ${ catalog_name} ;
3437 """
3538
36- def db_name = prefix + " _db"
39+ def db_name = prefix + " _db" + ThreadLocalRandom . current(). nextInt(100 );
40+ // Check if database exists
3741 sql """
3842 DROP DATABASE IF EXISTS ${ db_name} FORCE;
3943 """
@@ -65,6 +69,103 @@ suite("iceberg_on_hms_and_filesystem_and_dlf", "p2,external,new_catalog_property
6569 SELECT * FROM ${ table_name} ;
6670 """
6771 assert queryResult. size() == 1
72+ def branch_name = prefix + " _branch"
73+ def tag_name = prefix + " _tag"
74+ sql """
75+ ALTER TABLE ${ table_name} CREATE BRANCH ${ branch_name} ;
76+ """
77+ sql """
78+ ALTER TABLE ${ table_name} CREATE TAG ${ tag_name} ;
79+ """
80+ sql """
81+ INSERT OVERWRITE TABLE ${ table_name} VALUES (1, 'a', 10),(2, 'b', 20), (3, 'c', 30)
82+ """
83+ def originalQueryResult = sql """
84+ SELECT * FROM ${ table_name} ;
85+ """
86+ assert originalQueryResult. size() == 3
87+ sql """
88+ insert into ${ table_name} @branch(${ branch_name} ) values (4, 'd', 40)
89+ """
90+ def branchQueryResult = sql """
91+ SELECT * FROM ${ table_name} @branch(${ branch_name} );
92+ """
93+ assert branchQueryResult. size() == 2
94+
95+
96+ def tagQueryResult = sql """
97+ SELECT * FROM ${ table_name} @tag(${ tag_name} );
98+ """
99+ assert tagQueryResult. size() == 1
100+ sql """
101+ ALTER TABLE ${ table_name} drop branch ${ branch_name} ;
102+ """
103+ sql """
104+ ALTER TABLE ${ table_name} drop tag ${ tag_name} ;
105+ """
106+ try {
107+ def sys_query_result = sql """
108+ SELECT * FROM ${ table_name} \$ files;
109+ """
110+ println sys_query_result
111+ println " iceberg_meta_result SUCCESS" + catalog_name
112+
113+ def iceberg_meta_result = sql """
114+ SELECT snapshot_id FROM iceberg_meta(
115+ 'table' = '${ catalog_name} .${ db_name} .${ table_name} ',
116+ 'query_type' = 'snapshots'
117+ ) order by committed_at desc;
118+
119+ """
120+ def first_snapshot_id = iceberg_meta_result. get(0 ). get(0 );
121+ def time_travel = sql """
122+ SELECT * FROM ${ table_name} FOR VERSION AS OF ${ first_snapshot_id} ;
123+ """
124+ println time_travel
125+
126+ println " iceberg_time_travel SUCCESS" + catalog_name
127+ }catch (Exception e) {
128+ println catalog_name + " system info error"
129+ }
130+
131+
132+ sql """
133+ DROP TABLE ${ table_name} ;
134+ """
135+ // partition table
136+ table_name = prefix + " _partition_table"
137+ sql """
138+ CREATE TABLE ${ table_name} (
139+ `ts` DATETIME COMMENT 'ts',
140+ `col1` BOOLEAN COMMENT 'col1',
141+ `col2` INT COMMENT 'col2',
142+ `col3` BIGINT COMMENT 'col3',
143+ `col4` FLOAT COMMENT 'col4',
144+ `col5` DOUBLE COMMENT 'col5',
145+ `col6` DECIMAL(9,4) COMMENT 'col6',
146+ `col7` STRING COMMENT 'col7',
147+ `col8` DATE COMMENT 'col8',
148+ `col9` DATETIME COMMENT 'col9',
149+ `pt1` STRING COMMENT 'pt1',
150+ `pt2` STRING COMMENT 'pt2'
151+ )
152+ PARTITION BY LIST (day(ts), pt1, pt2) ()
153+ PROPERTIES (
154+ 'write-format'='orc',
155+ 'compression-codec'='zlib'
156+ );
157+ """
158+
159+ sql """
160+ INSERT OVERWRITE TABLE ${ table_name} values
161+ ('2023-01-01 00:00:00', true, 1, 1, 1.0, 1.0, 1.0000, '1', '2023-01-01', '2023-01-01 00:00:00', 'a', '1'),
162+ ('2023-01-02 00:00:00', false, 2, 2, 2.0, 2.0, 2.0000, '2', '2023-01-02', '2023-01-02 00:00:00', 'b', '2'),
163+ ('2023-01-03 00:00:00', true, 3, 3, 3.0, 3.0, 3.0000, '3', '2023-01-03', '2023-01-03 00:00:00', 'c', '3');
164+ """
165+ def partitionQueryResult = sql """
166+ SELECT * FROM ${ table_name} WHERE pt1='a' and pt2='1';
167+ """
168+ assert partitionQueryResult. size() == 1
68169
69170 sql """
70171 DROP TABLE ${ table_name} ;
0 commit comments