CopyOnWriteSpec: A copy-on-write table - should create no new files for copy-on-write + Given SQL: CREATE TABLE polaris.my_namespace.CopyOnWriteSpec ( id int, label String, partitionKey long, date Date, timestamp Timestamp ) USING iceberg TBLPROPERTIES ( 'format-version' = '2', 'write.delete.mode' = 'copy-on-write', 'write.update.mode' = 'copy-on-write', 'sort-order' = 'partitionKey ASC NULLS FIRST', 'write.merge.mode' = 'copy-on-write' ) PARTITIONED BY (partitionKey); + When we execute it + Then there is an Iceberg table, polaris.my_namespace.CopyOnWriteSpec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - should insert creates new files for copy-on-write + Given SQL: INSERT INTO TABLE polaris.my_namespace.CopyOnWriteSpec (id, label, partitionKey, date, timestamp) VALUES ( 0, 'label_0', 0, cast(date_format('2024-11-15', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:19.792', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 1, 'label_1', 1, cast(date_format('2024-11-14', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:19.992', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 2, 'label_2', 2, cast(date_format('2024-11-13', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:20.192', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 3, 'label_3', 3, cast(date_format('2024-11-12', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:20.392', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 4, 'label_4', 4, cast(date_format('2024-11-11', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:20.592', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 5, 'label_5', 0, cast(date_format('2024-11-10', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:20.792', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 6, 'label_6', 1, cast(date_format('2024-11-09', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:20.992', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 7, 'label_7', 2, cast(date_format('2024-11-08', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:21.192', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 8, 'label_8', 3, cast(date_format('2024-11-07', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:21.392', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 9, 'label_9', 4, cast(date_format('2024-11-06', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:21.592', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 10, 'label_10', 0, cast(date_format('2024-11-05', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:21.792', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 11, 'label_11', 1, cast(date_format('2024-11-04', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:21.992', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 12, 'label_12', 2, cast(date_format('2024-11-03', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:22.192', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 13, 'label_13', 3, cast(date_format('2024-11-02', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:22.392', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 14, 'label_14', 4, cast(date_format('2024-11-01', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:22.592', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 15, 'label_15', 0, cast(date_format('2024-10-31', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:22.792', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 16, 'label_16', 1, cast(date_format('2024-10-30', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:22.992', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 17, 'label_17', 2, cast(date_format('2024-10-29', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:23.192', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 18, 'label_18', 3, cast(date_format('2024-10-28', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:23.392', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ), ( 19, 'label_19', 4, cast(date_format('2024-10-27', 'yyyy-MM-dd') as date), cast( date_format( '2024-11-15 16:48:23.592', 'yyyy-MM-dd HH:mm:ss.SSS' ) as timestamp ) ) + When we execute it + Then there are now 5 data files: /partitionKey=0/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00001.parquet /partitionKey=1/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00002.parquet /partitionKey=2/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00004.parquet /partitionKey=3/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00003.parquet /partitionKey=4/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00005.parquet + And the table contains: Datum(0,label_0,0,2024-11-15,2024-11-15 16:48:19.792) Datum(1,label_1,1,2024-11-14,2024-11-15 16:48:19.992) Datum(2,label_2,2,2024-11-13,2024-11-15 16:48:20.192) Datum(3,label_3,3,2024-11-12,2024-11-15 16:48:20.392) Datum(4,label_4,4,2024-11-11,2024-11-15 16:48:20.592) Datum(5,label_5,0,2024-11-10,2024-11-15 16:48:20.792) Datum(6,label_6,1,2024-11-09,2024-11-15 16:48:20.992) Datum(7,label_7,2,2024-11-08,2024-11-15 16:48:21.192) Datum(8,label_8,3,2024-11-07,2024-11-15 16:48:21.392) Datum(9,label_9,4,2024-11-06,2024-11-15 16:48:21.592) Datum(10,label_10,0,2024-11-05,2024-11-15 16:48:21.792) Datum(11,label_11,1,2024-11-04,2024-11-15 16:48:21.992) Datum(12,label_12,2,2024-11-03,2024-11-15 16:48:22.192) Datum(13,label_13,3,2024-11-02,2024-11-15 16:48:22.392) Datum(14,label_14,4,2024-11-01,2024-11-15 16:48:22.592) Datum(15,label_15,0,2024-10-31,2024-11-15 16:48:22.792) Datum(16,label_16,1,2024-10-30,2024-11-15 16:48:22.992) Datum(17,label_17,2,2024-10-29,2024-11-15 16:48:23.192) Datum(18,label_18,3,2024-10-28,2024-11-15 16:48:23.392) Datum(19,label_19,4,2024-10-27,2024-11-15 16:48:23.592) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - should update creates no new files for copy-on-write + Given SQL: UPDATE polaris.my_namespace.CopyOnWriteSpec SET label = 'label_1X' WHERE id = 1 + When we execute it + Then there are now 6 data files: /partitionKey=0/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00001.parquet /partitionKey=1/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00002.parquet /partitionKey=1/00000-758-d84ebc3d-aa76-4559-b286-7ea73a68aaff-0-00001.parquet /partitionKey=2/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00004.parquet /partitionKey=3/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00003.parquet /partitionKey=4/00000-752-ca550831-7816-4d78-b8dd-57300540ebe1-0-00005.parquet + And the table contains: Datum(0,label_0,0,2024-11-15,2024-11-15 16:48:19.792) Datum(1,label_1X,1,2024-11-14,2024-11-15 16:48:19.992) Datum(2,label_2,2,2024-11-13,2024-11-15 16:48:20.192) Datum(3,label_3,3,2024-11-12,2024-11-15 16:48:20.392) Datum(4,label_4,4,2024-11-11,2024-11-15 16:48:20.592) Datum(5,label_5,0,2024-11-10,2024-11-15 16:48:20.792) Datum(6,label_6,1,2024-11-09,2024-11-15 16:48:20.992) Datum(7,label_7,2,2024-11-08,2024-11-15 16:48:21.192) Datum(8,label_8,3,2024-11-07,2024-11-15 16:48:21.392) Datum(9,label_9,4,2024-11-06,2024-11-15 16:48:21.592) Datum(10,label_10,0,2024-11-05,2024-11-15 16:48:21.792) Datum(11,label_11,1,2024-11-04,2024-11-15 16:48:21.992) Datum(12,label_12,2,2024-11-03,2024-11-15 16:48:22.192) Datum(13,label_13,3,2024-11-02,2024-11-15 16:48:22.392) Datum(14,label_14,4,2024-11-01,2024-11-15 16:48:22.592) Datum(15,label_15,0,2024-10-31,2024-11-15 16:48:22.792) Datum(16,label_16,1,2024-10-30,2024-11-15 16:48:22.992) Datum(17,label_17,2,2024-10-29,2024-11-15 16:48:23.192) Datum(18,label_18,3,2024-10-28,2024-11-15 16:48:23.392) Datum(19,label_19,4,2024-10-27,2024-11-15 16:48:23.592) + And the new data file contains just the updated row(s) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - should reading an updated table using copy-on-write + Given a table that has been updated + When we read from it + Then the table still contains 20 records + And there are no new data files + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +