-
Notifications
You must be signed in to change notification settings - Fork 3.5k
API: Remove source type from Transform #5601
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c5816c4
Refactor Transforms.
rdblue cfffac9
Apply spotless.
rdblue 004e105
Uncomment deprecated tests for Dates and Timestamps.
rdblue 05cbaf7
Add revapi exception.
rdblue 20d794c
Fix CI failures.
rdblue 0a97eea
Fix timestamp projection tests.
rdblue b9bece9
Fix dates projection tests.
rdblue d114197
Ensure bound transforms are Serializable.
rdblue 6d74089
Fix review comments.
rdblue 9b58049
Add serialization tests.
rdblue b841764
Apply spotless.
rdblue fb21289
Fix toHumanString.
rdblue a3c37dc
Update ExpressionParser.
rdblue 3a8a866
Fix error message from Bucket.
rdblue 7e176fe
Update for review suggestions.
rdblue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ public class PartitionSpec implements Serializable { | |
| private final PartitionField[] fields; | ||
| private transient volatile ListMultimap<Integer, PartitionField> fieldsBySourceId = null; | ||
| private transient volatile Class<?>[] lazyJavaClasses = null; | ||
| private transient volatile StructType lazyPartitionType = null; | ||
| private transient volatile List<PartitionField> fieldList = null; | ||
| private final int lastAssignedFieldId; | ||
|
|
||
|
|
@@ -123,16 +124,23 @@ public List<PartitionField> getFieldsBySourceId(int fieldId) { | |
|
|
||
| /** Returns a {@link StructType} for partition data defined by this spec. */ | ||
| public StructType partitionType() { | ||
| List<Types.NestedField> structFields = Lists.newArrayListWithExpectedSize(fields.length); | ||
| if (lazyPartitionType == null) { | ||
| synchronized (this) { | ||
| if (lazyPartitionType == null) { | ||
| List<Types.NestedField> structFields = Lists.newArrayListWithExpectedSize(fields.length); | ||
|
|
||
| for (int i = 0; i < fields.length; i += 1) { | ||
| PartitionField field = fields[i]; | ||
| Type sourceType = schema.findType(field.sourceId()); | ||
| Type resultType = field.transform().getResultType(sourceType); | ||
| structFields.add(Types.NestedField.optional(field.fieldId(), field.name(), resultType)); | ||
| for (PartitionField field : fields) { | ||
| Type sourceType = schema.findType(field.sourceId()); | ||
| Type resultType = field.transform().getResultType(sourceType); | ||
| structFields.add(Types.NestedField.optional(field.fieldId(), field.name(), resultType)); | ||
| } | ||
|
|
||
| this.lazyPartitionType = Types.StructType.of(structFields); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Types.StructType.of(structFields); | ||
| return lazyPartitionType; | ||
| } | ||
|
|
||
| public Class<?>[] javaClasses() { | ||
|
|
@@ -175,9 +183,11 @@ private String escape(String string) { | |
| public String partitionToPath(StructLike data) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| Class<?>[] javaClasses = javaClasses(); | ||
| List<Types.NestedField> outputFields = partitionType().fields(); | ||
| for (int i = 0; i < javaClasses.length; i += 1) { | ||
| PartitionField field = fields[i]; | ||
| String valueString = field.transform().toHumanString(get(data, i, javaClasses[i])); | ||
| Type type = outputFields.get(i).type(); | ||
| String valueString = field.transform().toHumanString(type, get(data, i, javaClasses[i])); | ||
|
|
||
| if (i > 0) { | ||
| sb.append("/"); | ||
|
|
@@ -412,10 +422,7 @@ Builder identity(String sourceName, String targetName) { | |
| checkAndAddPartitionName(targetName, sourceColumn.fieldId()); | ||
| PartitionField field = | ||
| new PartitionField( | ||
| sourceColumn.fieldId(), | ||
| nextFieldId(), | ||
| targetName, | ||
| Transforms.identity(sourceColumn.type())); | ||
| sourceColumn.fieldId(), nextFieldId(), targetName, Transforms.identity()); | ||
| checkForRedundantPartitions(field); | ||
| fields.add(field); | ||
| return this; | ||
|
|
@@ -429,11 +436,7 @@ public Builder year(String sourceName, String targetName) { | |
| checkAndAddPartitionName(targetName); | ||
| Types.NestedField sourceColumn = findSourceColumn(sourceName); | ||
| PartitionField field = | ||
| new PartitionField( | ||
| sourceColumn.fieldId(), | ||
| nextFieldId(), | ||
| targetName, | ||
| Transforms.year(sourceColumn.type())); | ||
| new PartitionField(sourceColumn.fieldId(), nextFieldId(), targetName, Transforms.year()); | ||
| checkForRedundantPartitions(field); | ||
| fields.add(field); | ||
| return this; | ||
|
|
@@ -447,11 +450,7 @@ public Builder month(String sourceName, String targetName) { | |
| checkAndAddPartitionName(targetName); | ||
| Types.NestedField sourceColumn = findSourceColumn(sourceName); | ||
| PartitionField field = | ||
| new PartitionField( | ||
| sourceColumn.fieldId(), | ||
| nextFieldId(), | ||
| targetName, | ||
| Transforms.month(sourceColumn.type())); | ||
| new PartitionField(sourceColumn.fieldId(), nextFieldId(), targetName, Transforms.month()); | ||
| checkForRedundantPartitions(field); | ||
| fields.add(field); | ||
| return this; | ||
|
|
@@ -465,11 +464,7 @@ public Builder day(String sourceName, String targetName) { | |
| checkAndAddPartitionName(targetName); | ||
| Types.NestedField sourceColumn = findSourceColumn(sourceName); | ||
| PartitionField field = | ||
| new PartitionField( | ||
| sourceColumn.fieldId(), | ||
| nextFieldId(), | ||
| targetName, | ||
| Transforms.day(sourceColumn.type())); | ||
| new PartitionField(sourceColumn.fieldId(), nextFieldId(), targetName, Transforms.day()); | ||
|
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. The new line length is quite unfortunate. |
||
| checkForRedundantPartitions(field); | ||
| fields.add(field); | ||
| return this; | ||
|
|
@@ -483,11 +478,7 @@ public Builder hour(String sourceName, String targetName) { | |
| checkAndAddPartitionName(targetName); | ||
| Types.NestedField sourceColumn = findSourceColumn(sourceName); | ||
| PartitionField field = | ||
| new PartitionField( | ||
| sourceColumn.fieldId(), | ||
| nextFieldId(), | ||
| targetName, | ||
| Transforms.hour(sourceColumn.type())); | ||
| new PartitionField(sourceColumn.fieldId(), nextFieldId(), targetName, Transforms.hour()); | ||
| checkForRedundantPartitions(field); | ||
| fields.add(field); | ||
| return this; | ||
|
|
@@ -502,10 +493,7 @@ public Builder bucket(String sourceName, int numBuckets, String targetName) { | |
| Types.NestedField sourceColumn = findSourceColumn(sourceName); | ||
| fields.add( | ||
| new PartitionField( | ||
| sourceColumn.fieldId(), | ||
| nextFieldId(), | ||
| targetName, | ||
| Transforms.bucket(sourceColumn.type(), numBuckets))); | ||
| sourceColumn.fieldId(), nextFieldId(), targetName, Transforms.bucket(numBuckets))); | ||
| return this; | ||
| } | ||
|
|
||
|
|
@@ -518,10 +506,7 @@ public Builder truncate(String sourceName, int width, String targetName) { | |
| Types.NestedField sourceColumn = findSourceColumn(sourceName); | ||
| fields.add( | ||
| new PartitionField( | ||
| sourceColumn.fieldId(), | ||
| nextFieldId(), | ||
| targetName, | ||
| Transforms.truncate(sourceColumn.type(), width))); | ||
| sourceColumn.fieldId(), nextFieldId(), targetName, Transforms.truncate(width))); | ||
| return this; | ||
| } | ||
|
|
||
|
|
@@ -545,16 +530,10 @@ public Builder alwaysNull(String sourceName) { | |
|
|
||
| // add a partition field with an auto-increment partition field id starting from | ||
| // PARTITION_DATA_ID_START | ||
| Builder add(int sourceId, String name, String transform) { | ||
| Builder add(int sourceId, String name, Transform<?, ?> transform) { | ||
| return add(sourceId, nextFieldId(), name, transform); | ||
| } | ||
|
|
||
| Builder add(int sourceId, int fieldId, String name, String transform) { | ||
| Types.NestedField column = schema.findField(sourceId); | ||
| Preconditions.checkNotNull(column, "Cannot find source column: %s", sourceId); | ||
| return add(sourceId, fieldId, name, Transforms.fromString(column.type(), transform)); | ||
| } | ||
|
|
||
| Builder add(int sourceId, int fieldId, String name, Transform<?, ?> transform) { | ||
| checkAndAddPartitionName(name, sourceId); | ||
| fields.add(new PartitionField(sourceId, fieldId, name, transform)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.