Skip to content

fix sql compatible null handling config work with runtime.properties#8876

Merged
clintropolis merged 12 commits intoapache:masterfrom
clintropolis:null-handling-config-fix
Nov 20, 2019
Merged

fix sql compatible null handling config work with runtime.properties#8876
clintropolis merged 12 commits intoapache:masterfrom
clintropolis:null-handling-config-fix

Conversation

@clintropolis
Copy link
Copy Markdown
Member

@clintropolis clintropolis commented Nov 15, 2019

Description

This terrible PR modifies NullHandling to no longer have a default value since it appears in practice to overwrite the instance injected by NullHandlingModule through requestStaticInjection, causing the druid.generic.useDefaultValueForNull config to not function when it is in a runtime.properties or similar file, and only works when specified as an argument. The injected instance was in fact being created, it was just being overwritten immediately by the default value that was being set for it in NullHandling.

Since there is no longer a default value, I have added a method that is just awful, NullHandling.initializeForTests(), which any tests or benchmarks or anything that does not wire up injection must use to avoid null pointer exceptions. This is bad, but seemed better than any alternative I could come up with, because NullHandling.replaceWithDefault is called in a lot of 'hot' places, so introducing an if statement or method call overhead from using a Supplier or something like that didn't seem worth risking the overhead for the sake of easier to write tests.


This PR has:

  • been self-reviewed.
  • been tested in a test Druid cluster.

Key changed/added classes in this PR
  • NullHandling
  • NullValueHandlingConfig

@gianm
Copy link
Copy Markdown
Contributor

gianm commented Nov 19, 2019

@clintropolis The Travis failure looks legit, e.g.,

[ERROR] org.apache.druid.server.lookup.jdbc.JdbcDataFetcherTest$FetchTest.testFetch(org.apache.druid.server.lookup.jdbc.JdbcDataFetcherTest$FetchTest)

[ERROR]   Run 1: JdbcDataFetcherTest$FetchTest.testFetch:111->assertMapLookup:176 » NullPointer

[ERROR]   Run 2: JdbcDataFetcherTest$FetchTest.testFetch:111->assertMapLookup:176 » NullPointer

[ERROR]   Run 3: JdbcDataFetcherTest$FetchTest.testFetch:111->assertMapLookup:176 » NullPointer

[ERROR]   Run 4: JdbcDataFetcherTest$FetchTest.testFetch:111->assertMapLookup:176 » NullPointer

{
this.useDefaultValuesForNull = useDefaultValuesForNull == null
? true
? Boolean.valueOf(System.getProperty(NULL_HANDLING_CONFIG_STRING, "true"))
Copy link
Copy Markdown
Contributor

@gianm gianm Nov 19, 2019

Choose a reason for hiding this comment

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

I don't think this System.getProperty is necessary. The normal Druid injectorator stuff (what is being activated by the JsonConfigProvider.bind line in NullHandlingModule) handles reading from system properties too.

private static NullValueHandlingConfig INSTANCE = new NullValueHandlingConfig(
Boolean.valueOf(System.getProperty(NULL_HANDLING_CONFIG_STRING, "true"))
);
private static NullValueHandlingConfig INSTANCE;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest making a private getInstance() method, using that everywhere, and having that method throw a nice exception that asks you to either call NullHandling.initializeForTests() or include NullHandlingModule. That way, future benchmark and test writers don't get confused by null pointer exceptions.

@clintropolis
Copy link
Copy Markdown
Member Author

closing in favor of #8908

Copy link
Copy Markdown
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

👍 after CI

@clintropolis clintropolis merged commit 3fcaa1a into apache:master Nov 20, 2019
@clintropolis
Copy link
Copy Markdown
Member Author

This PR also fixed up a non-conflicting merge issue between #8779 and #8871

@clintropolis clintropolis deleted the null-handling-config-fix branch November 20, 2019 11:57
jon-wei pushed a commit to jon-wei/druid that referenced this pull request Nov 26, 2019
…pache#8876)

* fix sql compatible null handling config work with runtime.properties

* fix npe

* fix tests

* add friendly error

* comment, and friendlier still

* fix compile

* fix from merges
@jon-wei jon-wei added this to the 0.17.0 milestone Dec 17, 2019
@a2l007 a2l007 mentioned this pull request Jan 2, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants