Skip to content
Closed
Show file tree
Hide file tree
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 Sep 15, 2017
7552a61
Supporting Nulls in Indexing layer
nishantmonu51 Sep 15, 2017
7f5fa83
Querying part 1 : Aggregators support for Nulls
nishantmonu51 Sep 15, 2017
40b6228
Querying part 2 : Filters + DimensionSpec + lookups
nishantmonu51 Sep 15, 2017
6fe82f6
Querying : Expressions + SQL layer + lookup
nishantmonu51 Sep 15, 2017
3c1e6af
Querying remaining changes + groupie
nishantmonu51 Sep 15, 2017
920139f
Enable test matrix in travis
nishantmonu51 Sep 15, 2017
6387e4b
Fixing tests
nishantmonu51 Sep 15, 2017
51a9db0
handle review comment
nishantmonu51 Sep 15, 2017
2d81e72
use default value for isNull in NullableAgg/combiners
nishantmonu51 Sep 15, 2017
65c3380
Handle review comments
nishantmonu51 Sep 18, 2017
22f2335
checkstyle errors fix
nishantmonu51 Sep 18, 2017
800e795
Fix Null Aggregate Serde and handle nulls in post aggs.
nishantmonu51 Sep 18, 2017
d4b0339
review comments
nishantmonu51 Sep 26, 2017
4004029
review comments - move numeric column null handling to single place
nishantmonu51 Oct 3, 2017
5efe3fb
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Oct 3, 2017
079debd
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Oct 3, 2017
c9300dd
review comments - remove version from numeric column serve v2
nishantmonu51 Oct 4, 2017
c46c6b6
Fix compilation and tests
nishantmonu51 Oct 5, 2017
2e3ba31
review comments
nishantmonu51 Oct 5, 2017
d102801
Add @Override annotation
nishantmonu51 Oct 6, 2017
400be55
more review comments and fix failing test
nishantmonu51 Oct 7, 2017
824c257
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Oct 7, 2017
c5fbbd5
Remove Guice Static Injection
nishantmonu51 Oct 10, 2017
b5a0880
Revert "Remove Guice Static Injection"
nishantmonu51 Oct 10, 2017
23ee4f1
Attempt to fix UT in travis runs
nishantmonu51 Oct 10, 2017
5334e80
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Oct 11, 2017
01ec864
Fix metric serialization missing bitmapSerdeFactory and QueryableInde…
nishantmonu51 Oct 13, 2017
7dc2efd
[BUG-90164] Addendum patch to fix serde of bitmap factory used. TESTS…
nishantmonu51 Oct 16, 2017
2af1f73
[BUG-90687] Fix null handling for extraction functions.
nishantmonu51 Oct 24, 2017
2848ffc
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Nov 6, 2017
ad9d591
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Nov 6, 2017
4e3231d
review comments
nishantmonu51 Nov 6, 2017
909a3d8
more review comments
nishantmonu51 Nov 6, 2017
1c8fae0
review comments
nishantmonu51 Nov 7, 2017
7a0a8a9
Expression support IS_NULL and IS_NOT_NULL
nishantmonu51 Nov 8, 2017
5e674a3
tests passing with null handling set to true
nishantmonu51 Nov 8, 2017
ad8c7b9
more review comments
nishantmonu51 Nov 8, 2017
35291a6
refactor method names
nishantmonu51 Nov 8, 2017
e87560b
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Nov 21, 2017
6b28b98
review comments
nishantmonu51 Nov 22, 2017
b4fced5
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Nov 22, 2017
eb24122
review comments
nishantmonu51 Dec 7, 2017
9362286
merge master and resolve conflicts
nishantmonu51 Dec 7, 2017
dc0d9dc
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Dec 7, 2017
41f6261
fix strict compilation
nishantmonu51 Dec 7, 2017
d36fcca
more review comments
nishantmonu51 Dec 10, 2017
cf4fa7e
Add order by clause to make test deterministic and pass in travis.
nishantmonu51 Dec 10, 2017
1fdb0a5
More review comments
nishantmonu51 Dec 17, 2017
b581a40
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Dec 17, 2017
9afc302
fix compilation after merge
nishantmonu51 Dec 17, 2017
df861ce
Add more info to debug travis failure
nishantmonu51 Dec 18, 2017
2470d3b
Review comments
nishantmonu51 Dec 20, 2017
87ac998
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Dec 20, 2017
a3001dc
fix unused imports
nishantmonu51 Dec 20, 2017
6a9b99f
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Dec 21, 2017
f965efe
fix compilation
nishantmonu51 Dec 27, 2017
90b6fcd
Merge remote-tracking branch 'remotes/upstream/master' into null-hand…
nishantmonu51 Dec 27, 2017
cff7d47
review comments
nishantmonu51 Dec 28, 2017
6bbb06f
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Jan 4, 2018
71fc458
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Jan 5, 2018
3d82a9f
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Jan 16, 2018
7603c8e
review comments
nishantmonu51 Jan 16, 2018
bad3ed5
review comment
nishantmonu51 Jan 16, 2018
72f90b4
review comment
nishantmonu51 Jan 16, 2018
246b515
Merge remote-tracking branch 'upstream/master' into null-handling-4
nishantmonu51 Jan 21, 2018
bc71553
fix failing tests
nishantmonu51 Jan 21, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,38 @@ matrix:
install: echo "MAVEN_OPTS='-Xmx3000m'" > ~/.mavenrc && mvn install -q -ff -DskipTests -B
before_script:
- unset _JAVA_OPTIONS

