Skip to content

Conversation

@kbendick
Copy link
Contributor

This adds tests for the serialization / deserialization of CreateTableRequest.

This class is already being used quite a bit in other tests, specifically CatalogTests and TestRESTCatalog. It also relied pretty heavily on existing serializers inside of RESTSerializers for things like Schema etc, which simply call out to our existing parsers.

Thus, I kept the tests light in terms of combinations of schemas etc as this is a combination of several tested components.

@github-actions github-actions bot added the core label Jun 15, 2022
private UnboundSortOrder order;
private Map<String, String> properties;
private Boolean stageCreate;
private Boolean stageCreate = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I defaulted this to false so that users didn't need to explicitly set it if writing JSON. Because it's a boxed Boolean, if it's not present in the JSON, it gets set as null.

I did this because CreateTableRequest does not have stageCreate in its list of required fields in the OpenAPI spec.

As there is an assertion that stageCreate is not null in the validate method of this class, I would also be comfortable with requiring that stageCreate be set in the OpenAPI spec, but I prefer this as it matches the builders behavior as well (if .stageCreate() isn't called on the builder, false is used).

@Test
// Test cases that are JSON that can be created via the Builder
public void testRoundTripSerDe() throws JsonProcessingException {
String fullJsonRaw =
Copy link
Contributor Author

@kbendick kbendick Jun 15, 2022

Choose a reason for hiding this comment

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

As most of the complex fields (all of the classes we define, such as Schema etc) are serialized and deserialized via the existing *Parser, I only put one test where the whole JSON is defined as a raw string).

Formatting it well across lines was somewhat difficult, as the assertRoundTripSerializesEquallyFrom method requires that the JSON matches letter for letter, so it can't have newlines.

I can split this out with newlines and then replace them if we'd like though, or even read from an external file if need be.

// The same JSON but using existing parsers for clarity
String fullJson = String.format(
"{\"name\":\"%s\",\"location\":\"%s\",\"schema\":%s,\"spec\":%s," +
"\"order\":%s,\"properties\":%s,\"stageCreate\":%b}",
Copy link
Contributor Author

@kbendick kbendick Jun 15, 2022

Choose a reason for hiding this comment

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

For strings that continue onto the next line, my editor (with our configuration applied) wanted the next string line to be indented. I can remove that though I started questioning what the style standard is 😅

Comment on lines +279 to +281
Assert.assertTrue("Schemas should be equivalent and have same schema id",
expected.schema().sameSchema(actual.schema()) && expected.schema().schemaId() == actual.schema().schemaId());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally had this as two assertions (one for sameSchema and one for equality checking on schemaId).

If we prefer, I can revert to that.

@kbendick
Copy link
Contributor Author

cc @danielcweeks @rdblue @Fokko @nastra and @singhpk234 who has helped contribute to some areas of the REST spec.

Kept this one relatively simple given that most of the heavy lifting is done by existing Parsers.

Copy link
Contributor

@singhpk234 singhpk234 left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks @kbendick !!

@kbendick kbendick force-pushed the kb-add-create-table-request-tests branch from 59eef97 to 46bcb86 Compare June 20, 2022 03:58
@rdblue rdblue merged commit a3c44ee into apache:master Jun 20, 2022
@rdblue
Copy link
Contributor

rdblue commented Jun 20, 2022

Thanks, @kbendick!

@kbendick kbendick deleted the kb-add-create-table-request-tests branch June 21, 2022 16:51
namrathamyske pushed a commit to namrathamyske/iceberg that referenced this pull request Jul 10, 2022
namrathamyske pushed a commit to namrathamyske/iceberg that referenced this pull request Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants