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('2025-05-13', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:37:59.688',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    1,
    'label_1',
    1,
    cast(date_format('2025-05-12', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:37:59.888',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    2,
    'label_2',
    2,
    cast(date_format('2025-05-11', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:00.088',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    3,
    'label_3',
    3,
    cast(date_format('2025-05-10', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:00.288',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    4,
    'label_4',
    4,
    cast(date_format('2025-05-09', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:00.488',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    5,
    'label_5',
    0,
    cast(date_format('2025-05-08', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:00.688',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    6,
    'label_6',
    1,
    cast(date_format('2025-05-07', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:00.888',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    7,
    'label_7',
    2,
    cast(date_format('2025-05-06', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:01.088',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    8,
    'label_8',
    3,
    cast(date_format('2025-05-05', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:01.288',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    9,
    'label_9',
    4,
    cast(date_format('2025-05-04', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:01.488',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    10,
    'label_10',
    0,
    cast(date_format('2025-05-03', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:01.688',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    11,
    'label_11',
    1,
    cast(date_format('2025-05-02', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:01.888',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    12,
    'label_12',
    2,
    cast(date_format('2025-05-01', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:02.088',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    13,
    'label_13',
    3,
    cast(date_format('2025-04-30', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:02.288',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    14,
    'label_14',
    4,
    cast(date_format('2025-04-29', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:02.488',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    15,
    'label_15',
    0,
    cast(date_format('2025-04-28', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:02.688',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    16,
    'label_16',
    1,
    cast(date_format('2025-04-27', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:02.888',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    17,
    'label_17',
    2,
    cast(date_format('2025-04-26', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:03.088',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    18,
    'label_18',
    3,
    cast(date_format('2025-04-25', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:03.288',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ),
  (
    19,
    'label_19',
    4,
    cast(date_format('2025-04-24', 'yyyy-MM-dd') as date),
    cast(
      date_format(
        '2025-05-13 16:38:03.488',
        'yyyy-MM-dd HH:mm:ss.SSS'
      ) as timestamp
    )
  ) 
  + When we execute it 
  + Then there are now 5 data files:
/partitionKey=0/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00001.parquet
/partitionKey=1/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00002.parquet
/partitionKey=2/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00004.parquet
/partitionKey=3/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00003.parquet
/partitionKey=4/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00005.parquet 
  + And the table contains:
Datum(0,label_0,0,2025-05-13,2025-05-13 16:37:59.688)
Datum(1,label_1,1,2025-05-12,2025-05-13 16:37:59.888)
Datum(2,label_2,2,2025-05-11,2025-05-13 16:38:00.088)
Datum(3,label_3,3,2025-05-10,2025-05-13 16:38:00.288)
Datum(4,label_4,4,2025-05-09,2025-05-13 16:38:00.488)
Datum(5,label_5,0,2025-05-08,2025-05-13 16:38:00.688)
Datum(6,label_6,1,2025-05-07,2025-05-13 16:38:00.888)
Datum(7,label_7,2,2025-05-06,2025-05-13 16:38:01.088)
Datum(8,label_8,3,2025-05-05,2025-05-13 16:38:01.288)
Datum(9,label_9,4,2025-05-04,2025-05-13 16:38:01.488)
Datum(10,label_10,0,2025-05-03,2025-05-13 16:38:01.688)
Datum(11,label_11,1,2025-05-02,2025-05-13 16:38:01.888)
Datum(12,label_12,2,2025-05-01,2025-05-13 16:38:02.088)
Datum(13,label_13,3,2025-04-30,2025-05-13 16:38:02.288)
Datum(14,label_14,4,2025-04-29,2025-05-13 16:38:02.488)
Datum(15,label_15,0,2025-04-28,2025-05-13 16:38:02.688)
Datum(16,label_16,1,2025-04-27,2025-05-13 16:38:02.888)
Datum(17,label_17,2,2025-04-26,2025-05-13 16:38:03.088)
Datum(18,label_18,3,2025-04-25,2025-05-13 16:38:03.288)
Datum(19,label_19,4,2025-04-24,2025-05-13 16:38:03.488)
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  
- 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-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00001.parquet
/partitionKey=1/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00002.parquet
/partitionKey=1/00000-1558-c257f9cf-9efb-4d47-8d23-1f1d362807a8-0-00001.parquet
/partitionKey=2/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00004.parquet
/partitionKey=3/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00003.parquet
/partitionKey=4/00000-1548-6264a3f9-3ac9-4946-9360-d5f7a345569d-0-00005.parquet 
  + And the table contains:
Datum(0,label_0,0,2025-05-13,2025-05-13 16:37:59.688)
Datum(1,label_1X,1,2025-05-12,2025-05-13 16:37:59.888)
Datum(2,label_2,2,2025-05-11,2025-05-13 16:38:00.088)
Datum(3,label_3,3,2025-05-10,2025-05-13 16:38:00.288)
Datum(4,label_4,4,2025-05-09,2025-05-13 16:38:00.488)
Datum(5,label_5,0,2025-05-08,2025-05-13 16:38:00.688)
Datum(6,label_6,1,2025-05-07,2025-05-13 16:38:00.888)
Datum(7,label_7,2,2025-05-06,2025-05-13 16:38:01.088)
Datum(8,label_8,3,2025-05-05,2025-05-13 16:38:01.288)
Datum(9,label_9,4,2025-05-04,2025-05-13 16:38:01.488)
Datum(10,label_10,0,2025-05-03,2025-05-13 16:38:01.688)
Datum(11,label_11,1,2025-05-02,2025-05-13 16:38:01.888)
Datum(12,label_12,2,2025-05-01,2025-05-13 16:38:02.088)
Datum(13,label_13,3,2025-04-30,2025-05-13 16:38:02.288)
Datum(14,label_14,4,2025-04-29,2025-05-13 16:38:02.488)
Datum(15,label_15,0,2025-04-28,2025-05-13 16:38:02.688)
Datum(16,label_16,1,2025-04-27,2025-05-13 16:38:02.888)
Datum(17,label_17,2,2025-04-26,2025-05-13 16:38:03.088)
Datum(18,label_18,3,2025-04-25,2025-05-13 16:38:03.288)
Datum(19,label_19,4,2025-04-24,2025-05-13 16:38:03.488)
 
  + 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 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +  
Run completed in 29 seconds, 743 milliseconds.
Total number of tests run: 38
Suites: completed 22, aborted 0
Tests: succeeded 38, failed 0, canceled 0, ignored 4, pending 0
All tests passed.