Repository navigation
API: Add the file type #18252
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
Open
RussellSpitzer
wants to merge
2
commits into
apache:main
Choose a base branch
from
RussellSpitzer:file-type-1-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+684
−63
Open
API: Add the file type #18252
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,8 +31,8 @@ class AssignIds extends TypeUtil.CustomOrderSchemaVisitor<Type> { | |||||
| this.getID = getID; | ||||||
| } | ||||||
|
|
||||||
| private int idFor(int id) { | ||||||
| return getID.get(id); | ||||||
| private int idFor(int id, Type type) { | ||||||
| return type.isFileType() ? getID.get(id, Types.FileType.NUM_NESTED_FIELDS) : getID.get(id); | ||||||
|
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. looks like there's constant need to figure out the reserved id space of given type, 6 for file and 0 otherwise, maybe we can move it to TypeUtils so this can be simply
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -48,15 +48,16 @@ public Type struct(Types.StructType struct, Iterable<Type> futures) { | |||||
| // assign IDs for this struct's fields first | ||||||
| List<Integer> newIds = Lists.newArrayListWithExpectedSize(length); | ||||||
| for (Types.NestedField field : fields) { | ||||||
| newIds.add(idFor(field.fieldId())); | ||||||
| newIds.add(idFor(field.fieldId(), field.type())); | ||||||
| } | ||||||
|
|
||||||
| List<Types.NestedField> newFields = Lists.newArrayListWithExpectedSize(length); | ||||||
| Iterator<Type> types = futures.iterator(); | ||||||
| for (int i = 0; i < length; i += 1) { | ||||||
| Types.NestedField field = fields.get(i); | ||||||
| Type type = types.next(); | ||||||
| newFields.add(Types.NestedField.from(field).withId(newIds.get(i)).ofType(type).build()); | ||||||
| int newId = newIds.get(i); | ||||||
| Type type = TypeUtil.applyAssignedId(field.type(), newId, types.next()); | ||||||
| newFields.add(Types.NestedField.from(field).withId(newId).ofType(type).build()); | ||||||
| } | ||||||
|
|
||||||
| return Types.StructType.of(newFields); | ||||||
|
|
@@ -69,22 +70,25 @@ public Type field(Types.NestedField field, Supplier<Type> future) { | |||||
|
|
||||||
| @Override | ||||||
| public Type list(Types.ListType list, Supplier<Type> future) { | ||||||
| int newId = idFor(list.elementId()); | ||||||
| int newId = idFor(list.elementId(), list.elementType()); | ||||||
| Type elementType = TypeUtil.applyAssignedId(list.elementType(), newId, future.get()); | ||||||
| if (list.isElementOptional()) { | ||||||
| return Types.ListType.ofOptional(newId, future.get()); | ||||||
| return Types.ListType.ofOptional(newId, elementType); | ||||||
| } else { | ||||||
| return Types.ListType.ofRequired(newId, future.get()); | ||||||
| return Types.ListType.ofRequired(newId, elementType); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public Type map(Types.MapType map, Supplier<Type> keyFuture, Supplier<Type> valueFuture) { | ||||||
| int newKeyId = idFor(map.keyId()); | ||||||
| int newValueId = idFor(map.valueId()); | ||||||
| int newKeyId = idFor(map.keyId(), map.keyType()); | ||||||
| int newValueId = idFor(map.valueId(), map.valueType()); | ||||||
| Type keyType = TypeUtil.applyAssignedId(map.keyType(), newKeyId, keyFuture.get()); | ||||||
| Type valueType = TypeUtil.applyAssignedId(map.valueType(), newValueId, valueFuture.get()); | ||||||
| if (map.isValueOptional()) { | ||||||
| return Types.MapType.ofOptional(newKeyId, newValueId, keyFuture.get(), valueFuture.get()); | ||||||
| return Types.MapType.ofOptional(newKeyId, newValueId, keyType, valueType); | ||||||
| } else { | ||||||
| return Types.MapType.ofRequired(newKeyId, newValueId, keyFuture.get(), valueFuture.get()); | ||||||
| return Types.MapType.ofRequired(newKeyId, newValueId, keyType, valueType); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -93,6 +97,12 @@ public Type variant(Types.VariantType variant) { | |||||
| return variant; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public Type file(Types.FileType file, Iterable<Type> futures) { | ||||||
| // nested fields are rebuilt from the new id assigned to the field that holds this type | ||||||
| return file; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public Type primitive(Type.PrimitiveType primitive) { | ||||||
| return primitive; | ||||||
|
|
||||||
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.
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.
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.
looks like the logic is find the filed by id and look up in the schema, then we can make type based decision on whether to reuse the base id. we can potentially inline the logic of canReuseBaseId and baseField? Something like