@@ -79,6 +79,17 @@ def example_table_metadata_with_snapshot_v1_rest_json(example_table_metadata_wit
79
79
}
80
80
81
81
82
+ @pytest .fixture
83
+ def example_table_metadata_with_no_location (example_table_metadata_with_snapshot_v1 : Dict [str , Any ]) -> Dict [str , Any ]:
84
+ return {
85
+ "metadata" : example_table_metadata_with_snapshot_v1 ,
86
+ "config" : {
87
+ "client.factory" : "io.tabular.iceberg.catalog.TabularAwsClientFactory" ,
88
+ "region" : "us-west-2" ,
89
+ },
90
+ }
91
+
92
+
82
93
@pytest .fixture
83
94
def example_table_metadata_no_snapshot_v1_rest_json (example_table_metadata_no_snapshot_v1 : Dict [str , Any ]) -> Dict [str , Any ]:
84
95
return {
@@ -899,6 +910,70 @@ def test_create_table_with_given_location_removes_trailing_slash_200(
899
910
assert rest_mock .last_request .json ()["location" ] == location
900
911
901
912
913
+ def test_create_staged_table_200 (
914
+ rest_mock : Mocker ,
915
+ table_schema_simple : Schema ,
916
+ example_table_metadata_with_no_location : Dict [str , Any ],
917
+ example_table_metadata_no_snapshot_v1_rest_json : Dict [str , Any ],
918
+ ) -> None :
919
+ rest_mock .post (
920
+ f"{ TEST_URI } v1/namespaces/fokko/tables" ,
921
+ json = example_table_metadata_with_no_location ,
922
+ status_code = 200 ,
923
+ request_headers = TEST_HEADERS ,
924
+ )
925
+ rest_mock .post (
926
+ f"{ TEST_URI } v1/namespaces/fokko/tables/fokko2" ,
927
+ json = example_table_metadata_no_snapshot_v1_rest_json ,
928
+ status_code = 200 ,
929
+ request_headers = TEST_HEADERS ,
930
+ )
931
+ identifier = ("fokko" , "fokko2" )
932
+ catalog = RestCatalog ("rest" , uri = TEST_URI , token = TEST_TOKEN )
933
+ txn = catalog .create_table_transaction (
934
+ identifier = identifier ,
935
+ schema = table_schema_simple ,
936
+ location = None ,
937
+ partition_spec = PartitionSpec (
938
+ PartitionField (source_id = 1 , field_id = 1000 , transform = TruncateTransform (width = 3 ), name = "id" ), spec_id = 1
939
+ ),
940
+ sort_order = SortOrder (SortField (source_id = 2 , transform = IdentityTransform ())),
941
+ properties = {"owner" : "fokko" },
942
+ )
943
+ txn .commit_transaction ()
944
+
945
+ actual_response = rest_mock .last_request .json ()
946
+ expected = {
947
+ "identifier" : {"namespace" : ["fokko" ], "name" : "fokko2" },
948
+ "requirements" : [{"type" : "assert-create" }],
949
+ "updates" : [
950
+ {"action" : "assign-uuid" , "uuid" : "b55d9dda-6561-423a-8bfc-787980ce421f" },
951
+ {"action" : "upgrade-format-version" , "format-version" : 1 },
952
+ {
953
+ "action" : "add-schema" ,
954
+ "schema" : {
955
+ "type" : "struct" ,
956
+ "fields" : [
957
+ {"id" : 1 , "name" : "id" , "type" : "int" , "required" : False },
958
+ {"id" : 2 , "name" : "data" , "type" : "string" , "required" : False },
959
+ ],
960
+ "schema-id" : 0 ,
961
+ "identifier-field-ids" : [],
962
+ },
963
+ "last-column-id" : 2 ,
964
+ },
965
+ {"action" : "set-current-schema" , "schema-id" : - 1 },
966
+ {"action" : "add-spec" , "spec" : {"spec-id" : 0 , "fields" : []}},
967
+ {"action" : "set-default-spec" , "spec-id" : - 1 },
968
+ {"action" : "add-sort-order" , "sort-order" : {"order-id" : 0 , "fields" : []}},
969
+ {"action" : "set-default-sort-order" , "sort-order-id" : - 1 },
970
+ {"action" : "set-location" , "location" : "s3://warehouse/database/table" },
971
+ {"action" : "set-properties" , "updates" : {"owner" : "bryan" , "write.metadata.compression-codec" : "gzip" }},
972
+ ],
973
+ }
974
+ assert actual_response == expected
975
+
976
+
902
977
def test_create_table_409 (rest_mock : Mocker , table_schema_simple : Schema ) -> None :
903
978
rest_mock .post (
904
979
f"{ TEST_URI } v1/namespaces/fokko/tables" ,
0 commit comments