MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / createBTreeFile

Method createBTreeFile

src/java/simpledb/index/BTreeUtility.java:378–414  ·  view source on GitHub ↗

creates a non random B+ tree file for testing @param columns - number of columns @param rows - number of rows @param columnSpecification - optional column specification @param tuples - optional list of tuples to return @param keyField - the index of the key field @return a BTreeFile @throws IOExcept

(int columns, int rows,
                                            Map<Integer, Integer> columnSpecification,
                                            List<List<Integer>> tuples, int keyField)

Source from the content-addressed store, hash-verified

376 * @throws TransactionAbortedException
377 */
378 public static BTreeFile createBTreeFile(int columns, int rows,
379 Map<Integer, Integer> columnSpecification,
380 List<List<Integer>> tuples, int keyField)
381 throws IOException, DbException, TransactionAbortedException {
382 if (tuples != null) {
383 tuples.clear();
384 } else {
385 tuples = new ArrayList<>(rows);
386 }
387
388 // Fill the tuples list with generated values
389 for (int i = 0; i < rows; ++i) {
390 List<Integer> tuple = new ArrayList<>(columns);
391 for (int j = 0; j < columns; ++j) {
392 // Generate values, or use the column specification
393 Integer columnValue = null;
394 if (columnSpecification != null) columnValue = columnSpecification.get(j);
395 if (columnValue == null) {
396 columnValue = (i+1)*(j+1);
397 }
398 tuple.add(columnValue);
399 }
400 tuples.add(tuple);
401 }
402
403 // Convert the tuples list to a B+ tree file
404 File hFile = File.createTempFile("table", ".dat");
405 hFile.deleteOnExit();
406
407 File bFile = File.createTempFile("table_index", ".dat");
408 bFile.deleteOnExit();
409
410 Type[] typeAr = new Type[columns];
411 Arrays.fill(typeAr, Type.INT_TYPE);
412 return BTreeFileEncoder.convert(tuples, hFile, bFile, BufferPool.getPageSize(),
413 columns, typeAr, ',', keyField) ;
414 }
415
416 /** Opens a BTreeFile and adds it to the catalog.
417 *

Callers 2

indexIteratorMethod · 0.95
testReadPageMethod · 0.95

Calls 4

convertMethod · 0.95
getPageSizeMethod · 0.95
clearMethod · 0.80
getMethod · 0.80

Tested by 2

indexIteratorMethod · 0.76
testReadPageMethod · 0.76