-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Make NULL handling in Druid more compatible to SQL standard #4754
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
Closed
Closed
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
aae8d98
Support Nulls in Storage Layer
nishantmonu51 7552a61
Supporting Nulls in Indexing layer
nishantmonu51 7f5fa83
Querying part 1 : Aggregators support for Nulls
nishantmonu51 40b6228
Querying part 2 : Filters + DimensionSpec + lookups
nishantmonu51 6fe82f6
Querying : Expressions + SQL layer + lookup
nishantmonu51 3c1e6af
Querying remaining changes + groupie
nishantmonu51 920139f
Enable test matrix in travis
nishantmonu51 6387e4b
Fixing tests
nishantmonu51 51a9db0
handle review comment
nishantmonu51 2d81e72
use default value for isNull in NullableAgg/combiners
nishantmonu51 65c3380
Handle review comments
nishantmonu51 22f2335
checkstyle errors fix
nishantmonu51 800e795
Fix Null Aggregate Serde and handle nulls in post aggs.
nishantmonu51 d4b0339
review comments
nishantmonu51 4004029
review comments - move numeric column null handling to single place
nishantmonu51 5efe3fb
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 079debd
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 c9300dd
review comments - remove version from numeric column serve v2
nishantmonu51 c46c6b6
Fix compilation and tests
nishantmonu51 2e3ba31
review comments
nishantmonu51 d102801
Add @Override annotation
nishantmonu51 400be55
more review comments and fix failing test
nishantmonu51 824c257
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 c5fbbd5
Remove Guice Static Injection
nishantmonu51 b5a0880
Revert "Remove Guice Static Injection"
nishantmonu51 23ee4f1
Attempt to fix UT in travis runs
nishantmonu51 5334e80
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 01ec864
Fix metric serialization missing bitmapSerdeFactory and QueryableInde…
nishantmonu51 7dc2efd
[BUG-90164] Addendum patch to fix serde of bitmap factory used. TESTS…
nishantmonu51 2af1f73
[BUG-90687] Fix null handling for extraction functions.
nishantmonu51 2848ffc
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 ad9d591
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 4e3231d
review comments
nishantmonu51 909a3d8
more review comments
nishantmonu51 1c8fae0
review comments
nishantmonu51 7a0a8a9
Expression support IS_NULL and IS_NOT_NULL
nishantmonu51 5e674a3
tests passing with null handling set to true
nishantmonu51 ad8c7b9
more review comments
nishantmonu51 35291a6
refactor method names
nishantmonu51 e87560b
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 6b28b98
review comments
nishantmonu51 b4fced5
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 eb24122
review comments
nishantmonu51 9362286
merge master and resolve conflicts
nishantmonu51 dc0d9dc
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 41f6261
fix strict compilation
nishantmonu51 d36fcca
more review comments
nishantmonu51 cf4fa7e
Add order by clause to make test deterministic and pass in travis.
nishantmonu51 1fdb0a5
More review comments
nishantmonu51 b581a40
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 9afc302
fix compilation after merge
nishantmonu51 df861ce
Add more info to debug travis failure
nishantmonu51 2470d3b
Review comments
nishantmonu51 87ac998
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 a3001dc
fix unused imports
nishantmonu51 6a9b99f
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 f965efe
fix compilation
nishantmonu51 90b6fcd
Merge remote-tracking branch 'remotes/upstream/master' into null-hand…
nishantmonu51 cff7d47
review comments
nishantmonu51 6bbb06f
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 71fc458
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 3d82a9f
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 7603c8e
review comments
nishantmonu51 bad3ed5
review comment
nishantmonu51 72f90b4
review comment
nishantmonu51 246b515
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 bc71553
fix failing tests
nishantmonu51 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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
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
106 changes: 106 additions & 0 deletions
106
common/src/main/java/io/druid/common/config/NullHandling.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,106 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets 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 io.druid.common.config; | ||
|
|
||
| import com.google.common.base.Strings; | ||
| import com.google.inject.Inject; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Helper class for NullHandling. This class is used to switch between SQL compatible Null Handling behavior | ||
| * introduced as part of {@link https://github.com/druid-io/druid/issues/4349} and the old druid behavior | ||
| * where null values are replaced with default values e.g Null Strings are replaced with empty values. | ||
| */ | ||
| public class NullHandling | ||
| { | ||
| private static String NULL_HANDLING_CONFIG_STRING = "druid.generic.useDefaultValueForNull"; | ||
|
|
||
| /** | ||
| * use these values to ensure that {@link NullHandling#defaultDoubleValue()}, | ||
| * {@link NullHandling#defaultFloatValue()} , {@link NullHandling#defaultFloatValue()} | ||
| * return the same boxed object when returning a constant zero | ||
| */ | ||
| public static final Double ZERO_DOUBLE = 0.0d; | ||
| public static final Float ZERO_FLOAT = 0.0f; | ||
| public static final Long ZERO_LONG = 0L; | ||
|
|
||
| /** | ||
| * INSTANCE is injected using static injection to avoid adding JacksonInject annotations all over the code. | ||
| * See {@link io.druid.guice.NullHandlingModule} for details. | ||
| * It does not take effect in all unit tests since we don't use Guice Injection. | ||
| * For tests default system property is supposed to be used only in tests | ||
| */ | ||
| @Inject | ||
| private static NullValueHandlingConfig INSTANCE = new NullValueHandlingConfig( | ||
| Boolean.valueOf(System.getProperty(NULL_HANDLING_CONFIG_STRING, "true")) | ||
| ); | ||
|
|
||
| public static boolean useDefaultValuesForNull() | ||
| { | ||
| return INSTANCE.isUseDefaultValuesForNull(); | ||
| } | ||
|
|
||
| @Nullable | ||
| public static String nullToEmptyIfNeeded(@Nullable String value) | ||
| { | ||
| //CHECKSTYLE.OFF: Regexp | ||
| return useDefaultValuesForNull() ? Strings.nullToEmpty(value) : value; | ||
| //CHECKSTYLE.ON: Regexp | ||
| } | ||
|
|
||
| @Nullable | ||
| public static String emptyToNullIfNeeded(@Nullable String value) | ||
| { | ||
| //CHECKSTYLE.OFF: Regexp | ||
| return useDefaultValuesForNull() ? Strings.emptyToNull(value) : value; | ||
| //CHECKSTYLE.ON: Regexp | ||
| } | ||
|
|
||
| @Nullable | ||
| public static String defaultStringValue() | ||
| { | ||
| return useDefaultValuesForNull() ? "" : null; | ||
| } | ||
|
|
||
| @Nullable | ||
| public static Long defaultLongValue() | ||
| { | ||
| return useDefaultValuesForNull() ? ZERO_LONG : null; | ||
| } | ||
|
|
||
| @Nullable | ||
| public static Float defaultFloatValue() | ||
| { | ||
| return useDefaultValuesForNull() ? ZERO_FLOAT : null; | ||
| } | ||
|
|
||
| @Nullable | ||
| public static Double defaultDoubleValue() | ||
| { | ||
| return useDefaultValuesForNull() ? ZERO_DOUBLE : null; | ||
| } | ||
|
|
||
| public static boolean isNullOrEquivalent(@Nullable String value) | ||
| { | ||
| return INSTANCE.isUseDefaultValuesForNull() ? Strings.isNullOrEmpty(value) : value == null; | ||
| } | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
common/src/main/java/io/druid/common/config/NullValueHandlingConfig.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,43 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets 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 io.druid.common.config; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| public class NullValueHandlingConfig | ||
| { | ||
|
|
||
| @JsonProperty("useDefaultValueForNull") | ||
| private final boolean useDefaultValuesForNull; | ||
|
|
||
| @JsonCreator | ||
| public NullValueHandlingConfig(@JsonProperty("useDefaultValueForNull") Boolean useDefaultValuesForNull) | ||
| { | ||
| this.useDefaultValuesForNull = useDefaultValuesForNull == null | ||
| ? true | ||
| : useDefaultValuesForNull; | ||
| } | ||
|
|
||
| public boolean isUseDefaultValuesForNull() | ||
| { | ||
| return useDefaultValuesForNull; | ||
| } | ||
| } |
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.
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.
Is there any way to prevent the situation when somebody forgets to update
Strings.emptyToNull()toNullHandling.emptyToNullIfNeeded(), or uses the "old" method in some newly written code?Uh oh!
There was an error while loading. Please reload this page.
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.
done. added a checkstyle check.