Merge pull request #841 from metamx/distinguish-legacy-vs-default-bitmap

Distinguish between default and legacy bitmaps
This commit is contained in:
Fangjin Yang 2014-11-11 19:37:35 -07:00
commit 4903f36639
4 changed files with 58 additions and 9 deletions

View File

@ -59,10 +59,10 @@ import io.druid.segment.column.ColumnConfig;
import io.druid.segment.column.ColumnDescriptor; import io.druid.segment.column.ColumnDescriptor;
import io.druid.segment.column.ValueType; import io.druid.segment.column.ValueType;
import io.druid.segment.data.ArrayIndexed; import io.druid.segment.data.ArrayIndexed;
import io.druid.segment.data.BitmapSerde;
import io.druid.segment.data.BitmapSerdeFactory; import io.druid.segment.data.BitmapSerdeFactory;
import io.druid.segment.data.ByteBufferSerializer; import io.druid.segment.data.ByteBufferSerializer;
import io.druid.segment.data.CompressedLongsIndexedSupplier; import io.druid.segment.data.CompressedLongsIndexedSupplier;
import io.druid.segment.data.ConciseBitmapSerdeFactory;
import io.druid.segment.data.GenericIndexed; import io.druid.segment.data.GenericIndexed;
import io.druid.segment.data.IndexedIterable; import io.druid.segment.data.IndexedIterable;
import io.druid.segment.data.IndexedRTree; import io.druid.segment.data.IndexedRTree;
@ -257,7 +257,7 @@ public class IndexIO
indexBuffer, GenericIndexed.stringStrategy indexBuffer, GenericIndexed.stringStrategy
); );
final Interval dataInterval = new Interval(serializerUtils.readString(indexBuffer)); final Interval dataInterval = new Interval(serializerUtils.readString(indexBuffer));
final BitmapSerdeFactory conciseBitmapSerdeFactory = new ConciseBitmapSerdeFactory(); final BitmapSerdeFactory bitmapSerdeFactory = BitmapSerde.createLegacyFactory();
CompressedLongsIndexedSupplier timestamps = CompressedLongsIndexedSupplier.fromByteBuffer( CompressedLongsIndexedSupplier timestamps = CompressedLongsIndexedSupplier.fromByteBuffer(
smooshedFiles.mapFile(makeTimeFile(inDir, BYTE_ORDER).getName()), BYTE_ORDER smooshedFiles.mapFile(makeTimeFile(inDir, BYTE_ORDER).getName()), BYTE_ORDER
@ -296,7 +296,7 @@ public class IndexIO
for (int i = 0; i < availableDimensions.size(); ++i) { for (int i = 0; i < availableDimensions.size(); ++i) {
bitmaps.put( bitmaps.put(
serializerUtils.readString(invertedBuffer), serializerUtils.readString(invertedBuffer),
GenericIndexed.read(invertedBuffer, conciseBitmapSerdeFactory.getObjectStrategy()) GenericIndexed.read(invertedBuffer, bitmapSerdeFactory.getObjectStrategy())
); );
} }
@ -307,7 +307,7 @@ public class IndexIO
serializerUtils.readString(spatialBuffer), serializerUtils.readString(spatialBuffer),
ByteBufferSerializer.read( ByteBufferSerializer.read(
spatialBuffer, spatialBuffer,
new IndexedRTree.ImmutableRTreeObjectStrategy(conciseBitmapSerdeFactory.getBitmapFactory()) new IndexedRTree.ImmutableRTreeObjectStrategy(bitmapSerdeFactory.getBitmapFactory())
) )
); );
} }
@ -772,7 +772,7 @@ public class IndexIO
if (indexBuffer.hasRemaining()) { if (indexBuffer.hasRemaining()) {
segmentBitmapSerdeFactory = mapper.readValue(serializerUtils.readString(indexBuffer), BitmapSerdeFactory.class); segmentBitmapSerdeFactory = mapper.readValue(serializerUtils.readString(indexBuffer), BitmapSerdeFactory.class);
} else { } else {
segmentBitmapSerdeFactory = new ConciseBitmapSerdeFactory(); segmentBitmapSerdeFactory = BitmapSerde.createLegacyFactory();
} }
Map<String, Column> columns = Maps.newHashMap(); Map<String, Column> columns = Maps.newHashMap();

