Repository navigation
Improve MetaDataProtoEditor handling of unqualified types and add support for renaming all the types - #3402
Conversation
We can't update the SQL string
This has better support for the situation where the types don't have any qualification.
Just directly call into MetaDataProtoEditor, and merge the tests
This parses the protobuf to find the actual type names, removing our need to replicate protobufs name resolution. This does have the downside that it might result in converting non-fully-qualified types to fully-qualified types when it doesn't need to, but I'm not going to optimize that at this point. There's also still a bunch of TODOs because I didn't want to flush out the whole call hierarchy. And FDBMetaDataStoreTest still fails, but that will come next.
…iptor Some of the other code dependend on fieldIsType but didn't have a descriptor handy, so updated that to use the descriptors now.
I ended up not using it
After MetaDataProtoEditor was added more things were added to the MetaData protobuf that were not supported. This isn't exhaustive, but hopefully helps.
alecgrieser
left a comment
There was a problem hiding this comment.
I had a few clarifying questions about some of the stuff in the editor, but nothing too major. I haven't had a chance to look at the test code changes yet, but I figured I'd submit this now for your responses
These were added before I switched to FileDescriptor, and I think I just didn't recognize that I needed to clean them up.
(well a lot if you count the parameters)
I didn't know the find* methods existed, so I created a map, but it does, so no need for the map.
alecgrieser
left a comment
There was a problem hiding this comment.
LGTM. I had a few thoughts as I was going through, but it also looks good to me. Feel free to merge if you don't think there's anything that needs responding to
| private static boolean isNested(@Nonnull Descriptors.Descriptor typeDescriptor, | ||
| @Nonnull Descriptors.Descriptor targetDescriptor) { | ||
| if (typeDescriptor.equals(targetDescriptor)) { | ||
| return true; |
There was a problem hiding this comment.
It's maybe a bit interesting to me that this method considers a type is considered to be nested within itself, though I think that's consistent with how the method is used. I'm trying to think if there's a way that makes that more obvious, like "is sub-type of", but that also depends on whether people think of "improper sub-types" (like an improper subset)
There was a problem hiding this comment.
Yeah, I think it makes it a little bit simpler to implement it's one usage. Although, maybe it would be better as a do-while. I added a javadoc to make it clear.
| assertSame(simpleRecordDescriptor, modifiedFileDescriptor.findMessageTypeByName(RecordMetaDataBuilder.DEFAULT_UNION_NAME).findFieldByName("_MySimpleRecord").getMessageType()); | ||
|
|
||
| assertEquals(FieldTypeMatch.MIGHT_MATCH, | ||
| assertEquals(FieldTypeMatch.MATCHES, |
There was a problem hiding this comment.
I'm sure you felt this while you were trying to edit these tests, but this does seem like the kind of thing that we'd want to consider refactoring into a parameterized test. It probably would have sped up fixing all of these
| { | ||
| "name": "VALUE", | ||
| "number": 2, | ||
| "type": "TYPE_INT64" |
There was a problem hiding this comment.
What would happen here if we had an index set via a field annotation? Would that get added into the indexes list (with a name based on the original type) and then type renaming would just keep the old name? Or would the annotation be persisted and potentially re-evaluated leading to an index with the new type name?
There was a problem hiding this comment.
It does not rename the index, the index is preserved in the metadata. Which is essential because it needs to persist things like subspace, and modified versions. I added a test of this behavior. The test uses the RecordMetaData.toProto, but that does appear to fully qualify, so I'm glad we still have all these handwritten json files.
| "name": "T1", | ||
| "number": 2, | ||
| "type": "TYPE_MESSAGE", | ||
| "type_name": "T1" |
There was a problem hiding this comment.
Do we have tests here that attempt to do things like use different package specifications for the type name here? I think we have tests for that in the unit test, but maybe not through these JSON files. That level of testing may be fine
There was a problem hiding this comment.
I don't think I want to get into different package specifications at this level, because that's, in some ways, testing protobuf's resolution.
I did, however, add a test where there is a dependency with the same name as one of the types.
I also reworked the tests to make it easier to write tests that have additional assertions on the renamed result.
ScottDugas
left a comment
There was a problem hiding this comment.
Yeah, I thought some of the additional tests would be important to have.
| private static boolean isNested(@Nonnull Descriptors.Descriptor typeDescriptor, | ||
| @Nonnull Descriptors.Descriptor targetDescriptor) { | ||
| if (typeDescriptor.equals(targetDescriptor)) { | ||
| return true; |
There was a problem hiding this comment.
Yeah, I think it makes it a little bit simpler to implement it's one usage. Although, maybe it would be better as a do-while. I added a javadoc to make it clear.
| "name": "T1", | ||
| "number": 2, | ||
| "type": "TYPE_MESSAGE", | ||
| "type_name": "T1" |
There was a problem hiding this comment.
I don't think I want to get into different package specifications at this level, because that's, in some ways, testing protobuf's resolution.
I did, however, add a test where there is a dependency with the same name as one of the types.
| { | ||
| "name": "VALUE", | ||
| "number": 2, | ||
| "type": "TYPE_INT64" |
There was a problem hiding this comment.
It does not rename the index, the index is preserved in the metadata. Which is essential because it needs to persist things like subspace, and modified versions. I added a test of this behavior. The test uses the RecordMetaData.toProto, but that does appear to fully qualify, so I'm glad we still have all these handwritten json files.
This does two things:
MetaDataProtoEditor.renameRecordTypesthat takes a function to rename all the types.Descriptors.FileDescriptor, and lets that do the type resolution. This requires you to be able to get the dependencies in order to do these operations, but it means that we don't have to try to re-implement protobuf's type resolution.And don't be too afraid about the lines changed, it is mostly new json files to try and test more of the rename logic.
Historical note: I didn't realize MetaDataProtoEditor existed, so I wrote my own suite of tests, and implementation. Then discovered and tried to merge, at which point I discovered that it couldn't handle the unqualified types in my protobufs, and thus went about fixing it. In hindsight, I should have stopped to fix the issue about ambiguous types and come back to the new method, but I was using the new tests to validate it.
Resolves: #3428