Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI: add initial/write defaults to schema #12094

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class TestCreateTableRequest extends RequestResponseTestBase<CreateTableR
private static final String SAMPLE_LOCATION = "file://tmp/location/";
private static final Schema SAMPLE_SCHEMA =
new Schema(
required(1, "id", Types.IntegerType.get()), optional(2, "data", Types.StringType.get()));
required("id").withId(1).ofType(Types.IntegerType.get()).withWriteDefault(1).build(),
optional("data").withId(2).ofType(Types.StringType.get()).build());
private static final String SAMPLE_SCHEMA_JSON = SchemaParser.toJson(SAMPLE_SCHEMA);
private static final PartitionSpec SAMPLE_SPEC =
PartitionSpec.builderFor(SAMPLE_SCHEMA).bucket("id", 16).build();
Expand All @@ -59,7 +60,7 @@ public class TestCreateTableRequest extends RequestResponseTestBase<CreateTableR
public void testRoundTripSerDe() throws JsonProcessingException {
String fullJsonRaw =
"{\"name\":\"test_tbl\",\"location\":\"file://tmp/location/\",\"schema\":{\"type\":\"struct\","
+ "\"schema-id\":0,\"fields\":[{\"id\":1,\"name\":\"id\",\"required\":true,\"type\":\"int\"},"
+ "\"schema-id\":0,\"fields\":[{\"id\":1,\"name\":\"id\",\"required\":true,\"type\":\"int\",\"write-default\":1},"
danielcweeks marked this conversation as resolved.
Show resolved Hide resolved
+ "{\"id\":2,\"name\":\"data\",\"required\":false,\"type\":\"string\"}]},\"partition-spec\":{\"spec-id\":0,"
+ "\"fields\":[{\"name\":\"id_bucket\",\"transform\":\"bucket[16]\",\"source-id\":1,\"field-id\":1000}]},"
+ "\"write-order\":{\"order-id\":1,\"fields\":"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ public void testRoundTripSerdeWithV2TableMetadata() throws Exception {
assertRoundTripSerializesEquallyFrom(json, resp);
}

@Test
public void testRoundTripSerdeWithV3TableMetadata() throws Exception {
String tableMetadataJson = readTableMetadataInputFile("TableMetadataV3ValidMinimal.json");
TableMetadata v3Metadata =
TableMetadataParser.fromJson(TEST_METADATA_LOCATION, tableMetadataJson);
// Convert the TableMetadata JSON from the file to an object and then back to JSON so that
// missing fields
danielcweeks marked this conversation as resolved.
Show resolved Hide resolved
// are filled in with their default values.
String json =
String.format(
"{\"metadata-location\":\"%s\",\"metadata\":%s,\"config\":{\"foo\":\"bar\"}}",
TEST_METADATA_LOCATION, TableMetadataParser.toJson(v3Metadata));
LoadTableResponse resp =
LoadTableResponse.builder().withTableMetadata(v3Metadata).addAllConfig(CONFIG).build();
assertRoundTripSerializesEquallyFrom(json, resp);
}

@Test
public void testCanDeserializeWithoutDefaultValues() throws Exception {
String metadataJson = readTableMetadataInputFile("TableMetadataV1Valid.json");
Expand Down
73 changes: 73 additions & 0 deletions core/src/test/resources/TableMetadataV3ValidMinimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"format-version": 2,
"table-uuid": "9c12d441-03fe-4693-9a96-a0705ddf69c1",
"location": "s3://bucket/test/location",
"last-sequence-number": 34,
"last-updated-ms": 1602638573590,
"last-column-id": 3,
"current-schema-id": 0,
"schemas": [
{
"type": "struct",
"schema-id": 0,
"fields": [
{
"id": 1,
"name": "x",
"required": true,
"type": "long",
"initial-default": 1,
"write-default": 1
},
{
"id": 2,
"name": "y",
"required": true,
"type": "long",
"doc": "comment"
},
{
"id": 3,
"name": "z",
"required": true,
"type": "long"
}
]
}
],
"default-spec-id": 0,
"partition-specs": [
{
"spec-id": 0,
"fields": [
{
"name": "x",
"transform": "identity",
"source-id": 1,
"field-id": 1000
}
]
}
],
"last-partition-id": 1000,
"default-sort-order-id": 3,
"sort-orders": [
{
"order-id": 3,
"fields": [
{
"transform": "identity",
"source-id": 2,
"direction": "asc",
"null-order": "nulls-first"
},
{
"transform": "bucket[4]",
"source-id": 3,
"direction": "desc",
"null-order": "nulls-last"
}
]
}
]
}
2 changes: 2 additions & 0 deletions open-api/rest-catalog-open-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ class StructField(BaseModel):
type: Type
required: bool
doc: Optional[str] = None
initial_default: Optional[str] = Field(None, alias='initial-default')
write_default: Optional[str] = Field(None, alias='write-default')


class StructType(BaseModel):
Expand Down
4 changes: 4 additions & 0 deletions open-api/rest-catalog-open-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,10 @@ components:
type: boolean
doc:
type: string
initial-default:
type: string
danielcweeks marked this conversation as resolved.
Show resolved Hide resolved
write-default:
type: string
danielcweeks marked this conversation as resolved.
Show resolved Hide resolved

StructType:
type: object
Expand Down