-
Notifications
You must be signed in to change notification settings - Fork 3.8k
#12912 Fix KafkaEmitter not emitting queryType for a native query #12915
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
abhishekagarwal87
merged 6 commits into
apache:master
from
deep-bi:feature-fix-kafka-emitter-missing-query-type
Aug 24, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08d767a
#12912 Fix KafkaEmitter not emitting queryType for a native query
BartMiki 5505d73
Remove dependency on joda DateTime in UnitTests
BartMiki 56237ef
#12912 Replace bare Map with EventMap in Event#toMap
BartMiki 59e2b38
#12912 Use @Test instead of TestCase
BartMiki 4cb8ee0
#12912 Refactor: move test to correct modules, modify EventMap with b…
BartMiki 8d250ae
#12912 Refactor: rename unit test classes
BartMiki 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
109 changes: 109 additions & 0 deletions
109
core/src/main/java/org/apache/druid/java/util/emitter/core/EventMap.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,109 @@ | ||
| /* | ||
| * 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.java.util.emitter.core; | ||
|
|
||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * EventMap is a hash map implementation. It can be safely serialzed to JSON using Jackson serializer as it | ||
| * respects the polymorphic annotations on entires (unlike standard Map). The example of polymorphic class is a query | ||
| * interface, where different native query types are resolved by additional field called "queryType". | ||
| * This implementation ensures that the annotation on the values are respected during serialization. | ||
| */ | ||
| @JsonSerialize(using = EventMapSerializer.class) | ||
| public class EventMap extends HashMap<String, Object> | ||
| { | ||
| /** | ||
| * Returns builder with Fluent API to build EventMap instance using method chaining | ||
| */ | ||
| public static Builder builder() | ||
| { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * Convert this EventMap to a builder. Performs copy of the whole EventMap. | ||
| */ | ||
| public Builder asBuilder() | ||
| { | ||
| return new Builder().putAll(this); | ||
| } | ||
|
|
||
| public static class Builder | ||
| { | ||
|
|
||
| private final EventMap map; | ||
|
|
||
| protected Builder() | ||
| { | ||
| map = new EventMap(); | ||
| } | ||
|
|
||
| /** | ||
| * Adds key -> value pair to the map | ||
| */ | ||
| public Builder put(String key, Object value) | ||
| { | ||
| map.put(key, value); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Adds key -> value pair to the map only if value is not null | ||
| */ | ||
| public Builder putNonNull(String key, Object value) | ||
| { | ||
| if (value != null) { | ||
| map.put(key, value); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Adds map entry to the map | ||
| */ | ||
| public Builder put(Map.Entry<String, Object> entry) | ||
| { | ||
| map.put(entry.getKey(), entry.getValue()); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Adds all key -> value pairs from other map | ||
| */ | ||
| public Builder putAll(Map<? extends String, ? extends Object> other) | ||
| { | ||
| map.putAll(other); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Builds and returns the EventMap | ||
| */ | ||
| public EventMap build() | ||
| { | ||
| return map; | ||
| } | ||
| } | ||
|
|
||
| } | ||
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/apache/druid/java/util/emitter/core/EventMapSerializer.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,40 @@ | ||
| /* | ||
| * 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.java.util.emitter.core; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.JsonSerializer; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| public class EventMapSerializer extends JsonSerializer<EventMap> | ||
| { | ||
| @Override | ||
| public void serialize(EventMap map, JsonGenerator gen, SerializerProvider serializers) throws IOException | ||
| { | ||
| gen.writeStartObject(); | ||
| for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
| gen.writeObjectField(entry.getKey(), entry.getValue()); | ||
| } | ||
| gen.writeEndObject(); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,4 +290,5 @@ public void testNaN2() | |
| { | ||
| ServiceMetricEvent.builder().build("foo", 0 / 0f); | ||
| } | ||
|
|
||
| } | ||
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.