mirror of https://github.com/apache/druid.git
code review
This commit is contained in:
parent
a14f3807d3
commit
61fe33ebf7
|
@ -142,12 +142,12 @@ public class InDimFilter extends AbstractOptimizableDimFilter implements Filter
|
||||||
|
|
||||||
// The values set can be huge. Try to avoid copying the set if possible.
|
// The values set can be huge. Try to avoid copying the set if possible.
|
||||||
// Note that we may still need to copy values to a list for caching. See getCacheKey().
|
// Note that we may still need to copy values to a list for caching. See getCacheKey().
|
||||||
if (NullHandling.sqlCompatible() || !values.remove("")) {
|
if (!NullHandling.sqlCompatible() && values.remove("")) {
|
||||||
this.values = values;
|
// In Non sql compatible mode, empty strings should be converted to nulls for the filter.
|
||||||
} else {
|
// In sql compatible mode, empty strings and nulls should be treated differently
|
||||||
values.add(null);
|
values.add(null);
|
||||||
this.values = values;
|
|
||||||
}
|
}
|
||||||
|
this.values = values;
|
||||||
|
|
||||||
this.dimension = Preconditions.checkNotNull(dimension, "dimension cannot be null");
|
this.dimension = Preconditions.checkNotNull(dimension, "dimension cannot be null");
|
||||||
this.extractionFn = extractionFn;
|
this.extractionFn = extractionFn;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
package org.apache.druid.segment.join.lookup;
|
package org.apache.druid.segment.join.lookup;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.Sets;
|
||||||
import org.apache.druid.java.util.common.io.Closer;
|
import org.apache.druid.java.util.common.io.Closer;
|
||||||
import org.apache.druid.query.lookup.LookupExtractor;
|
import org.apache.druid.query.lookup.LookupExtractor;
|
||||||
import org.apache.druid.segment.ColumnSelectorFactory;
|
import org.apache.druid.segment.ColumnSelectorFactory;
|
||||||
|
@ -33,7 +33,6 @@ import org.apache.druid.segment.join.Joinable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -107,10 +106,10 @@ public class LookupJoinable implements Joinable
|
||||||
Set<String> correlatedValues;
|
Set<String> correlatedValues;
|
||||||
if (LookupColumnSelectorFactory.KEY_COLUMN.equals(searchColumnName)) {
|
if (LookupColumnSelectorFactory.KEY_COLUMN.equals(searchColumnName)) {
|
||||||
if (LookupColumnSelectorFactory.KEY_COLUMN.equals(retrievalColumnName)) {
|
if (LookupColumnSelectorFactory.KEY_COLUMN.equals(retrievalColumnName)) {
|
||||||
correlatedValues = ImmutableSet.of(searchColumnValue);
|
correlatedValues = Sets.newHashSet(searchColumnValue);
|
||||||
} else {
|
} else {
|
||||||
// This should not happen in practice because the column to be joined on must be a key.
|
// This should not happen in practice because the column to be joined on must be a key.
|
||||||
correlatedValues = Collections.singleton(extractor.apply(searchColumnValue));
|
correlatedValues = Sets.newHashSet(extractor.apply(searchColumnValue));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!allowNonKeyColumnSearch) {
|
if (!allowNonKeyColumnSearch) {
|
||||||
|
@ -118,11 +117,11 @@ public class LookupJoinable implements Joinable
|
||||||
}
|
}
|
||||||
if (LookupColumnSelectorFactory.VALUE_COLUMN.equals(retrievalColumnName)) {
|
if (LookupColumnSelectorFactory.VALUE_COLUMN.equals(retrievalColumnName)) {
|
||||||
// This should not happen in practice because the column to be joined on must be a key.
|
// This should not happen in practice because the column to be joined on must be a key.
|
||||||
correlatedValues = ImmutableSet.of(searchColumnValue);
|
correlatedValues = Sets.newHashSet(searchColumnValue);
|
||||||
} else {
|
} else {
|
||||||
// Lookup extractor unapply only provides a list of strings, so we can't respect
|
// Lookup extractor unapply only provides a list of strings, so we can't respect
|
||||||
// maxCorrelationSetSize easily. This should be handled eventually.
|
// maxCorrelationSetSize easily. This should be handled eventually.
|
||||||
correlatedValues = ImmutableSet.copyOf(extractor.unapply(searchColumnValue));
|
correlatedValues = Sets.newHashSet(extractor.unapply(searchColumnValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional.of(correlatedValues);
|
return Optional.of(correlatedValues);
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.apache.druid.query.filter;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import org.apache.druid.common.config.NullHandling;
|
import org.apache.druid.common.config.NullHandling;
|
||||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||||
|
@ -59,26 +58,37 @@ public class InDimFilterTest extends InitializedNullHandlingTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetValuesWithValuesSetOfNonEmptyStringsUseTheGivenSet()
|
public void testInitWithoutEmptyStringsShouldUseValuesAsIs()
|
||||||
{
|
{
|
||||||
final Set<String> values = ImmutableSet.of("v1", "v2", "v3");
|
Set<String> values = Sets.newHashSet("good", "bad", null);
|
||||||
final InDimFilter filter = new InDimFilter("dim", values, null, null);
|
final InDimFilter inDimFilter = new InDimFilter("dimTest", values, null);
|
||||||
Assert.assertSame(values, filter.getValues());
|
Assert.assertSame(values, inDimFilter.getValues());
|
||||||
|
Assert.assertEquals(3, values.size());
|
||||||
|
Assert.assertEquals(Sets.newHashSet("good", "bad", null), inDimFilter.getValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetValuesWithValuesSetIncludingEmptyString()
|
public void testInitWithEmptyStringsShouldUseValuesAndReplaceWithNullInNonSqlCompatibleMode()
|
||||||
{
|
{
|
||||||
final Set<String> values = Sets.newHashSet("v1", "", "v3");
|
Set<String> values = Sets.newHashSet("good", "bad", "");
|
||||||
final InDimFilter filter = new InDimFilter("dim", values, null, null);
|
final InDimFilter inDimFilter = new InDimFilter("dimTest", values, null);
|
||||||
if (NullHandling.replaceWithDefault()) {
|
Assert.assertSame(values, inDimFilter.getValues());
|
||||||
Assert.assertNotSame(values, filter.getValues());
|
Assert.assertEquals(3, values.size());
|
||||||
Assert.assertEquals(Sets.newHashSet("v1", null, "v3"), filter.getValues());
|
if (NullHandling.sqlCompatible()) {
|
||||||
|
Assert.assertEquals(Sets.newHashSet("good", "bad", ""), inDimFilter.getValues());
|
||||||
} else {
|
} else {
|
||||||
Assert.assertSame(values, filter.getValues());
|
Assert.assertEquals(Sets.newHashSet("good", "bad", null), inDimFilter.getValues());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetValuesWithValuesSetOfNonEmptyStringsUseTheGivenSet()
|
||||||
|
{
|
||||||
|
final Set<String> values = Sets.newHashSet("v1", "v2", "v3");
|
||||||
|
final InDimFilter filter = new InDimFilter("dim", values, null, null);
|
||||||
|
Assert.assertSame(values, filter.getValues());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheKeyReturningSameKeyForValuesOfDifferentOrders()
|
public void testGetCacheKeyReturningSameKeyForValuesOfDifferentOrders()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue