Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -28,6 +28,11 @@ public interface RegisterTableRequest extends RESTRequest {

String metadataLocation();

@Value.Default
default boolean overwrite() {
return false;
}

@Override
default void validate() {
// nothing to validate as it's not possible to create an invalid instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class RegisterTableRequestParser {

private static final String NAME = "name";
private static final String METADATA_LOCATION = "metadata-location";
private static final String OVERWRITE = "overwrite";

private RegisterTableRequestParser() {}

Expand All @@ -47,6 +48,10 @@ public static void toJson(RegisterTableRequest request, JsonGenerator gen) throw
gen.writeStringField(NAME, request.name());
gen.writeStringField(METADATA_LOCATION, request.metadataLocation());

if (request.overwrite()) {
gen.writeBooleanField(OVERWRITE, request.overwrite());
}

gen.writeEndObject();
}

Expand All @@ -61,9 +66,14 @@ public static RegisterTableRequest fromJson(JsonNode json) {
String name = JsonUtil.getString(NAME, json);
String metadataLocation = JsonUtil.getString(METADATA_LOCATION, json);

return ImmutableRegisterTableRequest.builder()
.name(name)
.metadataLocation(metadataLocation)
.build();
ImmutableRegisterTableRequest.Builder builder =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is it possible to put them in one line if we are using var?

ImmutableRegisterTableRequest.builder().name(name).metadataLocation(metadataLocation);

Boolean overwrite = JsonUtil.getBoolOrNull(OVERWRITE, json);
if (overwrite != null) {
builder.overwrite(overwrite);
}

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,28 @@ public void roundTripSerde() {
assertThat(RegisterTableRequestParser.toJson(RegisterTableRequestParser.fromJson(json), true))
.isEqualTo(expectedJson);
}

@Test
public void roundTripSerdeWithOverwrite() {
RegisterTableRequest request =
ImmutableRegisterTableRequest.builder()
.name("table_1")
.metadataLocation(
"file://tmp/NS/test_tbl/metadata/00000-d4f60d2f-2ad2-408b-8832-0ed7fbd851ee.metadata.json")
.overwrite(true)
.build();

String expectedJson =
"{\n"
+ " \"name\" : \"table_1\",\n"
+ " \"metadata-location\" : \"file://tmp/NS/test_tbl/metadata/00000-d4f60d2f-2ad2-408b-8832-0ed7fbd851ee.metadata.json\",\n"
+ " \"overwrite\" : true\n"
+ "}";

String json = RegisterTableRequestParser.toJson(request, true);
assertThat(json).isEqualTo(expectedJson);

assertThat(RegisterTableRequestParser.toJson(RegisterTableRequestParser.fromJson(json), true))
.isEqualTo(expectedJson);
}
}