Repository navigation
fix: keep default values of proto3 fields without presence in protobuf ingestion #20485
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
amaechler
merged 4 commits into
apache:master
from
amaechler:protobuf-proto3-default-values
Oct 6, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e77b4ce
Keep default values of proto3 fields without presence in protobuf ing…
amaechler 4d7d053
Size converted map for declared fields and trim proto3 test
amaechler 1893e62
Reword converter comment and wrap test builder
amaechler a5c196b
Add embedded proto3 ingestion test for default values
amaechler 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
Binary file not shown.
32 changes: 32 additions & 0 deletions
32
embedded-tests/src/test/resources/data/protobuf/proto3_event.proto
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,32 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You 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. | ||
|
|
||
| // Regenerate the descriptor from this directory with: | ||
| // protoc --include_imports --descriptor_set_out=proto3_event.desc proto3_event.proto | ||
|
|
||
| syntax = "proto3"; | ||
|
|
||
| message Proto3Event { | ||
| enum Category { | ||
| ZERO = 0; | ||
| ONE = 1; | ||
| } | ||
|
|
||
| string timestamp = 1; | ||
| int32 someInt = 2; | ||
| string someString = 3; | ||
| bool someBool = 4; | ||
| Category category = 5; | ||
| } |
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
59 changes: 59 additions & 0 deletions
59
...-extensions/src/test/java/org/apache/druid/data/input/protobuf/ProtobufConverterTest.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,59 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.druid.data.input.protobuf; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.protobuf.DynamicMessage; | ||
| import org.apache.druid.data.input.protobuf.Proto3TestEventWrapper.Proto3TestEvent; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class ProtobufConverterTest | ||
| { | ||
| @Test | ||
| public void testProto3ImplicitPresenceFieldsKeepDefaultValues() throws Exception | ||
| { | ||
| Assertions.assertEquals( | ||
| ImmutableMap.of( | ||
| "someInt", 0, | ||
| "someString", "", | ||
| "category", "CATEGORY_ZERO" | ||
| ), | ||
| convert(Proto3TestEvent.getDefaultInstance()) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testProto3NestedMessageKeepsDefaultValues() throws Exception | ||
| { | ||
| final Proto3TestEvent event = | ||
| Proto3TestEvent.newBuilder().setNested(Proto3TestEvent.Nested.getDefaultInstance()).build(); | ||
|
|
||
| Assertions.assertEquals(ImmutableMap.of("value", 0), convert(event).get("nested")); | ||
| } | ||
|
|
||
| private static Map<String, Object> convert(Proto3TestEvent event) throws Exception | ||
| { | ||
| // Round-trip through bytes like ingestion does. | ||
| return ProtobufConverter.convertMessage(DynamicMessage.parseFrom(Proto3TestEvent.getDescriptor(), event.toByteArray())); | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
extensions-core/protobuf-extensions/src/test/resources/proto3_test_event.proto
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,37 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You 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"; | ||
| package proto3test; | ||
| option java_package = "org.apache.druid.data.input.protobuf"; | ||
| option java_outer_classname = "Proto3TestEventWrapper"; | ||
|
|
||
| message Proto3TestEvent { | ||
| enum Category { | ||
| CATEGORY_ZERO = 0; | ||
| CATEGORY_ONE = 1; | ||
| } | ||
|
|
||
| message Nested { | ||
| int32 value = 1; | ||
| } | ||
|
|
||
| int32 someInt = 1; | ||
| string someString = 2; | ||
| Category category = 3; | ||
| optional int32 optionalInt = 4; | ||
| Nested nested = 5; | ||
| repeated int32 someList = 6; | ||
| } |
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.