Skip to content

Remove abuse of new ObjectMapper.#8736

Merged
Jackie-Jiang merged 11 commits intoapache:masterfrom
gortiz:feature/79-reduce-new-ObjectMapper
May 25, 2022
Merged

Remove abuse of new ObjectMapper.#8736
Jackie-Jiang merged 11 commits intoapache:masterfrom
gortiz:feature/79-reduce-new-ObjectMapper

Conversation

@gortiz
Copy link
Contributor

@gortiz gortiz commented May 19, 2022

Remove abuse of new ObjectMapper. Fix issue #79.

Also some minor possible bugs detected by static code analyzers have been fixed

Also some minor possible bugs detected by static code analyzers have been fixed
Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! This makes our json config much easier to manage

@codecov-commenter
Copy link

codecov-commenter commented May 20, 2022

Codecov Report

Merging #8736 (defff28) into master (b4c4585) will decrease coverage by 40.72%.
The diff coverage is 8.69%.

❗ Current head defff28 differs from pull request most recent head 03562b7. Consider uploading reports for the commit 03562b7 to get more accurate results

@@              Coverage Diff              @@
##             master    #8736       +/-   ##
=============================================
- Coverage     69.67%   28.95%   -40.73%     
+ Complexity     4612       45     -4567     
=============================================
  Files          1730     1718       -12     
  Lines         90312    89964      -348     
  Branches      13421    13386       -35     
=============================================
- Hits          62928    26048    -36880     
- Misses        23015    61494    +38479     
+ Partials       4369     2422     -1947     
Flag Coverage Δ
integration1 26.80% <4.34%> (-0.06%) ⬇️
integration2 25.26% <8.69%> (+0.09%) ⬆️
unittests1 ?
unittests2 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...main/java/org/apache/pinot/client/BrokerCache.java 0.00% <0.00%> (ø)
...g/apache/pinot/client/PinotConnectionMetaData.java 0.00% <0.00%> (ø)
...n/java/org/apache/pinot/client/PinotResultSet.java 14.28% <0.00%> (-30.96%) ⬇️
...not/client/controller/response/SchemaResponse.java 0.00% <0.00%> (ø)
...inot/client/controller/response/TableResponse.java 0.00% <0.00%> (ø)
...org/apache/pinot/common/utils/PinotAppConfigs.java 0.00% <0.00%> (-64.71%) ⬇️
...t/controller/api/resources/TableDebugResource.java 0.00% <0.00%> (ø)
...inot/controller/recommender/RecommenderDriver.java 0.00% <ø> (-75.00%) ⬇️
.../pinot/controller/recommender/io/InputManager.java 0.00% <0.00%> (-93.04%) ⬇️
...re/common/evaluators/DefaultJsonPathEvaluator.java 17.78% <ø> (-14.43%) ⬇️
... and 1188 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4c4585...03562b7. Read the comment docs.

Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning them up! Let's try to keep one method per functionality in the JsonUtils

public static final ObjectWriter DEFAULT_WRITER = DEFAULT_MAPPER.writer();
public static final ObjectWriter DEFAULT_PRETTY_WRITER = DEFAULT_MAPPER.writerWithDefaultPrettyPrinter();
private static final TypeReference<HashMap<String, Object>> GENERIC_JSON_TYPE =
public static final TypeReference<HashMap<String, Object>> GENERIC_JSON_TYPE =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest not exposing this one. We may add a helper method stringToMap(String jsonString)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? I understand we should not expose the ObjectMapper because it may be mutated, but object is immutable and may be useful to have a single instance if someone has to do some advance usage of Jackson.

I mean, I would think that JsonUtils is used to avoid repetition and useless object creation, not to prevent devs to know about Jackson. The same we expose DEFAULT_WRITER, DEFAULT_PRETTY_WRITER and DEFAULT_READER, we can (and I would say should) expose GENERIC_JSON_TYPE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can definitely expose common type reference. My only concern about exposing this type is that we name the HashMap type as GENERIC_JSON which is a little bit confusing to me, but I guess it might be okay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm renaming it to MAP_TYPE_REFERENCE, which should be more clear.

Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please fix the compilation error in the tests

public static final ObjectWriter DEFAULT_WRITER = DEFAULT_MAPPER.writer();
public static final ObjectWriter DEFAULT_PRETTY_WRITER = DEFAULT_MAPPER.writerWithDefaultPrettyPrinter();
private static final TypeReference<HashMap<String, Object>> GENERIC_JSON_TYPE =
public static final TypeReference<HashMap<String, Object>> GENERIC_JSON_TYPE =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can definitely expose common type reference. My only concern about exposing this type is that we name the HashMap type as GENERIC_JSON which is a little bit confusing to me, but I guess it might be okay

return DEFAULT_READER.readTree(new ByteArrayInputStream(jsonBytes));
}

public static Map<String, Object> jsonNodeToObject(JsonNode jsonNode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to jsonNodeToMap, and remove the one using the MAPPER which has worse performance IIRC

Copy link
Contributor Author

@gortiz gortiz May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonNodeToMap already exists. Removing this method and changing its usages.

Ok, I've just understood what you indicated me to do

@Jackie-Jiang Jackie-Jiang merged commit 9beb630 into apache:master May 25, 2022
@gortiz gortiz deleted the feature/79-reduce-new-ObjectMapper branch June 15, 2022 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants