Skip to content

Commit

Permalink
Merge pull request apache#841 from metamx/distinguish-legacy-vs-defau…
Browse files Browse the repository at this point in the history
…lt-bitmap

Distinguish between default and legacy bitmaps
  • Loading branch information
fjy committed Nov 12, 2014
2 parents bc5c56e + b580269 commit 4903f36
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
10 changes: 5 additions & 5 deletions processing/src/main/java/io/druid/segment/IndexIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
import io.druid.segment.column.ColumnDescriptor;
import io.druid.segment.column.ValueType;
import io.druid.segment.data.ArrayIndexed;
import io.druid.segment.data.BitmapSerde;
import io.druid.segment.data.BitmapSerdeFactory;
import io.druid.segment.data.ByteBufferSerializer;
import io.druid.segment.data.CompressedLongsIndexedSupplier;
import io.druid.segment.data.ConciseBitmapSerdeFactory;
import io.druid.segment.data.GenericIndexed;
import io.druid.segment.data.IndexedIterable;
import io.druid.segment.data.IndexedRTree;
Expand Down Expand Up @@ -257,7 +257,7 @@ public MMappedIndex mapDir(File inDir) throws IOException
indexBuffer, GenericIndexed.stringStrategy
);
final Interval dataInterval = new Interval(serializerUtils.readString(indexBuffer));
final BitmapSerdeFactory conciseBitmapSerdeFactory = new ConciseBitmapSerdeFactory();
final BitmapSerdeFactory bitmapSerdeFactory = BitmapSerde.createLegacyFactory();

CompressedLongsIndexedSupplier timestamps = CompressedLongsIndexedSupplier.fromByteBuffer(
smooshedFiles.mapFile(makeTimeFile(inDir, BYTE_ORDER).getName()), BYTE_ORDER
Expand Down Expand Up @@ -296,7 +296,7 @@ public MMappedIndex mapDir(File inDir) throws IOException
for (int i = 0; i < availableDimensions.size(); ++i) {
bitmaps.put(
serializerUtils.readString(invertedBuffer),
GenericIndexed.read(invertedBuffer, conciseBitmapSerdeFactory.getObjectStrategy())
GenericIndexed.read(invertedBuffer, bitmapSerdeFactory.getObjectStrategy())
);
}

Expand All @@ -307,7 +307,7 @@ public MMappedIndex mapDir(File inDir) throws IOException
serializerUtils.readString(spatialBuffer),
ByteBufferSerializer.read(
spatialBuffer,
new IndexedRTree.ImmutableRTreeObjectStrategy(conciseBitmapSerdeFactory.getBitmapFactory())
new IndexedRTree.ImmutableRTreeObjectStrategy(bitmapSerdeFactory.getBitmapFactory())
)
);
}
Expand Down Expand Up @@ -772,7 +772,7 @@ public QueryableIndex load(File inDir) throws IOException
if (indexBuffer.hasRemaining()) {
segmentBitmapSerdeFactory = mapper.readValue(serializerUtils.readString(indexBuffer), BitmapSerdeFactory.class);
} else {
segmentBitmapSerdeFactory = new ConciseBitmapSerdeFactory();
segmentBitmapSerdeFactory = BitmapSerde.createLegacyFactory();
}

Map<String, Column> columns = Maps.newHashMap();
Expand Down
50 changes: 50 additions & 0 deletions processing/src/main/java/io/druid/segment/data/BitmapSerde.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

/**
*/
@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.Type(name = "concise", value = ConciseBitmapSerdeFactory.class),
@JsonSubTypes.Type(name = "roaring", value = RoaringBitmapSerdeFactory.class)
})

public interface BitmapSerdeFactory
{
public ObjectStrategy<ImmutableBitmap> getObjectStrategy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import io.druid.segment.column.ColumnBuilder;
import io.druid.segment.column.ColumnConfig;
import io.druid.segment.column.ValueType;
import io.druid.segment.data.BitmapSerde;
import io.druid.segment.data.BitmapSerdeFactory;
import io.druid.segment.data.ByteBufferSerializer;
import io.druid.segment.data.ConciseBitmapSerdeFactory;
import io.druid.segment.data.GenericIndexed;
import io.druid.segment.data.IndexedRTree;
import io.druid.segment.data.VSizeIndexed;
Expand Down Expand Up @@ -97,7 +97,7 @@ public DictionaryEncodedColumnPartSerde(
{
this.isSingleValued = isSingleValued;
this.bitmapSerdeFactory = bitmapSerdeFactory == null
? new ConciseBitmapSerdeFactory()
? BitmapSerde.createLegacyFactory()
: bitmapSerdeFactory;

this.dictionary = null;
Expand Down

0 comments on commit 4903f36

Please sign in to comment.