Formatted code in Asterix style.
git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_storage_cleanup@264 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java b/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java
index 32771bf..54b97c1 100644
--- a/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java
+++ b/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java
@@ -72,16 +72,16 @@
import edu.uci.ics.hyracks.tests.integration.AbstractIntegrationTest;
public class BTreeOperatorsTest extends AbstractIntegrationTest {
-
- private static HyracksSimpleStorageManagerInterface storageManager = new HyracksSimpleStorageManagerInterface(8192, 20);
-
- @Test
- public void bulkLoadTest() throws Exception {
-
- JobSpecification spec = new JobSpecification();
-
- FileSplit[] ordersSplits = new FileSplit[] {
- new FileSplit(NC1_ID, new File("data/tpch0.001/orders-part1.tbl")) };
+
+ private static HyracksSimpleStorageManagerInterface storageManager = new HyracksSimpleStorageManagerInterface(8192,
+ 20);
+
+ @Test
+ public void bulkLoadTest() throws Exception {
+
+ JobSpecification spec = new JobSpecification();
+
+ FileSplit[] ordersSplits = new FileSplit[] { new FileSplit(NC1_ID, new File("data/tpch0.001/orders-part1.tbl")) };
IFileSplitProvider ordersSplitProvider = new ConstantFileSplitProvider(ordersSplits);
RecordDescriptor ordersDesc = new RecordDescriptor(new ISerializerDeserializer[] {
UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE,
@@ -89,169 +89,193 @@
UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE,
UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE,
UTF8StringSerializerDeserializer.INSTANCE });
-
+
FileScanOperatorDescriptor ordScanner = new FileScanOperatorDescriptor(spec, ordersSplitProvider,
new DelimitedDataTupleParserFactory(new IValueParserFactory[] { UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE }, '|'), ordersDesc);
- PartitionConstraint ordersPartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] {
- new AbsoluteLocationConstraint(NC1_ID) });
+ PartitionConstraint ordersPartitionConstraint = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
ordScanner.setPartitionConstraint(ordersPartitionConstraint);
InMemorySortOperatorDescriptor sorter = new InMemorySortOperatorDescriptor(spec, new int[] { 0 },
new IBinaryComparatorFactory[] { UTF8StringBinaryComparatorFactory.INSTANCE }, ordersDesc);
- PartitionConstraint sortersPartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] {
- new AbsoluteLocationConstraint(NC1_ID) });
+ PartitionConstraint sortersPartitionConstraint = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
sorter.setPartitionConstraint(sortersPartitionConstraint);
-
+
// declare fields
- int fieldCount = 3;
- ITypeTrait[] typeTraits = new ITypeTrait[fieldCount];
+ int fieldCount = 3;
+ ITypeTrait[] typeTraits = new ITypeTrait[fieldCount];
typeTraits[0] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
typeTraits[1] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
typeTraits[2] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
-
+
// declare keys
- int keyFieldCount = 1;
- IBinaryComparatorFactory[] comparatorFactories = new IBinaryComparatorFactory[keyFieldCount];
- comparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
-
- TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
- //SimpleTupleWriterFactory tupleWriterFactory = new SimpleTupleWriterFactory();
- IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
- IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);
- IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();
-
- int[] fieldPermutation = {0, 4, 5};
- String btreeName = "btree.bin";
- String nc1FileName = System.getProperty("java.io.tmpdir") + "/nc1/" + btreeName;
- IFileSplitProvider btreeSplitProvider = new ConstantFileSplitProvider(
- new FileSplit[] { new FileSplit(NC1_ID, new File(nc1FileName)) } );
-
- BTreeBulkLoadOperatorDescriptor btreeBulkLoad = new BTreeBulkLoadOperatorDescriptor(spec, storageManager, btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, fieldPermutation, 0.7f);
- PartitionConstraint btreePartitionConstraintA = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
- btreeBulkLoad.setPartitionConstraint(btreePartitionConstraintA);
-
+ int keyFieldCount = 1;
+ IBinaryComparatorFactory[] comparatorFactories = new IBinaryComparatorFactory[keyFieldCount];
+ comparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
+
+ TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
+ // SimpleTupleWriterFactory tupleWriterFactory = new
+ // SimpleTupleWriterFactory();
+ IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
+ IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);
+ IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();
+
+ int[] fieldPermutation = { 0, 4, 5 };
+ String btreeName = "btree.bin";
+ String nc1FileName = System.getProperty("java.io.tmpdir") + "/nc1/" + btreeName;
+ IFileSplitProvider btreeSplitProvider = new ConstantFileSplitProvider(new FileSplit[] { new FileSplit(NC1_ID,
+ new File(nc1FileName)) });
+
+ BTreeBulkLoadOperatorDescriptor btreeBulkLoad = new BTreeBulkLoadOperatorDescriptor(spec, storageManager,
+ btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits,
+ comparatorFactories, fieldPermutation, 0.7f);
+ PartitionConstraint btreePartitionConstraintA = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+ btreeBulkLoad.setPartitionConstraint(btreePartitionConstraintA);
+
spec.connect(new OneToOneConnectorDescriptor(spec), ordScanner, 0, sorter, 0);
-
+
spec.connect(new OneToOneConnectorDescriptor(spec), sorter, 0, btreeBulkLoad, 0);
-
+
spec.addRoot(btreeBulkLoad);
runTest(spec);
-
- // construct a multicomparator from the factories (only for printing purposes)
- IBinaryComparator[] comparators = new IBinaryComparator[comparatorFactories.length];
- for(int i = 0; i < comparatorFactories.length; i++) {
- comparators[i] = comparatorFactories[i].createBinaryComparator();
- }
-
+
+ // construct a multicomparator from the factories (only for printing
+ // purposes)
+ IBinaryComparator[] comparators = new IBinaryComparator[comparatorFactories.length];
+ for (int i = 0; i < comparatorFactories.length; i++) {
+ comparators[i] = comparatorFactories[i].createBinaryComparator();
+ }
+
MultiComparator cmp = new MultiComparator(typeTraits, comparators);
-
+
// try an ordered scan on the bulk-loaded btree
int btreeFileId = storageManager.getFileMapProvider().lookupFileId(nc1FileName);
- storageManager.getBufferCache().openFile(btreeFileId);
+ storageManager.getBufferCache().openFile(btreeFileId);
BTree btree = btreeRegistryProvider.getBTreeRegistry().get(btreeFileId);
IBTreeCursor scanCursor = new RangeSearchCursor(leafFrameFactory.getFrame());
RangePredicate nullPred = new RangePredicate(true, null, null, true, true, null, null);
- BTreeOpContext opCtx = btree.createOpContext(BTreeOp.BTO_SEARCH, leafFrameFactory.getFrame(), interiorFrameFactory.getFrame(), null);
+ BTreeOpContext opCtx = btree.createOpContext(BTreeOp.BTO_SEARCH, leafFrameFactory.getFrame(),
+ interiorFrameFactory.getFrame(), null);
btree.search(scanCursor, nullPred, opCtx);
try {
- while (scanCursor.hasNext()) {
- scanCursor.next();
- ITupleReference frameTuple = scanCursor.getTuple();
+ while (scanCursor.hasNext()) {
+ scanCursor.next();
+ ITupleReference frameTuple = scanCursor.getTuple();
String rec = cmp.printTuple(frameTuple, ordersDesc.getFields());
System.out.println(rec);
- }
+ }
} catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace();
} finally {
- scanCursor.close();
- }
+ scanCursor.close();
+ }
storageManager.getBufferCache().closeFile(btreeFileId);
- }
-
- @Test
- public void btreeSearchTest() throws Exception {
- JobSpecification spec = new JobSpecification();
-
- // declare fields
- int fieldCount = 3;
- ITypeTrait[] typeTraits = new ITypeTrait[fieldCount];
+ }
+
+ @Test
+ public void btreeSearchTest() throws Exception {
+ JobSpecification spec = new JobSpecification();
+
+ // declare fields
+ int fieldCount = 3;
+ ITypeTrait[] typeTraits = new ITypeTrait[fieldCount];
typeTraits[0] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
typeTraits[1] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
typeTraits[2] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
-
+
// declare keys
- int keyFieldCount = 1;
- IBinaryComparatorFactory[] comparatorFactories = new IBinaryComparatorFactory[keyFieldCount];
- comparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
-
- TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
- //SimpleTupleWriterFactory tupleWriterFactory = new SimpleTupleWriterFactory();
- IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
- IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);
-
- // construct a multicomparator from the factories (only for printing purposes)
- IBinaryComparator[] comparators = new IBinaryComparator[comparatorFactories.length];
- for(int i = 0; i < comparatorFactories.length; i++) {
- comparators[i] = comparatorFactories[i].createBinaryComparator();
- }
+ int keyFieldCount = 1;
+ IBinaryComparatorFactory[] comparatorFactories = new IBinaryComparatorFactory[keyFieldCount];
+ comparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
+
+ TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
+ // SimpleTupleWriterFactory tupleWriterFactory = new
+ // SimpleTupleWriterFactory();
+ IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
+ IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);
+
+ // construct a multicomparator from the factories (only for printing
+ // purposes)
+ IBinaryComparator[] comparators = new IBinaryComparator[comparatorFactories.length];
+ for (int i = 0; i < comparatorFactories.length; i++) {
+ comparators[i] = comparatorFactories[i].createBinaryComparator();
+ }
MultiComparator cmp = new MultiComparator(typeTraits, comparators);
-
+
// build tuple containing low and high search key
- ArrayTupleBuilder tb = new ArrayTupleBuilder(cmp.getKeyFieldCount()*2); // high key and low key
- DataOutput dos = tb.getDataOutput();
-
- tb.reset();
- UTF8StringSerializerDeserializer.INSTANCE.serialize("100", dos); // low key
- tb.addFieldEndOffset();
- UTF8StringSerializerDeserializer.INSTANCE.serialize("200", dos); // high key
- tb.addFieldEndOffset();
-
- ISerializerDeserializer[] keyRecDescSers = { UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE };
- RecordDescriptor keyRecDesc = new RecordDescriptor(keyRecDescSers);
-
- ConstantTupleSourceOperatorDescriptor keyProviderOp = new ConstantTupleSourceOperatorDescriptor(spec, keyRecDesc, tb.getFieldEndOffsets(), tb.getByteArray(), tb.getSize());
- PartitionConstraint keyProviderPartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
- keyProviderOp.setPartitionConstraint(keyProviderPartitionConstraint);
- IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();
-
- RecordDescriptor recDesc = new RecordDescriptor(
- new ISerializerDeserializer[] { UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE });
-
- String btreeName = "btree.bin";
- String nc1FileName = System.getProperty("java.io.tmpdir") + "/nc1/" + btreeName;
- IFileSplitProvider btreeSplitProvider = new ConstantFileSplitProvider(
- new FileSplit[] { new FileSplit(NC1_ID, new File(nc1FileName)) } );
-
- BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(spec, recDesc, storageManager, btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, true, new int[]{0}, new int[]{1}, true, true);
- //BTreeDiskOrderScanOperatorDescriptor btreeSearchOp = new BTreeDiskOrderScanOperatorDescriptor(spec, splitProvider, recDesc, bufferCacheProvider, btreeRegistryProvider, 0, "btreetest.bin", interiorFrameFactory, leafFrameFactory, cmp);
-
- PartitionConstraint btreePartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
- btreeSearchOp.setPartitionConstraint(btreePartitionConstraint);
-
- PrinterOperatorDescriptor printer = new PrinterOperatorDescriptor(spec);
- PartitionConstraint printerPartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+ ArrayTupleBuilder tb = new ArrayTupleBuilder(cmp.getKeyFieldCount() * 2); // high
+ // key
+ // and
+ // low
+ // key
+ DataOutput dos = tb.getDataOutput();
+
+ tb.reset();
+ UTF8StringSerializerDeserializer.INSTANCE.serialize("100", dos); // low
+ // key
+ tb.addFieldEndOffset();
+ UTF8StringSerializerDeserializer.INSTANCE.serialize("200", dos); // high
+ // key
+ tb.addFieldEndOffset();
+
+ ISerializerDeserializer[] keyRecDescSers = { UTF8StringSerializerDeserializer.INSTANCE,
+ UTF8StringSerializerDeserializer.INSTANCE };
+ RecordDescriptor keyRecDesc = new RecordDescriptor(keyRecDescSers);
+
+ ConstantTupleSourceOperatorDescriptor keyProviderOp = new ConstantTupleSourceOperatorDescriptor(spec,
+ keyRecDesc, tb.getFieldEndOffsets(), tb.getByteArray(), tb.getSize());
+ PartitionConstraint keyProviderPartitionConstraint = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+ keyProviderOp.setPartitionConstraint(keyProviderPartitionConstraint);
+ IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();
+
+ RecordDescriptor recDesc = new RecordDescriptor(new ISerializerDeserializer[] {
+ UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE,
+ UTF8StringSerializerDeserializer.INSTANCE });
+
+ String btreeName = "btree.bin";
+ String nc1FileName = System.getProperty("java.io.tmpdir") + "/nc1/" + btreeName;
+ IFileSplitProvider btreeSplitProvider = new ConstantFileSplitProvider(new FileSplit[] { new FileSplit(NC1_ID,
+ new File(nc1FileName)) });
+
+ BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(spec, recDesc, storageManager,
+ btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits,
+ comparatorFactories, true, new int[] { 0 }, new int[] { 1 }, true, true);
+ // BTreeDiskOrderScanOperatorDescriptor btreeSearchOp = new
+ // BTreeDiskOrderScanOperatorDescriptor(spec, splitProvider, recDesc,
+ // bufferCacheProvider, btreeRegistryProvider, 0, "btreetest.bin",
+ // interiorFrameFactory, leafFrameFactory, cmp);
+
+ PartitionConstraint btreePartitionConstraint = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+ btreeSearchOp.setPartitionConstraint(btreePartitionConstraint);
+
+ PrinterOperatorDescriptor printer = new PrinterOperatorDescriptor(spec);
+ PartitionConstraint printerPartitionConstraint = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
printer.setPartitionConstraint(printerPartitionConstraint);
-
+
spec.connect(new OneToOneConnectorDescriptor(spec), keyProviderOp, 0, btreeSearchOp, 0);
spec.connect(new OneToOneConnectorDescriptor(spec), btreeSearchOp, 0, printer, 0);
-
+
spec.addRoot(printer);
runTest(spec);
- }
-
- @Test
- public void insertTest() throws Exception {
- // relies on the fact that NCs are run from same process
- System.setProperty("NodeControllerDataPath", System.getProperty("java.io.tmpdir") + "/");
-
- JobSpecification spec = new JobSpecification();
-
- FileSplit[] ordersSplits = new FileSplit[] {
- new FileSplit(NC1_ID, new File("data/tpch0.001/orders-part1.tbl")) };
+ }
+
+ @Test
+ public void insertTest() throws Exception {
+ // relies on the fact that NCs are run from same process
+ System.setProperty("NodeControllerDataPath", System.getProperty("java.io.tmpdir") + "/");
+
+ JobSpecification spec = new JobSpecification();
+
+ FileSplit[] ordersSplits = new FileSplit[] { new FileSplit(NC1_ID, new File("data/tpch0.001/orders-part1.tbl")) };
IFileSplitProvider ordersSplitProvider = new ConstantFileSplitProvider(ordersSplits);
RecordDescriptor ordersDesc = new RecordDescriptor(new ISerializerDeserializer[] {
UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE,
@@ -259,214 +283,233 @@
UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE,
UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE,
UTF8StringSerializerDeserializer.INSTANCE });
-
+
FileScanOperatorDescriptor ordScanner = new FileScanOperatorDescriptor(spec, ordersSplitProvider,
new DelimitedDataTupleParserFactory(new IValueParserFactory[] { UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE,
UTF8StringParserFactory.INSTANCE, UTF8StringParserFactory.INSTANCE }, '|'), ordersDesc);
- PartitionConstraint ordersPartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] {
- new AbsoluteLocationConstraint(NC1_ID) });
+ PartitionConstraint ordersPartitionConstraint = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
ordScanner.setPartitionConstraint(ordersPartitionConstraint);
-
- // we will create a primary index and 2 secondary indexes
- // first create comparators for primary index
- int primaryFieldCount = 6;
- ITypeTrait[] primaryTypeTraits = new ITypeTrait[primaryFieldCount];
+
+ // we will create a primary index and 2 secondary indexes
+ // first create comparators for primary index
+ int primaryFieldCount = 6;
+ ITypeTrait[] primaryTypeTraits = new ITypeTrait[primaryFieldCount];
primaryTypeTraits[0] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
primaryTypeTraits[1] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
primaryTypeTraits[2] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
primaryTypeTraits[3] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
primaryTypeTraits[4] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
primaryTypeTraits[5] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
-
- int primaryKeyFieldCount = 1;
- IBinaryComparatorFactory[] primaryComparatorFactories = new IBinaryComparatorFactory[primaryKeyFieldCount];
- primaryComparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
-
- TypeAwareTupleWriterFactory primaryTupleWriterFactory = new TypeAwareTupleWriterFactory(primaryTypeTraits);
- //SimpleTupleWriterFactory primaryTupleWriterFactory = new SimpleTupleWriterFactory();
- IBTreeInteriorFrameFactory primaryInteriorFrameFactory = new NSMInteriorFrameFactory(primaryTupleWriterFactory);
- IBTreeLeafFrameFactory primaryLeafFrameFactory = new NSMLeafFrameFactory(primaryTupleWriterFactory);
- IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();
-
- // construct a multicomparator for the primary index
- IBinaryComparator[] primaryComparators = new IBinaryComparator[primaryComparatorFactories.length];
- for(int i = 0; i < primaryComparatorFactories.length; i++) {
- primaryComparators[i] = primaryComparatorFactories[i].createBinaryComparator();
- }
-
+
+ int primaryKeyFieldCount = 1;
+ IBinaryComparatorFactory[] primaryComparatorFactories = new IBinaryComparatorFactory[primaryKeyFieldCount];
+ primaryComparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
+
+ TypeAwareTupleWriterFactory primaryTupleWriterFactory = new TypeAwareTupleWriterFactory(primaryTypeTraits);
+ // SimpleTupleWriterFactory primaryTupleWriterFactory = new
+ // SimpleTupleWriterFactory();
+ IBTreeInteriorFrameFactory primaryInteriorFrameFactory = new NSMInteriorFrameFactory(primaryTupleWriterFactory);
+ IBTreeLeafFrameFactory primaryLeafFrameFactory = new NSMLeafFrameFactory(primaryTupleWriterFactory);
+ IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();
+
+ // construct a multicomparator for the primary index
+ IBinaryComparator[] primaryComparators = new IBinaryComparator[primaryComparatorFactories.length];
+ for (int i = 0; i < primaryComparatorFactories.length; i++) {
+ primaryComparators[i] = primaryComparatorFactories[i].createBinaryComparator();
+ }
+
MultiComparator primaryCmp = new MultiComparator(primaryTypeTraits, primaryComparators);
-
- // now create comparators for secondary indexes
- int secondaryFieldCount = 2;
- ITypeTrait[] secondaryTypeTraits = new ITypeTrait[secondaryFieldCount];
+
+ // now create comparators for secondary indexes
+ int secondaryFieldCount = 2;
+ ITypeTrait[] secondaryTypeTraits = new ITypeTrait[secondaryFieldCount];
secondaryTypeTraits[0] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
- secondaryTypeTraits[1] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
-
- int secondaryKeyFieldCount = 2;
- IBinaryComparatorFactory[] secondaryComparatorFactories = new IBinaryComparatorFactory[secondaryKeyFieldCount];
- secondaryComparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
- secondaryComparatorFactories[1] = UTF8StringBinaryComparatorFactory.INSTANCE;
-
- TypeAwareTupleWriterFactory secondaryTupleWriterFactory = new TypeAwareTupleWriterFactory(secondaryTypeTraits);
- //SimpleTupleWriterFactory secondaryTupleWriterFactory = new SimpleTupleWriterFactory();
- IBTreeInteriorFrameFactory secondaryInteriorFrameFactory = new NSMInteriorFrameFactory(secondaryTupleWriterFactory);
- IBTreeLeafFrameFactory secondaryLeafFrameFactory = new NSMLeafFrameFactory(secondaryTupleWriterFactory);
-
- // construct a multicomparator for the secondary indexes
- IBinaryComparator[] secondaryComparators = new IBinaryComparator[secondaryComparatorFactories.length];
- for(int i = 0; i < secondaryComparatorFactories.length; i++) {
- secondaryComparators[i] = secondaryComparatorFactories[i].createBinaryComparator();
- }
-
+ secondaryTypeTraits[1] = new TypeTrait(ITypeTrait.VARIABLE_LENGTH);
+
+ int secondaryKeyFieldCount = 2;
+ IBinaryComparatorFactory[] secondaryComparatorFactories = new IBinaryComparatorFactory[secondaryKeyFieldCount];
+ secondaryComparatorFactories[0] = UTF8StringBinaryComparatorFactory.INSTANCE;
+ secondaryComparatorFactories[1] = UTF8StringBinaryComparatorFactory.INSTANCE;
+
+ TypeAwareTupleWriterFactory secondaryTupleWriterFactory = new TypeAwareTupleWriterFactory(secondaryTypeTraits);
+ // SimpleTupleWriterFactory secondaryTupleWriterFactory = new
+ // SimpleTupleWriterFactory();
+ IBTreeInteriorFrameFactory secondaryInteriorFrameFactory = new NSMInteriorFrameFactory(
+ secondaryTupleWriterFactory);
+ IBTreeLeafFrameFactory secondaryLeafFrameFactory = new NSMLeafFrameFactory(secondaryTupleWriterFactory);
+
+ // construct a multicomparator for the secondary indexes
+ IBinaryComparator[] secondaryComparators = new IBinaryComparator[secondaryComparatorFactories.length];
+ for (int i = 0; i < secondaryComparatorFactories.length; i++) {
+ secondaryComparators[i] = secondaryComparatorFactories[i].createBinaryComparator();
+ }
+
MultiComparator secondaryCmp = new MultiComparator(secondaryTypeTraits, secondaryComparators);
-
- // we create and register 3 btrees for in an insert pipeline being fed from a filescan op
- BTreeRegistry btreeRegistry = btreeRegistryProvider.getBTreeRegistry();
+
+ // we create and register 3 btrees for in an insert pipeline being fed
+ // from a filescan op
+ BTreeRegistry btreeRegistry = btreeRegistryProvider.getBTreeRegistry();
IBufferCache bufferCache = storageManager.getBufferCache();
- IFileMapProvider fileMapProvider = storageManager.getFileMapProvider();
-
+ IFileMapProvider fileMapProvider = storageManager.getFileMapProvider();
+
// primary index
String fileNameA = "/tmp/btreetestA.ix";
- bufferCache.createFile(fileNameA);
- int fileIdA = fileMapProvider.lookupFileId(fileNameA);
+ bufferCache.createFile(fileNameA);
+ int fileIdA = fileMapProvider.lookupFileId(fileNameA);
bufferCache.openFile(fileIdA);
- BTree btreeA = new BTree(bufferCache, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryCmp);
+ BTree btreeA = new BTree(bufferCache, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryCmp);
btreeA.create(fileIdA, primaryLeafFrameFactory.getFrame(), new MetaDataFrame());
btreeA.open(fileIdA);
btreeRegistry.register(fileIdA, btreeA);
bufferCache.closeFile(fileIdA);
-
+
// first secondary index
String fileNameB = "/tmp/btreetestB.ix";
- bufferCache.createFile(fileNameB);
+ bufferCache.createFile(fileNameB);
int fileIdB = fileMapProvider.lookupFileId(fileNameB);
bufferCache.openFile(fileIdB);
- BTree btreeB = new BTree(bufferCache, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryCmp);
- btreeB.create(fileIdB, secondaryLeafFrameFactory.getFrame(), new MetaDataFrame());
+ BTree btreeB = new BTree(bufferCache, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryCmp);
+ btreeB.create(fileIdB, secondaryLeafFrameFactory.getFrame(), new MetaDataFrame());
btreeB.open(fileIdB);
btreeRegistry.register(fileIdB, btreeB);
bufferCache.closeFile(fileIdB);
-
+
// second secondary index
String fileNameC = "/tmp/btreetestC.ix";
bufferCache.createFile(fileNameC);
int fileIdC = fileMapProvider.lookupFileId(fileNameC);
bufferCache.openFile(fileIdC);
- BTree btreeC = new BTree(bufferCache, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryCmp);
- btreeC.create(fileIdC, secondaryLeafFrameFactory.getFrame(), new MetaDataFrame());
+ BTree btreeC = new BTree(bufferCache, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryCmp);
+ btreeC.create(fileIdC, secondaryLeafFrameFactory.getFrame(), new MetaDataFrame());
btreeC.open(fileIdC);
- btreeRegistry.register(fileIdC, btreeC);
+ btreeRegistry.register(fileIdC, btreeC);
bufferCache.closeFile(fileIdC);
-
-
+
// create insert operators
-
- // primary index
- IFileSplitProvider btreeSplitProviderA = new ConstantFileSplitProvider(
- new FileSplit[] { new FileSplit(NC1_ID, new File("/tmp/btreetestA.ix")) } );
- int[] fieldPermutationA = { 0,1,2,3,4,5 };
- BTreeInsertUpdateDeleteOperatorDescriptor insertOpA = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderA, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits, primaryComparatorFactories, fieldPermutationA, BTreeOp.BTO_INSERT);
- PartitionConstraint insertPartitionConstraintA = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+
+ // primary index
+ IFileSplitProvider btreeSplitProviderA = new ConstantFileSplitProvider(new FileSplit[] { new FileSplit(NC1_ID,
+ new File("/tmp/btreetestA.ix")) });
+ int[] fieldPermutationA = { 0, 1, 2, 3, 4, 5 };
+ BTreeInsertUpdateDeleteOperatorDescriptor insertOpA = new BTreeInsertUpdateDeleteOperatorDescriptor(spec,
+ ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderA, primaryInteriorFrameFactory,
+ primaryLeafFrameFactory, primaryTypeTraits, primaryComparatorFactories, fieldPermutationA,
+ BTreeOp.BTO_INSERT);
+ PartitionConstraint insertPartitionConstraintA = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
insertOpA.setPartitionConstraint(insertPartitionConstraintA);
-
+
// first secondary index
- IFileSplitProvider btreeSplitProviderB = new ConstantFileSplitProvider(
- new FileSplit[] { new FileSplit(NC1_ID, new File("/tmp/btreetestB.ix")) } );
- int[] fieldPermutationB = { 3, 0 };
- BTreeInsertUpdateDeleteOperatorDescriptor insertOpB = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderB, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationB, BTreeOp.BTO_INSERT);
- PartitionConstraint insertPartitionConstraintB = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+ IFileSplitProvider btreeSplitProviderB = new ConstantFileSplitProvider(new FileSplit[] { new FileSplit(NC1_ID,
+ new File("/tmp/btreetestB.ix")) });
+ int[] fieldPermutationB = { 3, 0 };
+ BTreeInsertUpdateDeleteOperatorDescriptor insertOpB = new BTreeInsertUpdateDeleteOperatorDescriptor(spec,
+ ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderB, secondaryInteriorFrameFactory,
+ secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationB,
+ BTreeOp.BTO_INSERT);
+ PartitionConstraint insertPartitionConstraintB = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
insertOpB.setPartitionConstraint(insertPartitionConstraintB);
-
+
// second secondary index
- IFileSplitProvider btreeSplitProviderC = new ConstantFileSplitProvider(
- new FileSplit[] { new FileSplit(NC1_ID, new File("/tmp/btreetestC.ix")) } );
- int[] fieldPermutationC = { 4, 0 };
- BTreeInsertUpdateDeleteOperatorDescriptor insertOpC = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderC, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationC, BTreeOp.BTO_INSERT);
- PartitionConstraint insertPartitionConstraintC = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+ IFileSplitProvider btreeSplitProviderC = new ConstantFileSplitProvider(new FileSplit[] { new FileSplit(NC1_ID,
+ new File("/tmp/btreetestC.ix")) });
+ int[] fieldPermutationC = { 4, 0 };
+ BTreeInsertUpdateDeleteOperatorDescriptor insertOpC = new BTreeInsertUpdateDeleteOperatorDescriptor(spec,
+ ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderC, secondaryInteriorFrameFactory,
+ secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationC,
+ BTreeOp.BTO_INSERT);
+ PartitionConstraint insertPartitionConstraintC = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
insertOpC.setPartitionConstraint(insertPartitionConstraintC);
-
+
NullSinkOperatorDescriptor nullSink = new NullSinkOperatorDescriptor(spec);
- PartitionConstraint nullSinkPartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
+ PartitionConstraint nullSinkPartitionConstraint = new ExplicitPartitionConstraint(
+ new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
nullSink.setPartitionConstraint(nullSinkPartitionConstraint);
-
+
spec.connect(new OneToOneConnectorDescriptor(spec), ordScanner, 0, insertOpA, 0);
-
+
spec.connect(new OneToOneConnectorDescriptor(spec), insertOpA, 0, insertOpB, 0);
-
- spec.connect(new OneToOneConnectorDescriptor(spec), insertOpB, 0, insertOpC, 0);
-
- spec.connect(new OneToOneConnectorDescriptor(spec), insertOpC, 0, nullSink, 0);
-
+
+ spec.connect(new OneToOneConnectorDescriptor(spec), insertOpB, 0, insertOpC, 0);
+
+ spec.connect(new OneToOneConnectorDescriptor(spec), insertOpC, 0, nullSink, 0);
+
spec.addRoot(nullSink);
runTest(spec);
-
- // scan primary index
+
+ // scan primary index
System.out.println("PRINTING PRIMARY INDEX");
bufferCache.openFile(fileIdA);
IBTreeCursor scanCursorA = new RangeSearchCursor(primaryLeafFrameFactory.getFrame());
RangePredicate nullPredA = new RangePredicate(true, null, null, true, true, null, null);
- BTreeOpContext opCtxA = btreeA.createOpContext(BTreeOp.BTO_SEARCH, primaryLeafFrameFactory.getFrame(), primaryInteriorFrameFactory.getFrame(), null);
+ BTreeOpContext opCtxA = btreeA.createOpContext(BTreeOp.BTO_SEARCH, primaryLeafFrameFactory.getFrame(),
+ primaryInteriorFrameFactory.getFrame(), null);
btreeA.search(scanCursorA, nullPredA, opCtxA);
try {
- while (scanCursorA.hasNext()) {
- scanCursorA.next();
- ITupleReference frameTuple = scanCursorA.getTuple();
+ while (scanCursorA.hasNext()) {
+ scanCursorA.next();
+ ITupleReference frameTuple = scanCursorA.getTuple();
String rec = primaryCmp.printTuple(frameTuple, ordersDesc.getFields());
- System.out.println(rec);
- }
+ System.out.println(rec);
+ }
} catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace();
} finally {
- scanCursorA.close();
- }
+ scanCursorA.close();
+ }
bufferCache.closeFile(fileIdA);
System.out.println();
-
+
// scan first secondary index
System.out.println("PRINTING FIRST SECONDARY INDEX");
bufferCache.openFile(fileIdB);
IBTreeCursor scanCursorB = new RangeSearchCursor(secondaryLeafFrameFactory.getFrame());
RangePredicate nullPredB = new RangePredicate(true, null, null, true, true, null, null);
- BTreeOpContext opCtxB = btreeB.createOpContext(BTreeOp.BTO_SEARCH, secondaryLeafFrameFactory.getFrame(), secondaryInteriorFrameFactory.getFrame(), null);
+ BTreeOpContext opCtxB = btreeB.createOpContext(BTreeOp.BTO_SEARCH, secondaryLeafFrameFactory.getFrame(),
+ secondaryInteriorFrameFactory.getFrame(), null);
btreeB.search(scanCursorB, nullPredB, opCtxB);
try {
- while (scanCursorB.hasNext()) {
- scanCursorB.next();
- ITupleReference frameTuple = scanCursorB.getTuple();
+ while (scanCursorB.hasNext()) {
+ scanCursorB.next();
+ ITupleReference frameTuple = scanCursorB.getTuple();
String rec = secondaryCmp.printTuple(frameTuple, ordersDesc.getFields());
- System.out.println(rec);
- }
+ System.out.println(rec);
+ }
} catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace();
} finally {
- scanCursorB.close();
- }
+ scanCursorB.close();
+ }
bufferCache.closeFile(fileIdB);
System.out.println();
-
+
// scan second secondary index
System.out.println("PRINTING SECOND SECONDARY INDEX");
bufferCache.openFile(fileIdC);
IBTreeCursor scanCursorC = new RangeSearchCursor(secondaryLeafFrameFactory.getFrame());
RangePredicate nullPredC = new RangePredicate(true, null, null, true, true, null, null);
- BTreeOpContext opCtxC = btreeC.createOpContext(BTreeOp.BTO_SEARCH, secondaryLeafFrameFactory.getFrame(), secondaryInteriorFrameFactory.getFrame(), null);
+ BTreeOpContext opCtxC = btreeC.createOpContext(BTreeOp.BTO_SEARCH, secondaryLeafFrameFactory.getFrame(),
+ secondaryInteriorFrameFactory.getFrame(), null);
btreeC.search(scanCursorC, nullPredC, opCtxC);
try {
- while (scanCursorC.hasNext()) {
- scanCursorC.next();
- ITupleReference frameTuple = scanCursorC.getTuple();
+ while (scanCursorC.hasNext()) {
+ scanCursorC.next();
+ ITupleReference frameTuple = scanCursorC.getTuple();
String rec = secondaryCmp.printTuple(frameTuple, ordersDesc.getFields());
System.out.println(rec);
- }
+ }
} catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace();
} finally {
- scanCursorC.close();
- }
+ scanCursorC.close();
+ }
bufferCache.closeFile(fileIdC);
System.out.println();
- }
+ }
}