Skip to content

Commit a0cde97

Browse files
Merge pull request #50 from JakeRoggenbuck/fix-out-of-bounds
Fix out of bounds
2 parents 90e0b2f + bbfc8a0 commit a0cde97

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

python/lstore/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from lstore.table import Table, Record
22
from lstore.index import Index
3-
from typing import Any
3+
from typing import Any, List
44
from .lstore import hello_from_rust, RDatabase, RQuery
55

66

@@ -46,7 +46,7 @@ def insert(self, *columns):
4646
"""
4747

4848
def select(
49-
self, search_key: Any, search_key_index: int, projected_columns_index: int
49+
self, search_key: Any, search_key_index: int, projected_columns_index: List[int]
5050
):
5151
return self.rquery.select(search_key, search_key_index, projected_columns_index)
5252

simple_tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
recs.append(rec)
1313

1414
for rec in recs:
15-
vals = query.select(rec.rid, 0, 0)
15+
vals = query.select(rec.rid, 0, [0])
1616
print(vals)

src/container.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,20 @@ impl TailContainer {
340340
addresses: addresses.clone(),
341341
}
342342
}
343+
344+
pub fn read_record(&self, record: Record) -> Vec<u64> {
345+
let mut values = Vec::<u64>::new();
346+
347+
let addrs = record.addresses.lock().unwrap();
348+
let addrs_clone = addrs.clone();
349+
for addr in addrs_clone {
350+
let a = addr.page.lock().unwrap();
351+
let b = a.read(addr.offset as usize);
352+
values.push(b.expect("Value should be there"));
353+
}
354+
355+
values
356+
}
343357
}
344358

345359
#[cfg(test)]
@@ -373,6 +387,17 @@ mod tests {
373387
assert_eq!(addresses.len(), 5); // 3 reserved + 2 data columns
374388
}
375389

390+
#[test]
391+
fn test_base_container_insert_513() {
392+
let mut container = BaseContainer::new(2);
393+
container.initialize();
394+
395+
for x in 0..513 {
396+
let values = vec![42, 43];
397+
let _record = container.insert_record(1, values);
398+
}
399+
}
400+
376401
#[test]
377402
#[should_panic(expected = "Number of values does not match number of columns")]
378403
fn test_base_container_insert_wrong_columns() {

src/page.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ impl PhysicalPage {
3030
}
3131

3232
pub fn write(&mut self, value: u64) {
33-
self.data[self.num_records as usize] = value;
34-
self.num_records += 1;
33+
if self.has_capacity() {
34+
self.data[self.num_records as usize] = value;
35+
self.num_records += 1;
36+
}
3537
}
3638

3739
pub fn read(&self, index: usize) -> Option<u64> {

src/query.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ impl RQuery {
2626
&mut self,
2727
search_key: i64,
2828
_search_key_index: i64,
29-
// TODO: I think this should be a vec, but I'm not sure
30-
projected_columns_index: i64,
29+
_projected_columns_index: Vec<i64>,
3130
) -> Vec<u64> {
3231
self.table.read(search_key as u64).unwrap()
3332
}

0 commit comments

Comments
 (0)