bug fix for merging with empty strings

This commit is contained in:
Fangjin Yang 2012-10-31 10:28:24 -07:00
parent d7f85cfbc4
commit d0f66c1fb3
4 changed files with 85 additions and 3 deletions

View File

@ -0,0 +1,55 @@
package com.metamx.druid;
import com.metamx.common.lifecycle.Lifecycle;
import com.metamx.common.lifecycle.LifecycleStart;
import com.metamx.common.lifecycle.LifecycleStop;
import com.metamx.common.logger.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.skife.config.ConfigurationObjectFactory;
import java.util.Properties;
/**
*/
public abstract class DruidNode
{
private static final Logger log = new Logger(DruidNode.class);
private final ObjectMapper jsonMapper;
private final Lifecycle lifecycle;
private final Properties props;
private final ConfigurationObjectFactory configFactory;
private boolean initialized = false;
public DruidNode(
ObjectMapper jsonMapper,
Lifecycle lifecycle,
Properties props,
ConfigurationObjectFactory configFactory
)
{
this.jsonMapper = jsonMapper;
this.lifecycle = lifecycle;
this.props = props;
this.configFactory = configFactory;
}
public abstract void init();
@LifecycleStart
public synchronized void start() throws Exception
{
if (!initialized) {
init();
}
lifecycle.start();
}
@LifecycleStop
public synchronized void stop()
{
lifecycle.stop();
}
}

View File

@ -36,9 +36,9 @@ import java.util.Iterator;
/**
* A generic, flat storage mechanism. Use static methods fromArray() or fromIterable() to construct. If input
* is sorted, supports binary search index lookups. If input is not sorted, only supports array-like index lookups.
*
* <p/>
* V1 Storage Format:
*
* <p/>
* byte 1: version (0x1)
* byte 2 == 0x1 => allowReverseLookup
* bytes 3-6 => numBytesUsed
@ -253,6 +253,9 @@ public class GenericIndexed<T> implements Indexed<T>
@Override
public byte[] toBytes(String val)
{
if (val == null) {
return new byte[]{};
}
return val.getBytes(Charsets.UTF_8);
}

View File

@ -70,6 +70,7 @@ public abstract class BaseStorageAdapter implements StorageAdapter
Iterable<String> dims = getDimValueLookup(dimension);
if (dims != null) {
for (String dimVal : dims) {
dimVal = dimVal == null ? "" : dimVal;
if (searchQuerySpec.accept(dimVal)) {
if (filterOffset != null) {
Offset lhs = new ConciseOffset(getInvertedIndex(dimension, dimVal));

View File

@ -469,12 +469,34 @@ public class IndexMerger
}
Iterable<String> dimensionValues = CombiningIterable.createSplatted(
dimValueLookups,
Iterables.transform(
dimValueLookups,
new Function<Indexed<String>, Iterable<String>>()
{
@Override
public Iterable<String> apply(@Nullable Indexed<String> indexed)
{
return Iterables.transform(
indexed,
new Function<String, String>()
{
@Override
public String apply(@Nullable String input)
{
return (input == null) ? "" : input;
}
}
);
}
}
)
,
Ordering.<String>natural().nullsFirst()
);
int count = 0;
for (String value : dimensionValues) {
value = value == null ? "" : value;
writer.write(value);
for (int i = 0; i < indexes.size(); i++) {
@ -855,6 +877,7 @@ public class IndexMerger
++currIndex;
if (currIndex == dimSet.size()) {
lastVal = value;
return;
}
currValue = dimSet.get(currIndex);
}