script: echo "MAVEN_OPTS='-Xmx512m'" > ~/.mavenrc && mvn test -B -Pparallel-test -Dmaven.fork.count=2 -pl '!processing,!server'

# processing module test with SQL Compatible Null Handling
- sudo: false
env:
- NAME="processing module test with SQL Compatible Null Handling"
install: echo "MAVEN_OPTS='-Xmx3000m'" > ~/.mavenrc && mvn install -q -ff -DskipTests -B
before_script:
- unset _JAVA_OPTIONS
script: echo "MAVEN_OPTS='-Xmx512m'" > ~/.mavenrc && mvn test -B -Pparallel-test -Dmaven.fork.count=2 -pl processing

# server module test with SQL Compatible Null Handling
- sudo: false
env:
- NAME="server module test with SQL Compatible Null Handling"
install: echo "MAVEN_OPTS='-Xmx3000m'" > ~/.mavenrc && mvn install -Ddruid.generic.useDefaultValueForNull=false -q -ff -DskipTests -B
before_script:
- unset _JAVA_OPTIONS
# Server module test is run without the parallel-test option because it's memory sensitive and often fails with that option.
script: echo "MAVEN_OPTS='-Xmx512m'" > ~/.mavenrc && mvn test -Ddruid.generic.useDefaultValueForNull=false -B -pl server

# other modules test with SQL Compatible Null Handling
- sudo: false
env:
- NAME="other modules test with SQL Compatible Null Handling"
install: echo "MAVEN_OPTS='-Xmx3000m'" > ~/.mavenrc && mvn install -q -ff -DskipTests -B
before_script:
- unset _JAVA_OPTIONS

script: echo "MAVEN_OPTS='-Xmx512m'" > ~/.mavenrc && mvn test -Ddruid.generic.useDefaultValueForNull=false -B -Pparallel-test -Dmaven.fork.count=2 -pl '!processing,!server'

# run integration tests
- sudo: required
services:
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/io/druid/data/input/MapBasedRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.druid.java.util.common.DateTimes;
import org.joda.time.DateTime;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -80,6 +81,7 @@ public List<String> getDimension(String dimension)
}

@Override
@Nullable
public Object getRaw(String dimension)
{
return event.get(dimension);
Expand Down
9 changes: 5 additions & 4 deletions api/src/main/java/io/druid/data/input/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.druid.guice.annotations.PublicApi;
import org.joda.time.DateTime;

import javax.annotation.Nullable;
import java.util.List;

/**
Expand Down Expand Up @@ -71,13 +72,13 @@ public interface Row extends Comparable<Row>
*
* @return the value of the provided column name
*/
@Nullable
Object getRaw(String dimension);

/**
* Returns the metric column value for the given column name. This method is different from {@link #getRaw} in two
* aspects:
* 1. If the column is absent in the row, numeric zero is returned, rather than null.
* 2. If the column has string value, an attempt is made to parse this value as a number.
* Returns the metric column value for the given column name. This method is different from {@link #getRaw}
* when column has string value, an attempt is made to parse this value as a number.
*/
@Nullable
Number getMetric(String metric);
}
6 changes: 4 additions & 2 deletions api/src/main/java/io/druid/data/input/Rows.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.druid.java.util.common.StringUtils;
import io.druid.java.util.common.parsers.ParseException;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -92,10 +93,11 @@ public static List<String> objectToStrings(final Object inputValue)
* @throws NullPointerException if the string is null
* @throws ParseException if the column cannot be converted to a number
*/
public static Number objectToNumber(final String name, final Object inputValue)
@Nullable
public static Number objectToNumber(final String name, @Nullable final Object inputValue)
{
if (inputValue == null) {
return Rows.LONG_ZERO;
return null;
}

if (inputValue instanceof Number) {
Expand Down
3 changes: 2 additions & 1 deletion api/src/test/java/io/druid/data/input/MapBasedRowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public void testGetLongMetricFromString()
.put("k6", "+9223372036854775802")
.build()
);

Assert.assertEquals(-1.2, row.getMetric("k0"));
Assert.assertEquals(1.23, row.getMetric("k1"));
Assert.assertEquals(1.8, row.getMetric("k2"));
Assert.assertEquals(100000.0, row.getMetric("k3"));
Assert.assertEquals(9223372036854775806L, row.getMetric("k4"));
Assert.assertEquals(-9223372036854775807L, row.getMetric("k5"));
Assert.assertEquals(9223372036854775802L, row.getMetric("k6"));
Assert.assertEquals(null, row.getMetric("k9"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,9 @@ public Filter toFilter()
if (extractionFn == null) {
return new NoBitmapSelectorFilter(dimension, value);
} else {
//CHECKSTYLE.OFF: Regexp
final String valueOrNull = Strings.emptyToNull(value);

//CHECKSTYLE.ON: Regexp
final DruidPredicateFactory predicateFactory = new DruidPredicateFactory()
{
@Override
Expand Down
10 changes: 10 additions & 0 deletions codestyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,15 @@
<property name="illegalPattern" value="true"/>
<property name="message" value="Use io.druid.java.util.common.logger.Logger instead"/>
</module>
<module name="Regexp">
<property name="format" value="Strings.emptyToNull"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Use io.druid.common.config.NullHandling.emptyToNullIfNeeded instead"/>
</module>
<module name="Regexp">
<property name="format" value="Strings.nullToEmpty"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Use io.druid.common.config.NullHandling.nullToEmptyIfNeeded instead"/>
</module>
</module>
</module>
3 changes: 2 additions & 1 deletion common/src/main/antlr4/io/druid/math/expr/antlr/Expr.g4
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
grammar Expr;

expr : ('-'|'!') expr # unaryOpExpr
expr : 'null' # null
| ('-'|'!') expr # unaryOpExpr
|<assoc=right> expr '^' expr # powOpExpr
| expr ('*'|'/'|'%') expr # mulDivModuloExpr
| expr ('+'|'-') expr # addSubExpr
Expand Down
106 changes: 106 additions & 0 deletions common/src/main/java/io/druid/common/config/NullHandling.java
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;
}

}
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;
}
}
1 change: 0 additions & 1 deletion common/src/main/java/io/druid/io/Channels.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

public final class Channels
{

public static void writeFully(WritableByteChannel channel, ByteBuffer src) throws IOException
{
while (src.remaining() > 0) {
Expand Down
15 changes: 12 additions & 3 deletions common/src/main/java/io/druid/math/expr/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
package io.druid.math.expr;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.math.LongMath;
import com.google.common.primitives.Ints;
import io.druid.common.config.NullHandling;
import io.druid.java.util.common.IAE;
import io.druid.java.util.common.ISE;
import io.druid.java.util.common.guava.Comparators;
Expand Down Expand Up @@ -124,7 +124,7 @@ class StringExpr extends ConstantExpr

public StringExpr(String value)
{
this.value = Strings.emptyToNull(value);
this.value = NullHandling.emptyToNullIfNeeded(value);
Copy link
Copy Markdown
Member

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() to NullHandling.emptyToNullIfNeeded(), or uses the "old" method in some newly written code?

Copy link
Copy Markdown
Member Author

@nishantmonu51 nishantmonu51 Jan 16, 2018

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.

}

@Nullable
Expand Down Expand Up @@ -362,6 +362,13 @@ public ExprEval eval(ObjectBinding bindings)
{
ExprEval leftVal = left.eval(bindings);
ExprEval rightVal = right.eval(bindings);

// Result of any Binary expressions is null if any of the argument is null.
// e.g "select null * 2 as c;" or "select null + 1 as c;" will return null as per Standard SQL spec.
if (!NullHandling.useDefaultValuesForNull() && (leftVal.isNull() || rightVal.isNull())) {
return ExprEval.of(null);
}

if (leftVal.type() == ExprType.STRING && rightVal.type() == ExprType.STRING) {
return evalString(leftVal.asString(), rightVal.asString());
} else if (leftVal.type() == ExprType.LONG && rightVal.type() == ExprType.LONG) {
Expand Down Expand Up @@ -491,7 +498,8 @@ class BinPlusExpr extends BinaryEvalOpExprBase
@Override
protected ExprEval evalString(@Nullable String left, @Nullable String right)
{
return ExprEval.of(Strings.nullToEmpty(left) + Strings.nullToEmpty(right));
return ExprEval.of(NullHandling.nullToEmptyIfNeeded(left)
+ NullHandling.nullToEmptyIfNeeded(right));
}

@Override
Expand Down Expand Up @@ -698,3 +706,4 @@ public ExprEval eval(ObjectBinding bindings)
return leftVal.asBoolean() ? leftVal : right.eval(bindings);
}
}

Loading