117
117
import static org .apache .iceberg .TableProperties .METADATA_DELETE_AFTER_COMMIT_ENABLED ;
118
118
import static org .apache .iceberg .TableProperties .METADATA_PREVIOUS_VERSIONS_MAX ;
119
119
import static org .apache .iceberg .TableProperties .SPLIT_SIZE ;
120
+ import static org .apache .iceberg .TableUtil .formatVersion ;
120
121
import static org .apache .iceberg .mapping .NameMappingParser .toJson ;
121
122
import static org .assertj .core .api .Assertions .assertThat ;
122
123
import static org .junit .jupiter .api .TestInstance .Lifecycle .PER_CLASS ;
@@ -154,11 +155,11 @@ public void testSettingFormatVersion()
154
155
{
155
156
String tableName = "test_seting_format_version_" + randomNameSuffix ();
156
157
assertUpdate ("CREATE TABLE " + tableName + " WITH (format_version = 2) AS SELECT * FROM tpch.tiny.nation" , 25 );
157
- assertThat (loadTable (tableName ). operations (). current (). formatVersion ( )).isEqualTo (2 );
158
+ assertThat (formatVersion ( loadTable (tableName ))).isEqualTo (2 );
158
159
assertUpdate ("DROP TABLE " + tableName );
159
160
160
161
assertUpdate ("CREATE TABLE " + tableName + " WITH (format_version = 1) AS SELECT * FROM tpch.tiny.nation" , 25 );
161
- assertThat (loadTable (tableName ). operations (). current (). formatVersion ( )).isEqualTo (1 );
162
+ assertThat (formatVersion ( loadTable (tableName ))).isEqualTo (1 );
162
163
assertUpdate ("DROP TABLE " + tableName );
163
164
}
164
165
@@ -167,7 +168,7 @@ public void testDefaultFormatVersion()
167
168
{
168
169
String tableName = "test_default_format_version_" + randomNameSuffix ();
169
170
assertUpdate ("CREATE TABLE " + tableName + " AS SELECT * FROM tpch.tiny.nation" , 25 );
170
- assertThat (loadTable (tableName ). operations (). current (). formatVersion ( )).isEqualTo (2 );
171
+ assertThat (formatVersion ( loadTable (tableName ))).isEqualTo (2 );
171
172
assertUpdate ("DROP TABLE " + tableName );
172
173
}
173
174
@@ -687,9 +688,9 @@ public void testUpgradeTableToV2FromTrino()
687
688
{
688
689
String tableName = "test_upgrade_table_to_v2_from_trino_" + randomNameSuffix ();
689
690
assertUpdate ("CREATE TABLE " + tableName + " WITH (format_version = 1) AS SELECT * FROM tpch.tiny.nation" , 25 );
690
- assertThat (loadTable (tableName ). operations (). current (). formatVersion ( )).isEqualTo (1 );
691
+ assertThat (formatVersion ( loadTable (tableName ))).isEqualTo (1 );
691
692
assertUpdate ("ALTER TABLE " + tableName + " SET PROPERTIES format_version = 2" );
692
- assertThat (loadTable (tableName ). operations (). current (). formatVersion ( )).isEqualTo (2 );
693
+ assertThat (formatVersion ( loadTable (tableName ))).isEqualTo (2 );
693
694
assertQuery ("SELECT * FROM " + tableName , "SELECT * FROM nation" );
694
695
}
695
696
@@ -698,7 +699,7 @@ public void testDowngradingV2TableToV1Fails()
698
699
{
699
700
String tableName = "test_downgrading_v2_table_to_v1_fails_" + randomNameSuffix ();
700
701
assertUpdate ("CREATE TABLE " + tableName + " WITH (format_version = 2) AS SELECT * FROM tpch.tiny.nation" , 25 );
701
- assertThat (loadTable (tableName ). operations (). current (). formatVersion ( )).isEqualTo (2 );
702
+ assertThat (formatVersion ( loadTable (tableName ))).isEqualTo (2 );
702
703
assertThat (query ("ALTER TABLE " + tableName + " SET PROPERTIES format_version = 1" ))
703
704
.failure ()
704
705
.hasMessage ("Failed to set new property values" )
@@ -711,7 +712,7 @@ public void testUpgradingToInvalidVersionFails()
711
712
{
712
713
String tableName = "test_upgrading_to_invalid_version_fails_" + randomNameSuffix ();
713
714
assertUpdate ("CREATE TABLE " + tableName + " WITH (format_version = 2) AS SELECT * FROM tpch.tiny.nation" , 25 );
714
- assertThat (loadTable (tableName ). operations (). current (). formatVersion ( )).isEqualTo (2 );
715
+ assertThat (formatVersion ( loadTable (tableName ))).isEqualTo (2 );
715
716
assertThat (query ("ALTER TABLE " + tableName + " SET PROPERTIES format_version = 42" ))
716
717
.failure ().hasMessage ("line 1:79: Unable to set catalog 'iceberg' table property 'format_version' to [42]: format_version must be between 1 and 2" );
717
718
}
@@ -722,13 +723,13 @@ public void testUpdatingAllTableProperties()
722
723
String tableName = "test_updating_all_table_properties_" + randomNameSuffix ();
723
724
assertUpdate ("CREATE TABLE " + tableName + " WITH (format_version = 1, format = 'ORC') AS SELECT * FROM tpch.tiny.nation" , 25 );
724
725
BaseTable table = loadTable (tableName );
725
- assertThat (table . operations (). current (). formatVersion ()).isEqualTo (1 );
726
+ assertThat (formatVersion (table )).isEqualTo (1 );
726
727
assertThat (table .properties ().get (TableProperties .DEFAULT_FILE_FORMAT ).equalsIgnoreCase ("ORC" )).isTrue ();
727
728
assertThat (table .spec ().isUnpartitioned ()).isTrue ();
728
729
729
730
assertUpdate ("ALTER TABLE " + tableName + " SET PROPERTIES format_version = 2, partitioning = ARRAY['regionkey'], format = 'PARQUET', sorted_by = ARRAY['comment']" );
730
731
table = loadTable (tableName );
731
- assertThat (table . operations (). current (). formatVersion ()).isEqualTo (2 );
732
+ assertThat (formatVersion (table )).isEqualTo (2 );
732
733
assertThat (table .properties ().get (TableProperties .DEFAULT_FILE_FORMAT ).equalsIgnoreCase ("PARQUET" )).isTrue ();
733
734
assertThat (table .spec ().isPartitioned ()).isTrue ();
734
735
List <PartitionField > partitionFields = table .spec ().fields ();
@@ -749,7 +750,7 @@ public void testUnsettingAllTableProperties()
749
750
assertUpdate ("CREATE TABLE " + tableName + " WITH (format_version = 1, format = 'PARQUET', partitioning = ARRAY['regionkey'], sorted_by = ARRAY['comment']) " +
750
751
"AS SELECT * FROM tpch.tiny.nation" , 25 );
751
752
BaseTable table = loadTable (tableName );
752
- assertThat (table . operations (). current (). formatVersion ()).isEqualTo (1 );
753
+ assertThat (formatVersion (table )).isEqualTo (1 );
753
754
assertThat (table .properties ().get (TableProperties .DEFAULT_FILE_FORMAT ).equalsIgnoreCase ("PARQUET" )).isTrue ();
754
755
assertThat (table .spec ().isPartitioned ()).isTrue ();
755
756
List <PartitionField > partitionFields = table .spec ().fields ();
@@ -759,7 +760,7 @@ public void testUnsettingAllTableProperties()
759
760
760
761
assertUpdate ("ALTER TABLE " + tableName + " SET PROPERTIES format_version = DEFAULT, format = DEFAULT, partitioning = DEFAULT, sorted_by = DEFAULT" );
761
762
table = loadTable (tableName );
762
- assertThat (table . operations (). current (). formatVersion ()).isEqualTo (2 );
763
+ assertThat (formatVersion (table )).isEqualTo (2 );
763
764
assertThat (table .properties ().get (TableProperties .DEFAULT_FILE_FORMAT ).equalsIgnoreCase ("PARQUET" )).isTrue ();
764
765
assertThat (table .spec ().isUnpartitioned ()).isTrue ();
765
766
assertThat (table .sortOrder ().isUnsorted ()).isTrue ();
0 commit comments