-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Core: do not allow optional, double and float identifier fields #2705
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1238,7 +1238,8 @@ public void testAddExistingIdentifierFields() { | |
| @Test | ||
| public void testAddNewIdentifierFieldColumns() { | ||
| Schema newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .addColumn("new_field", Types.StringType.get()) | ||
| .allowIncompatibleChanges() | ||
| .addRequiredColumn("new_field", Types.StringType.get()) | ||
| .setIdentifierFields("id", "new_field") | ||
| .apply(); | ||
|
|
||
|
|
@@ -1247,8 +1248,9 @@ public void testAddNewIdentifierFieldColumns() { | |
| newSchema.identifierFieldIds()); | ||
|
|
||
| newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .allowIncompatibleChanges() | ||
| .setIdentifierFields("id", "new_field") | ||
| .addColumn("new_field", Types.StringType.get()) | ||
| .addRequiredColumn("new_field", Types.StringType.get()) | ||
| .apply(); | ||
|
|
||
| Assert.assertEquals("set identifier then add column should succeed", | ||
|
|
@@ -1267,8 +1269,9 @@ public void testAddNestedIdentifierFieldColumns() { | |
| newSchema.identifierFieldIds()); | ||
|
|
||
| newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .addColumn("new", Types.StructType.of( | ||
| Types.NestedField.optional(SCHEMA_LAST_COLUMN_ID + 1, "field", Types.StringType.get()) | ||
| .allowIncompatibleChanges() | ||
| .addRequiredColumn("new", Types.StructType.of( | ||
| Types.NestedField.required(SCHEMA_LAST_COLUMN_ID + 1, "field", Types.StringType.get()) | ||
| )) | ||
| .setIdentifierFields("new.field") | ||
| .apply(); | ||
|
|
@@ -1278,9 +1281,10 @@ public void testAddNestedIdentifierFieldColumns() { | |
| newSchema.identifierFieldIds()); | ||
|
|
||
| newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .addColumn("new", Types.StructType.of( | ||
| Types.NestedField.optional(SCHEMA_LAST_COLUMN_ID + 1, "field", Types.StructType.of( | ||
| Types.NestedField.optional(SCHEMA_LAST_COLUMN_ID + 2, "nested", Types.StringType.get()))))) | ||
| .allowIncompatibleChanges() | ||
| .addRequiredColumn("new", Types.StructType.of( | ||
| Types.NestedField.required(SCHEMA_LAST_COLUMN_ID + 1, "field", Types.StructType.of( | ||
| Types.NestedField.required(SCHEMA_LAST_COLUMN_ID + 2, "nested", Types.StringType.get()))))) | ||
| .setIdentifierFields("new.field.nested") | ||
| .apply(); | ||
|
|
||
|
|
@@ -1292,7 +1296,8 @@ public void testAddNestedIdentifierFieldColumns() { | |
| @Test | ||
| public void testAddDottedIdentifierFieldColumns() { | ||
| Schema newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .addColumn(null, "dot.field", Types.StringType.get()) | ||
| .allowIncompatibleChanges() | ||
| .addRequiredColumn(null, "dot.field", Types.StringType.get()) | ||
| .setIdentifierFields("id", "dot.field") | ||
| .apply(); | ||
|
|
||
|
|
@@ -1304,8 +1309,9 @@ public void testAddDottedIdentifierFieldColumns() { | |
| @Test | ||
| public void testRemoveIdentifierFields() { | ||
| Schema newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .addColumn("new_field", Types.StringType.get()) | ||
| .addColumn("new_field2", Types.StringType.get()) | ||
| .allowIncompatibleChanges() | ||
| .addRequiredColumn("new_field", Types.StringType.get()) | ||
| .addRequiredColumn("new_field2", Types.StringType.get()) | ||
| .setIdentifierFields("id", "new_field", "new_field2") | ||
| .apply(); | ||
|
|
||
|
|
@@ -1342,18 +1348,18 @@ public void testSetIdentifierFieldsFails() { | |
| .setIdentifierFields("locations") | ||
| .apply()); | ||
|
|
||
| AssertHelpers.assertThrows("add a map key nested field should fail", | ||
| AssertHelpers.assertThrows("add an optional field should fail", | ||
| IllegalArgumentException.class, | ||
| "must not be nested in " + SCHEMA.findField("locations"), | ||
| "not a required field", | ||
| () -> new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .setIdentifierFields("locations.key.zip") | ||
| .setIdentifierFields("data") | ||
| .apply()); | ||
|
|
||
| AssertHelpers.assertThrows("add a map value nested field should fail", | ||
| AssertHelpers.assertThrows("add a map key nested field should fail", | ||
| IllegalArgumentException.class, | ||
| "must not be nested in " + SCHEMA.findField("locations"), | ||
| () -> new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .setIdentifierFields("locations.value.lat") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the test case using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah because that will hit the double check before hitting the map check. I added another one later with column |
||
| .setIdentifierFields("locations.key.zip") | ||
| .apply()); | ||
|
|
||
| AssertHelpers.assertThrows("add a nested field in list should fail", | ||
|
|
@@ -1364,19 +1370,52 @@ public void testSetIdentifierFieldsFails() { | |
| .apply()); | ||
|
|
||
| Schema newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID) | ||
| .addColumn("new", Types.StructType.of( | ||
| Types.NestedField.optional(SCHEMA_LAST_COLUMN_ID + 1, "fields", Types.ListType.ofOptional( | ||
| SCHEMA_LAST_COLUMN_ID + 2, Types.StructType.of( | ||
| Types.NestedField.optional(SCHEMA_LAST_COLUMN_ID + 3, "nested", Types.StringType.get()) | ||
| .allowIncompatibleChanges() | ||
| .addRequiredColumn("col_float", Types.FloatType.get()) | ||
| .addRequiredColumn("col_double", Types.DoubleType.get()) | ||
| .addRequiredColumn("new", Types.StructType.of( | ||
| Types.NestedField.required(SCHEMA_LAST_COLUMN_ID + 3, "fields", Types.ListType.ofOptional( | ||
| SCHEMA_LAST_COLUMN_ID + 4, Types.StructType.of( | ||
| Types.NestedField.required(SCHEMA_LAST_COLUMN_ID + 5, "nested", Types.StringType.get()) | ||
| )) | ||
| ) | ||
| )) | ||
| .addRequiredColumn("new_map", Types.MapType.ofRequired(SCHEMA_LAST_COLUMN_ID + 6, 11, | ||
| Types.StructType.of( | ||
| required(SCHEMA_LAST_COLUMN_ID + 7, "key_col", Types.StringType.get()) | ||
| ), | ||
| Types.StructType.of( | ||
| required(SCHEMA_LAST_COLUMN_ID + 8, "val_col", Types.StringType.get()) | ||
| )), "map of address to coordinate") | ||
| .apply(); | ||
|
|
||
| int lastColId = SCHEMA_LAST_COLUMN_ID + 8; | ||
|
|
||
| AssertHelpers.assertThrows("add a double field should fail", | ||
| IllegalArgumentException.class, | ||
| "must not be float or double field", | ||
| () -> new SchemaUpdate(newSchema, lastColId) | ||
| .setIdentifierFields("col_double") | ||
| .apply()); | ||
|
|
||
| AssertHelpers.assertThrows("add a float field should fail", | ||
| IllegalArgumentException.class, | ||
| "must not be float or double field", | ||
| () -> new SchemaUpdate(newSchema, lastColId) | ||
| .setIdentifierFields("col_float") | ||
| .apply()); | ||
|
|
||
| AssertHelpers.assertThrows("add a map value nested field should fail", | ||
| IllegalArgumentException.class, | ||
| "must not be nested in " + newSchema.findField("new_map"), | ||
| () -> new SchemaUpdate(newSchema, lastColId) | ||
| .setIdentifierFields("new_map.value.val_col") | ||
| .apply()); | ||
|
|
||
| AssertHelpers.assertThrows("add a nested field in struct of a map should fail", | ||
| IllegalArgumentException.class, | ||
| "must not be nested in " + newSchema.findField("new.fields"), | ||
| () -> new SchemaUpdate(newSchema, SCHEMA_LAST_COLUMN_ID + 3) | ||
| () -> new SchemaUpdate(newSchema, lastColId) | ||
| .setIdentifierFields("new.fields.element.nested") | ||
| .apply()); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is another bug not really related to the discussion, trying to just merge it here instead of having another 1 line PR.