Removed MultiComparator from more API calls in ITreeIndexFrame.
git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_btree_updates_next@621 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/util/SerdeUtils.java b/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/util/SerdeUtils.java
index cc35a13..d690279 100644
--- a/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/util/SerdeUtils.java
+++ b/hyracks-dataflow-common/src/main/java/edu/uci/ics/hyracks/dataflow/common/util/SerdeUtils.java
@@ -16,6 +16,7 @@
package edu.uci.ics.hyracks.dataflow.common.util;
import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.dataflow.value.ITypeTrait;
import edu.uci.ics.hyracks.dataflow.common.data.comparators.DoubleBinaryComparatorFactory;
@@ -87,4 +88,34 @@
}
throw new UnsupportedOperationException("Binary comparator for + " + serde.toString() + " not implemented.");
}
+
+ public static IBinaryComparatorFactory[] serdesToComparatorFactories(ISerializerDeserializer[] serdes, int numSerdes) {
+ IBinaryComparatorFactory[] comparatorsFactories = new IBinaryComparatorFactory[numSerdes];
+ for (int i = 0; i < numSerdes; i++) {
+ comparatorsFactories[i] = serdeToComparatorFactory(serdes[i]);
+ }
+ return comparatorsFactories;
+ }
+
+ public static IBinaryComparatorFactory serdeToComparatorFactory(ISerializerDeserializer serde) {
+ if (serde instanceof IntegerSerializerDeserializer) {
+ return IntegerBinaryComparatorFactory.INSTANCE;
+ }
+ if (serde instanceof Integer64SerializerDeserializer) {
+ throw new UnsupportedOperationException("Binary comparator factory for Integer64 not implemented.");
+ }
+ if (serde instanceof FloatSerializerDeserializer) {
+ return FloatBinaryComparatorFactory.INSTANCE;
+ }
+ if (serde instanceof DoubleSerializerDeserializer) {
+ return DoubleBinaryComparatorFactory.INSTANCE;
+ }
+ if (serde instanceof BooleanSerializerDeserializer) {
+ throw new UnsupportedOperationException("Binary comparator factory for Boolean not implemented.");
+ }
+ if (serde instanceof UTF8StringSerializerDeserializer) {
+ return UTF8StringBinaryComparatorFactory.INSTANCE;
+ }
+ throw new UnsupportedOperationException("Binary comparator for + " + serde.toString() + " not implemented.");
+ }
}
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java
index 38b4e61..dc4f53a 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IPrefixSlotManager.java
@@ -16,7 +16,6 @@
package edu.uci.ics.hyracks.storage.am.btree.api;
import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
-import edu.uci.ics.hyracks.storage.am.btree.frames.BTreeFieldPrefixNSMLeafFrame;
import edu.uci.ics.hyracks.storage.am.common.api.ISlotManager;
import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleReference;
import edu.uci.ics.hyracks.storage.am.common.ophelpers.FindTupleMode;
@@ -59,7 +58,7 @@
public int insertSlot(int slot, int tupleOff);
// returns prefix slot number, returns TUPLE_UNCOMPRESSED if none found
- public int findPrefix(ITupleReference tuple, ITreeIndexTupleReference framePrefixTuple, MultiComparator multiCmp);
+ public int findPrefix(ITupleReference tuple, ITreeIndexTupleReference framePrefixTuple);
public int getTupleSlotStartOff();
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java
index d1012a5..816f75e 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrame.java
@@ -79,13 +79,13 @@
private FieldPrefixTupleReference frameTuple;
private FieldPrefixPrefixTupleReference framePrefixTuple;
- public BTreeFieldPrefixNSMLeafFrame(ITreeIndexTupleWriter tupleWriter) {
+ public BTreeFieldPrefixNSMLeafFrame(ITreeIndexTupleWriter tupleWriter, MultiComparator cmp) {
this.tupleWriter = tupleWriter;
this.frameTuple = new FieldPrefixTupleReference(tupleWriter.createTupleReference());
ITypeTrait[] typeTraits = ((TypeAwareTupleWriter) tupleWriter).getTypeTraits();
this.fieldCount = typeTraits.length;
this.framePrefixTuple = new FieldPrefixPrefixTupleReference(typeTraits);
- this.slotManager = new FieldPrefixSlotManager();
+ this.slotManager = new FieldPrefixSlotManager(cmp);
this.compressor = new FieldPrefixCompressor(typeTraits, 0.001f, 2);
}
@@ -182,14 +182,8 @@
}
@Override
- public void delete(ITupleReference tuple, MultiComparator cmp, int slot) {
- // TODO: Fixme.
- //int slot = slotManager.findSlot(tuple, frameTuple, framePrefixTuple, cmp, FindTupleMode.FTM_EXACT,
- // FindTupleNoExactMatchPolicy.FTP_HIGHER_KEY);
+ public void delete(ITupleReference tuple, int slot) {
int tupleIndex = slotManager.decodeSecondSlotField(slot);
- //if (tupleIndex == FieldPrefixSlotManager.GREATEST_SLOT) {
- // throw new BTreeException("Key to be deleted does not exist.");
- //}
int prefixSlotNum = slotManager.decodeFirstSlotField(slot);
int tupleSlotOff = slotManager.getTupleSlotOff(tupleIndex);
@@ -219,7 +213,7 @@
}
@Override
- public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple, MultiComparator cmp) {
+ public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) {
int freeContiguous = buf.capacity() - buf.getInt(freeSpaceOff)
- ((buf.getInt(tupleCountOff) + buf.getInt(prefixTupleCountOff)) * slotManager.getSlotSize());
@@ -234,7 +228,7 @@
return FrameOpSpaceStatus.SUFFICIENT_SPACE;
// See if the tuple matches a prefix and will fit after truncating the prefix.
- int prefixSlotNum = slotManager.findPrefix(tuple, framePrefixTuple, cmp);
+ int prefixSlotNum = slotManager.findPrefix(tuple, framePrefixTuple);
if (prefixSlotNum != FieldPrefixSlotManager.TUPLE_UNCOMPRESSED) {
int prefixSlotOff = slotManager.getPrefixSlotOff(prefixSlotNum);
int prefixSlot = buf.getInt(prefixSlotOff);
@@ -272,7 +266,7 @@
}
@Override
- public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex, MultiComparator cmp) {
+ public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex) {
int tupleIndex = slotManager.decodeSecondSlotField(oldTupleIndex);
frameTuple.resetByTupleIndex(this, tupleIndex);
// TODO: Do we need to set the field count here?
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java
index 70ac13a..c4d8b9c 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeFieldPrefixNSMLeafFrameFactory.java
@@ -15,22 +15,28 @@
package edu.uci.ics.hyracks.storage.am.btree.frames;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrame;
+import edu.uci.ics.hyracks.storage.am.btree.util.BTreeUtils;
import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
public class BTreeFieldPrefixNSMLeafFrameFactory implements ITreeIndexFrameFactory {
private static final long serialVersionUID = 1L;
private final ITreeIndexTupleWriterFactory tupleWriterFactory;
-
- public BTreeFieldPrefixNSMLeafFrameFactory(ITreeIndexTupleWriterFactory tupleWriterFactory) {
+ private final IBinaryComparatorFactory[] cmpFactories;
+
+ public BTreeFieldPrefixNSMLeafFrameFactory(ITreeIndexTupleWriterFactory tupleWriterFactory, IBinaryComparatorFactory[] cmpFactories) {
this.tupleWriterFactory = tupleWriterFactory;
+ this.cmpFactories = cmpFactories;
}
@Override
public IBTreeLeafFrame createFrame() {
- return new BTreeFieldPrefixNSMLeafFrame(tupleWriterFactory.createTupleWriter());
+ MultiComparator cmp = BTreeUtils.createMultiComparator(cmpFactories);
+ return new BTreeFieldPrefixNSMLeafFrame(tupleWriterFactory.createTupleWriter(), cmp);
}
@Override
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
index 95fcd14..5d84c1d 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/BTreeNSMInteriorFrame.java
@@ -63,7 +63,7 @@
}
@Override
- public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple, MultiComparator cmp) {
+ public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) {
int bytesRequired = tupleWriter.bytesRequired(tuple) + 8; // for the two
// childpointers
if (bytesRequired + slotManager.getSlotSize() <= buf.capacity() - buf.getInt(freeSpaceOff)
@@ -320,22 +320,21 @@
}
@Override
- public void delete(ITupleReference tuple, MultiComparator cmp, int tupleIndex) {
- frameTuple.setFieldCount(cmp.getKeyFieldCount());
+ public void delete(ITupleReference tuple, int tupleIndex) {
int slotOff = slotManager.getSlotOff(tupleIndex);
int tupleOff;
int keySize;
if (tupleIndex == slotManager.getGreatestKeyIndicator()) {
tupleOff = slotManager.getTupleOff(slotManager.getSlotEndOff());
frameTuple.resetByTupleOffset(buf, tupleOff);
- keySize = tupleWriter.bytesRequired(frameTuple, 0, cmp.getKeyFieldCount());
+ keySize = tupleWriter.bytesRequired(frameTuple, 0, tuple.getFieldCount());
// copy new rightmost pointer
System.arraycopy(buf.array(), tupleOff + keySize, buf.array(), rightLeafOff, childPtrSize);
} else {
tupleOff = slotManager.getTupleOff(slotOff);
frameTuple.resetByTupleOffset(buf, tupleOff);
- keySize = tupleWriter.bytesRequired(frameTuple, 0, cmp.getKeyFieldCount());
+ keySize = tupleWriter.bytesRequired(frameTuple, 0, tuple.getFieldCount());
// perform deletion (we just do a memcpy to overwrite the slot)
int slotStartOff = slotManager.getSlotEndOff();
int length = slotOff - slotStartOff;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
index 03c1272..e7b3cd5 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
@@ -312,7 +312,7 @@
private void insertLeaf(ICachedPage node, int pageId, ITupleReference tuple, BTreeOpContext ctx) throws Exception {
ctx.leafFrame.setPage(node);
int targetTupleIndex = ctx.leafFrame.findInsertTupleIndex(tuple, cmp);
- FrameOpSpaceStatus spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple, cmp);
+ FrameOpSpaceStatus spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple);
switch (spaceStatus) {
case SUFFICIENT_CONTIGUOUS_SPACE: {
ctx.leafFrame.insert(tuple, targetTupleIndex);
@@ -334,7 +334,7 @@
if (reCompressed) {
// Compression could have changed the target tuple index, find it again.
targetTupleIndex = ctx.leafFrame.findInsertTupleIndex(tuple, cmp);
- spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple, cmp);
+ spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple);
}
if (spaceStatus == FrameOpSpaceStatus.SUFFICIENT_CONTIGUOUS_SPACE) {
ctx.leafFrame.insert(tuple, targetTupleIndex);
@@ -421,7 +421,7 @@
private void updateLeaf(ICachedPage node, int pageId, ITupleReference tuple, BTreeOpContext ctx) throws Exception {
ctx.leafFrame.setPage(node);
int oldTupleIndex = ctx.leafFrame.findUpdateTupleIndex(tuple, cmp);
- FrameOpSpaceStatus spaceStatus = ctx.leafFrame.hasSpaceUpdate(tuple, oldTupleIndex, cmp);
+ FrameOpSpaceStatus spaceStatus = ctx.leafFrame.hasSpaceUpdate(tuple, oldTupleIndex);
switch (spaceStatus) {
case SUFFICIENT_INPLACE_SPACE: {
ctx.leafFrame.update(tuple, oldTupleIndex, true);
@@ -435,7 +435,7 @@
}
case SUFFICIENT_SPACE: {
// Delete the old tuple, compact the frame, and insert the new tuple.
- ctx.leafFrame.delete(tuple, cmp, oldTupleIndex);
+ ctx.leafFrame.delete(tuple, oldTupleIndex);
ctx.leafFrame.compact(cmp);
int targetTupleIndex = ctx.leafFrame.findInsertTupleIndex(tuple, cmp);
ctx.leafFrame.insert(tuple, targetTupleIndex);
@@ -444,10 +444,10 @@
}
case INSUFFICIENT_SPACE: {
// Delete the old tuple, and try compressing the page to make space available.
- ctx.leafFrame.delete(tuple, cmp, oldTupleIndex);
+ ctx.leafFrame.delete(tuple, oldTupleIndex);
ctx.leafFrame.compress(cmp);
// We need to insert the new tuple, so check if there is space.
- spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple, cmp);
+ spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple);
if (spaceStatus == FrameOpSpaceStatus.SUFFICIENT_CONTIGUOUS_SPACE) {
int targetTupleIndex = ctx.leafFrame.findInsertTupleIndex(tuple, cmp);
ctx.leafFrame.insert(tuple, targetTupleIndex);
@@ -466,7 +466,7 @@
throws Exception {
ctx.interiorFrame.setPage(node);
int targetTupleIndex = ctx.interiorFrame.findInsertTupleIndex(tuple, cmp);
- FrameOpSpaceStatus spaceStatus = ctx.interiorFrame.hasSpaceInsert(tuple, cmp);
+ FrameOpSpaceStatus spaceStatus = ctx.interiorFrame.hasSpaceInsert(tuple);
switch (spaceStatus) {
case INSUFFICIENT_SPACE: {
int rightPageId = freePageManager.getFreePage(ctx.metaFrame);
@@ -542,7 +542,7 @@
try {
treeLatch.writeLock().lock();
try {
- ctx.leafFrame.delete(tuple, cmp, tupleIndex);
+ ctx.leafFrame.delete(tuple, tupleIndex);
// to propagate the deletion we only need to make the
// splitKey != null
// we can reuse data to identify which key to delete in
@@ -605,7 +605,7 @@
}
} else {
// Leaf will not become empty
- ctx.leafFrame.delete(tuple, cmp, tupleIndex);
+ ctx.leafFrame.delete(tuple, tupleIndex);
node.releaseWriteLatch();
bufferCache.unpin(node);
}
@@ -634,7 +634,7 @@
ctx.freePages.add(pageId);
} else {
- ctx.interiorFrame.delete(tuple, cmp, tupleIndex);
+ ctx.interiorFrame.delete(tuple, tupleIndex);
ctx.interiorFrame.setPageLsn(ctx.interiorFrame.getPageLsn() + 1); // TODO:
// tie
// together
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java
index 4ebb06a..22b4ec0 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/FieldPrefixSlotManager.java
@@ -36,7 +36,12 @@
private ByteBuffer buf;
private BTreeFieldPrefixNSMLeafFrame frame;
-
+ private final MultiComparator cmp;
+
+ public FieldPrefixSlotManager(MultiComparator cmp) {
+ this.cmp = cmp;
+ }
+
public int decodeFirstSlotField(int slot) {
return (slot & 0xFF000000) >>> 24;
}
@@ -50,7 +55,7 @@
}
// returns prefix slot number, or TUPLE_UNCOMPRESSED of no match was found
- public int findPrefix(ITupleReference tuple, ITreeIndexTupleReference framePrefixTuple, MultiComparator multiCmp) {
+ public int findPrefix(ITupleReference tuple, ITreeIndexTupleReference framePrefixTuple) {
int prefixMid;
int prefixBegin = 0;
int prefixEnd = frame.getPrefixTupleCount() - 1;
@@ -59,10 +64,10 @@
while (prefixBegin <= prefixEnd) {
prefixMid = (prefixBegin + prefixEnd) / 2;
framePrefixTuple.resetByTupleIndex(frame, prefixMid);
- int cmp = multiCmp.fieldRangeCompare(tuple, framePrefixTuple, 0, framePrefixTuple.getFieldCount());
- if (cmp < 0)
+ int cmpVal = cmp.fieldRangeCompare(tuple, framePrefixTuple, 0, framePrefixTuple.getFieldCount());
+ if (cmpVal < 0)
prefixEnd = prefixMid - 1;
- else if (cmp > 0)
+ else if (cmpVal > 0)
prefixBegin = prefixMid + 1;
else
return prefixMid;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeUtils.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeUtils.java
index a29354a..4165fa5 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeUtils.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeUtils.java
@@ -1,6 +1,7 @@
package edu.uci.ics.hyracks.storage.am.btree.util;
import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
import edu.uci.ics.hyracks.api.dataflow.value.ITypeTrait;
import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
import edu.uci.ics.hyracks.storage.am.btree.exceptions.BTreeException;
@@ -20,10 +21,10 @@
import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
public class BTreeUtils {
- public static BTree createBTree(IBufferCache bufferCache, int btreeFileId, ITypeTrait[] typeTraits, IBinaryComparator[] cmps, BTreeLeafFrameType leafType) throws BTreeException {
- MultiComparator cmp = new MultiComparator(cmps);
+ public static BTree createBTree(IBufferCache bufferCache, int btreeFileId, ITypeTrait[] typeTraits, IBinaryComparatorFactory[] cmpFactories, BTreeLeafFrameType leafType) throws BTreeException {
+ MultiComparator cmp = createMultiComparator(cmpFactories);
TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
- ITreeIndexFrameFactory leafFrameFactory = getLeafFrameFactory(tupleWriterFactory, leafType);
+ ITreeIndexFrameFactory leafFrameFactory = getLeafFrameFactory(tupleWriterFactory, leafType, cmpFactories);
ITreeIndexFrameFactory interiorFrameFactory = new BTreeNSMInteriorFrameFactory(tupleWriterFactory);
ITreeIndexMetaDataFrameFactory metaFrameFactory = new LIFOMetaDataFrameFactory();
IFreePageManager freePageManager = new LinkedListFreePageManager(bufferCache, btreeFileId, 0, metaFrameFactory);
@@ -45,17 +46,25 @@
return new MultiComparator(cmps);
}
- public static ITreeIndexFrameFactory getLeafFrameFactory(ITreeIndexTupleWriterFactory tupleWriterFactory, BTreeLeafFrameType leafType) throws BTreeException {
+ public static ITreeIndexFrameFactory getLeafFrameFactory(ITreeIndexTupleWriterFactory tupleWriterFactory, BTreeLeafFrameType leafType, IBinaryComparatorFactory[] cmpFactories) throws BTreeException {
switch(leafType) {
case REGULAR_NSM: {
- return new BTreeNSMLeafFrameFactory(tupleWriterFactory);
+ return new BTreeNSMLeafFrameFactory(tupleWriterFactory);
}
case FIELD_PREFIX_COMPRESSED_NSM: {
- return new BTreeFieldPrefixNSMLeafFrameFactory(tupleWriterFactory);
+ return new BTreeFieldPrefixNSMLeafFrameFactory(tupleWriterFactory, cmpFactories);
}
default: {
throw new BTreeException("Unknown BTreeLeafFrameType: " + leafType.toString());
}
}
}
+
+ public static MultiComparator createMultiComparator(IBinaryComparatorFactory[] cmpFactories) {
+ IBinaryComparator[] cmps = new IBinaryComparator[cmpFactories.length];
+ for (int i = 0; i < cmpFactories.length; i++) {
+ cmps[i] = cmpFactories[i].createBinaryComparator();
+ }
+ return new MultiComparator(cmps);
+ }
}
diff --git a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java
index f9e6a1c..bfcc914 100644
--- a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java
+++ b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/api/ITreeIndexFrame.java
@@ -25,11 +25,16 @@
import edu.uci.ics.hyracks.storage.common.buffercache.ICachedPage;
public interface ITreeIndexFrame {
- public void insert(ITupleReference tuple, int tupleIndex);
+
+ public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple);
+
+ public void insert(ITupleReference tuple, int tupleIndex);
- public void update(ITupleReference newTuple, int oldTupleIndex, boolean inPlace);
+ public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex);
+
+ public void update(ITupleReference newTuple, int oldTupleIndex, boolean inPlace);
- public void delete(ITupleReference tuple, MultiComparator cmp, int tupleIndex);
+ public void delete(ITupleReference tuple, int tupleIndex);
// returns true if slots were modified, false otherwise
public boolean compact(MultiComparator cmp);
@@ -40,11 +45,6 @@
public int getTupleCount();
- // assumption: page must be write-latched at this point
- public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple, MultiComparator cmp);
-
- public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex, MultiComparator cmp);
-
public int getTupleOffset(int slotNum);
public int getTotalFreeSpace();
diff --git a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
index 91acc6c..c9a7540 100644
--- a/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
+++ b/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/frames/TreeIndexNSMFrame.java
@@ -147,7 +147,7 @@
}
@Override
- public void delete(ITupleReference tuple, MultiComparator cmp, int tupleIndex) {
+ public void delete(ITupleReference tuple, int tupleIndex) {
int slotOff = slotManager.getSlotOff(tupleIndex);
int tupleOff = slotManager.getTupleOff(slotOff);
frameTuple.resetByTupleOffset(buf, tupleOff);
@@ -164,7 +164,7 @@
}
@Override
- public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple, MultiComparator cmp) {
+ public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) {
int bytesRequired = tupleWriter.bytesRequired(tuple);
// Enough space in the contiguous space region?
if (bytesRequired + slotManager.getSlotSize() <= buf.capacity() - buf.getInt(freeSpaceOff)
@@ -179,7 +179,7 @@
}
@Override
- public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex, MultiComparator cmp) {
+ public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex) {
frameTuple.resetByTupleIndex(this, oldTupleIndex);
int oldTupleBytes = frameTuple.getTupleSize();
int newTupleBytes = tupleWriter.bytesRequired(newTuple);
diff --git a/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/frames/RTreeNSMInteriorFrame.java b/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/frames/RTreeNSMInteriorFrame.java
index f644cb2..bdc5366 100644
--- a/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/frames/RTreeNSMInteriorFrame.java
+++ b/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/frames/RTreeNSMInteriorFrame.java
@@ -268,7 +268,7 @@
}
@Override
- public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple, MultiComparator cmp) {
+ public FrameOpSpaceStatus hasSpaceInsert(ITupleReference tuple) {
int bytesRequired = tupleWriter.bytesRequired(tuple) + childPtrSize; // for
// the
// child
diff --git a/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/impls/RTree.java b/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/impls/RTree.java
index db94765..5193d71 100644
--- a/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/impls/RTree.java
+++ b/hyracks-storage-am-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/impls/RTree.java
@@ -401,9 +401,9 @@
throws HyracksDataException, TreeIndexException {
FrameOpSpaceStatus spaceStatus;
if (!isLeaf) {
- spaceStatus = ctx.interiorFrame.hasSpaceInsert(tuple, cmp);
+ spaceStatus = ctx.interiorFrame.hasSpaceInsert(tuple);
} else {
- spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple, cmp);
+ spaceStatus = ctx.leafFrame.hasSpaceInsert(tuple);
}
switch (spaceStatus) {
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java
index 3c82529..0508384 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java
@@ -37,10 +37,8 @@
import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
import edu.uci.ics.hyracks.dataflow.common.data.comparators.IntegerBinaryComparatorFactory;
import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
-import edu.uci.ics.hyracks.storage.am.btree.api.IPrefixSlotManager;
import edu.uci.ics.hyracks.storage.am.btree.exceptions.BTreeException;
import edu.uci.ics.hyracks.storage.am.btree.frames.BTreeFieldPrefixNSMLeafFrame;
-import edu.uci.ics.hyracks.storage.am.btree.impls.FieldPrefixSlotManager;
import edu.uci.ics.hyracks.storage.am.btree.util.AbstractBTreeTest;
import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleWriter;
import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
@@ -116,12 +114,10 @@
ICachedPage page = bufferCache.pin(BufferedFileHandle.getDiskPageId(btreeFileId, 0), false);
try {
- IPrefixSlotManager slotManager = new FieldPrefixSlotManager();
ITreeIndexTupleWriter tupleWriter = new TypeAwareTupleWriter(typeTraits);
- BTreeFieldPrefixNSMLeafFrame frame = new BTreeFieldPrefixNSMLeafFrame(tupleWriter);
+ BTreeFieldPrefixNSMLeafFrame frame = new BTreeFieldPrefixNSMLeafFrame(tupleWriter, cmp);
frame.setPage(page);
frame.initBuffer((byte) 0);
- slotManager.setFrame(frame);
frame.setPrefixTupleCount(0);
String before = new String();
@@ -183,7 +179,7 @@
ITupleReference tuple = createTuple(ctx, savedFields[i][0], savedFields[i][1], savedFields[i][2], false);
try {
int tupleIndex = frame.findDeleteTupleIndex(tuple, cmp);
- frame.delete(tuple, cmp, tupleIndex);
+ frame.delete(tuple, tupleIndex);
} catch (Exception e) {
}
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
index 7cd88cb..4fbf83f 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
@@ -27,6 +27,7 @@
import org.junit.Test;
import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
import edu.uci.ics.hyracks.api.dataflow.value.ITypeTrait;
import edu.uci.ics.hyracks.api.dataflow.value.TypeTrait;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -47,6 +48,7 @@
import edu.uci.ics.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor;
import edu.uci.ics.hyracks.storage.am.btree.impls.RangePredicate;
import edu.uci.ics.hyracks.storage.am.btree.util.AbstractBTreeTest;
+import edu.uci.ics.hyracks.storage.am.btree.util.BTreeUtils;
import edu.uci.ics.hyracks.storage.am.common.api.IFreePageManager;
import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexCursor;
import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
@@ -244,19 +246,17 @@
public void nonUniqueFieldPrefixIndexTest() throws Exception {
LOGGER.info("TESTING RANGE SEARCH CURSOR ON NONUNIQUE FIELD-PREFIX COMPRESSED INDEX");
- ITreeIndexFrameFactory leafFrameFactory = new BTreeFieldPrefixNSMLeafFrameFactory(
- tupleWriterFactory);
- IBTreeLeafFrame leafFrame = (IBTreeLeafFrame)leafFrameFactory.createFrame();
-
// declare keys
int keyFieldCount = 2;
- IBinaryComparator[] cmps = new IBinaryComparator[keyFieldCount];
- cmps[0] = IntegerBinaryComparatorFactory.INSTANCE
- .createBinaryComparator();
- cmps[1] = IntegerBinaryComparatorFactory.INSTANCE
- .createBinaryComparator();
+ IBinaryComparatorFactory[] cmpFactories = new IBinaryComparatorFactory[keyFieldCount];
+ cmpFactories[0] = IntegerBinaryComparatorFactory.INSTANCE;
+ cmpFactories[1] = IntegerBinaryComparatorFactory.INSTANCE ;
- MultiComparator cmp = new MultiComparator(cmps);
+ ITreeIndexFrameFactory leafFrameFactory = new BTreeFieldPrefixNSMLeafFrameFactory(
+ tupleWriterFactory, cmpFactories);
+ IBTreeLeafFrame leafFrame = (IBTreeLeafFrame)leafFrameFactory.createFrame();
+
+ MultiComparator cmp = BTreeUtils.createMultiComparator(cmpFactories);
IFreePageManager freePageManager = new LinkedListFreePageManager(bufferCache, btreeFileId, 0, metaFrameFactory);
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeTestUtils.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeTestUtils.java
index 07acaa8..b7bf92b 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeTestUtils.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/util/BTreeTestUtils.java
@@ -12,7 +12,7 @@
import java.util.TreeSet;
import java.util.logging.Logger;
-import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.dataflow.value.ITypeTrait;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -46,9 +46,9 @@
public static BTreeTestContext createBTreeTestContext(IBufferCache bufferCache, int btreeFileId, ISerializerDeserializer[] fieldSerdes, int numKeyFields, BTreeLeafFrameType leafType) throws Exception {
ITypeTrait[] typeTraits = SerdeUtils.serdesToTypeTraits(fieldSerdes, fieldSerdes.length);
- IBinaryComparator[] cmps = SerdeUtils.serdesToComparators(fieldSerdes, numKeyFields);
+ IBinaryComparatorFactory[] cmpFactories = SerdeUtils.serdesToComparatorFactories(fieldSerdes, numKeyFields);
- BTree btree = BTreeUtils.createBTree(bufferCache, btreeFileId, typeTraits, cmps, leafType);
+ BTree btree = BTreeUtils.createBTree(bufferCache, btreeFileId, typeTraits, cmpFactories, leafType);
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) btree.getLeafFrameFactory().createFrame();
IBTreeInteriorFrame interiorFrame = (IBTreeInteriorFrame) btree.getInteriorFrameFactory().createFrame();