-
Notifications
You must be signed in to change notification settings - Fork 116
Omit __ prefixed identifiers from protobuf translation #3706
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
alecgrieser
merged 8 commits into
FoundationDB:main
from
g31pranjal:omit_double_underscore_prefixed_from_protobuf_compliant_translations
Nov 3, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
625481f
omit __ prefixed identifiers from protobuf translation
g31pranjal bcfb921
fix style
g31pranjal 4998472
address comments
g31pranjal 993bb42
update
g31pranjal 8bea956
update
g31pranjal 6aae90d
cleanup
g31pranjal 6dfc25a
more cleanup
g31pranjal b2cee70
more more cleanup
g31pranjal 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
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
83 changes: 83 additions & 0 deletions
83
...c/test/java/com/apple/foundationdb/relational/recordlayer/metadata/DataTypeUtilsTest.java
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * DataTypeUtilsTest.java | ||
| * | ||
| * This source file is part of the FoundationDB open source project | ||
| * | ||
| * Copyright 2015-2025 Apple Inc. and the FoundationDB project authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.apple.foundationdb.relational.recordlayer.metadata; | ||
|
|
||
| import com.apple.foundationdb.relational.api.exceptions.UncheckedRelationalException; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class DataTypeUtilsTest { | ||
|
|
||
|
|
||
| static Stream<Arguments> protobufCompliantNameTestArguments() { | ||
| return Stream.of( | ||
| Arguments.of("__", "__"), | ||
| Arguments.of("_", "_"), | ||
| Arguments.of("$", null), | ||
| Arguments.of(".", null), | ||
| Arguments.of("__hello", "__hello"), | ||
| Arguments.of("__$hello", "____1hello"), | ||
| Arguments.of("__$hello", "____1hello"), | ||
| Arguments.of("__.hello", "____2hello"), | ||
| Arguments.of("____hello", "____0hello"), | ||
| Arguments.of("__$h$e$l$l$o", "____1h__1e__1l__1l__1o"), | ||
| Arguments.of("__0", null), | ||
| Arguments.of("__0hello", null), | ||
| Arguments.of("__1", null), | ||
| Arguments.of("__1hello", null), | ||
| Arguments.of("__2", null), | ||
| Arguments.of("__2hello", null), | ||
| Arguments.of("__4", "__4"), | ||
| Arguments.of("__$$$$", "____1__1__1__1"), | ||
| Arguments.of("______", "____0__0"), | ||
| Arguments.of("__4hello", "__4hello"), | ||
| Arguments.of("$", null), | ||
| Arguments.of("$hello", null), | ||
| Arguments.of(".", null), | ||
| Arguments.of(".hello", null), | ||
| Arguments.of("h__e__l__l__o", "h__0e__0l__0l__0o"), | ||
| Arguments.of("h.e.l.l.o", "h__2e__2l__2l__2o"), | ||
| Arguments.of("h$e$l$l$o", "h__1e__1l__1l__1o"), | ||
| Arguments.of("1hello", null), | ||
| Arguments.of("डेटाबेस", null) | ||
| ); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("protobufCompliantNameTestArguments") | ||
| void protobufCompliantNameTest(@Nonnull String userIdentifier, @Nullable String protobufIdentifier) { | ||
| if (protobufIdentifier != null) { | ||
| final var actual = DataTypeUtils.toProtoBufCompliantName(userIdentifier); | ||
| Assertions.assertThat(actual).isEqualTo(protobufIdentifier); | ||
| final var reTranslated = DataTypeUtils.toUserIdentifier(actual); | ||
| Assertions.assertThat(reTranslated).isEqualTo(userIdentifier); | ||
| } else { | ||
| Assertions.assertThatThrownBy(() -> DataTypeUtils.toProtoBufCompliantName(userIdentifier)) | ||
| .isInstanceOf(UncheckedRelationalException.class); | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * identifiers.proto | ||
| * | ||
| * This source file is part of the FoundationDB open source project | ||
| * | ||
| * Copyright 2021-2024 Apple Inc. and the FoundationDB project authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| syntax = "proto3"; | ||
|
|
||
| // make sure to use this package naming convention: | ||
| // com.apple.foundationdb.relational.yamltests.generated.<name_of_test_suite> | ||
| // adding "generated" is important to exclude the generated Java file from Jacoco reports. | ||
| // suffixing the namespace with your test name is important for segregating similarly-named | ||
| // generated-Java-classes (such as RecordTypeUnion) into separate packages, otherwise you | ||
| // get an error from `protoc`. | ||
| package com.apple.foundationdb.relational.yamltests.generated.identifierstests; | ||
|
|
||
| option java_outer_classname = "IdentifiersTestProto"; | ||
|
|
||
| import "record_metadata_options.proto"; | ||
|
|
||
| message T1 { | ||
| int64 ID = 1 [(com.apple.foundationdb.record.field).primary_key = true]; | ||
| int64 T1__2COL1 = 2; | ||
| int64 T1__2COL2 = 3; | ||
| } | ||
|
|
||
| message T2 { | ||
| int64 ID = 1 [(com.apple.foundationdb.record.field).primary_key = true]; | ||
| int64 T2__1COL1 = 2; | ||
| int64 T2__1COL2 = 3; | ||
| } | ||
|
|
||
| message __T3 { | ||
| int64 ID = 1 [(com.apple.foundationdb.record.field).primary_key = true]; | ||
| int64 __T3__1COL1 = 2; | ||
| int64 __T3__1COL2 = 3; | ||
| } | ||
|
|
||
| message internal { | ||
| int64 a = 1; | ||
| int64 b = 2; | ||
| } | ||
|
|
||
| message T4 { | ||
| int64 ID = 1 [(com.apple.foundationdb.record.field).primary_key = true]; | ||
| internal ___hidden = 2; | ||
| int64 T4__2COL1 = 3; | ||
| int64 T4__2COL2 = 4; | ||
| } | ||
|
|
||
| message RecordTypeUnion { | ||
| T1 _T1 = 1; | ||
| T2 _T2 = 2; | ||
| __T3 ___T3 = 3; | ||
| T4 _T4 = 4; | ||
| } |
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.
Do view names actually need to be protobuf compliant? Shouldn't we only generate one of these if we're going to generate a protobuf ID out of the SQL ID (things like table names, structs, enums, fields, etc). I would have thought that that's not necessary for views
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.
Anything addressable from the user query would need to be translated. This is because it translates all identifiers in the query regardless of what they actually refer to. If we want to leave it out we probably need to some sort of logic in
generateAccessto be able to work with and without translation.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.
Hm, I see. It seems to me like this is a sign that the abstractions aren't quite right. Like, ideally, we'd be able to use names that aren't (necessarily) Protobuf compliant everywhere until right when we go and talk to Protobuf. But that can be something we work on later