View File

@ -0,0 +1,50 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2014 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.segment.data;
import com.metamx.common.ISE;
public class BitmapSerde
{
// default bitmap indices in Druid <= 0.6.x
public static final Class<ConciseBitmapSerdeFactory> LEGACY_BITMAP_FACTORY = ConciseBitmapSerdeFactory.class;
// default bitmap indices for Druid >= 0.7.x
public static final Class<ConciseBitmapSerdeFactory> DEFAULT_BITMAP_FACTORY = ConciseBitmapSerdeFactory.class;
public static BitmapSerdeFactory createDefaultFactory()
{
try {
return DEFAULT_BITMAP_FACTORY.newInstance();
} catch(InstantiationException | IllegalAccessException e) {
// should never happen
throw new ISE(e, "Unable to instatiate BitmapSerdeFactory");
}
}
public static BitmapSerdeFactory createLegacyFactory()
{
try {
return LEGACY_BITMAP_FACTORY.newInstance();
} catch(InstantiationException | IllegalAccessException e) {
// should never happen
throw new ISE(e, "Unable to instatiate BitmapSerdeFactory");
}
}
}

View File

@ -26,12 +26,11 @@ import com.metamx.collections.bitmap.ImmutableBitmap;
/** /**
*/ */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = ConciseBitmapSerdeFactory.class) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = BitmapSerde.DEFAULT_BITMAP_FACTORY)
@JsonSubTypes(value = { @JsonSubTypes(value = {
@JsonSubTypes.Type(name = "concise", value = ConciseBitmapSerdeFactory.class), @JsonSubTypes.Type(name = "concise", value = ConciseBitmapSerdeFactory.class),
@JsonSubTypes.Type(name = "roaring", value = RoaringBitmapSerdeFactory.class) @JsonSubTypes.Type(name = "roaring", value = RoaringBitmapSerdeFactory.class)
}) })
public interface BitmapSerdeFactory public interface BitmapSerdeFactory
{ {
public ObjectStrategy<ImmutableBitmap> getObjectStrategy(); public ObjectStrategy<ImmutableBitmap> getObjectStrategy();

View File

@ -28,9 +28,9 @@ import com.metamx.common.IAE;
import io.druid.segment.column.ColumnBuilder; import io.druid.segment.column.ColumnBuilder;
import io.druid.segment.column.ColumnConfig; import io.druid.segment.column.ColumnConfig;
import io.druid.segment.column.ValueType; import io.druid.segment.column.ValueType;
import io.druid.segment.data.BitmapSerde;
import io.druid.segment.data.BitmapSerdeFactory; import io.druid.segment.data.BitmapSerdeFactory;
import io.druid.segment.data.ByteBufferSerializer; import io.druid.segment.data.ByteBufferSerializer;
import io.druid.segment.data.ConciseBitmapSerdeFactory;
import io.druid.segment.data.GenericIndexed; import io.druid.segment.data.GenericIndexed;
import io.druid.segment.data.IndexedRTree; import io.druid.segment.data.IndexedRTree;
import io.druid.segment.data.VSizeIndexed; import io.druid.segment.data.VSizeIndexed;
@ -97,7 +97,7 @@ public class DictionaryEncodedColumnPartSerde implements ColumnPartSerde
{ {
this.isSingleValued = isSingleValued; this.isSingleValued = isSingleValued;
this.bitmapSerdeFactory = bitmapSerdeFactory == null this.bitmapSerdeFactory = bitmapSerdeFactory == null
? new ConciseBitmapSerdeFactory() ? BitmapSerde.createLegacyFactory()
: bitmapSerdeFactory; : bitmapSerdeFactory;
this.dictionary = null; this.dictionary = null;