-
Notifications
You must be signed in to change notification settings - Fork 3.5k
API: Fix inconsistent TimeTransform Type #6482
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 |
|---|---|---|
|
|
@@ -20,8 +20,10 @@ | |
|
|
||
| import static org.apache.iceberg.expressions.Expressions.bucket; | ||
| import static org.apache.iceberg.expressions.Expressions.truncate; | ||
| import static org.apache.iceberg.expressions.Expressions.year; | ||
|
|
||
| import org.apache.iceberg.transforms.Transforms; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
@@ -187,6 +189,46 @@ public void testRemoveAndAddField() { | |
| Assert.assertEquals(1001, table.spec().lastAssignedFieldId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAddAfterRemoveTimeField() { | ||
| table.updateSchema().addColumn("year_field", Types.DateType.get()).commit(); | ||
| table.updateSpec().addField(year("year_field")).commit(); | ||
|
|
||
| PartitionSpec newSpec = PartitionSpec.builderFor(table.schema()) | ||
| .withSpecId(1) | ||
| .bucket("data", 16) | ||
| .year("year_field") | ||
| .build(); | ||
|
|
||
| Assert.assertEquals( | ||
| "Should have same transform class: org.apache.iceberg.transforms.Years", | ||
| newSpec.fields().get(1).transform().getClass().getName(), | ||
| table.spec().fields().get(1).transform().getClass().getName()); | ||
| Assert.assertEquals("Should append a year partition field to the spec", newSpec, table.spec()); | ||
| Assert.assertEquals(1001, table.spec().lastAssignedFieldId()); | ||
|
|
||
| // remove and add a field with TimeTransform(Years, Months, Days, Hours) | ||
| table.updateSpec().removeField("year_field_year").addField(year("year_field")).commit(); | ||
|
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. Do we need to add a case that remove
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. I don't think we need this case. Other tests have include the case, eg. |
||
|
|
||
| V1Assert.assertEquals( | ||
| "Should remove and then add a year field", | ||
| PartitionSpec.builderFor(table.schema()) | ||
| .withSpecId(1) | ||
| .bucket("data", 16) | ||
| .year("year_field") | ||
| .build(), | ||
| table.spec()); | ||
| V2Assert.assertEquals( | ||
|
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. Again, these two tests are essentially the same for me, right? Please correct me if I missed something.
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.
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. Oh, You mean |
||
| "Should remove and then add a year field", | ||
| PartitionSpec.builderFor(table.schema()) | ||
| .withSpecId(1) | ||
| .add(2, 1000, "data_bucket", Transforms.bucket(16)) | ||
| .add(3, 1001, "year_field_year", Transforms.year()) | ||
| .build(), | ||
| table.spec()); | ||
| Assert.assertEquals(1001, table.spec().lastAssignedFieldId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAddAndRemoveField() { | ||
| table.updateSpec().addField(bucket("data", 6)).removeField("data_bucket").commit(); | ||
|
|
||
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.
I'm hesitant to remove those because then there is a situation where we don't know the
sourceColumn.