Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions python/lstore/query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from lstore.table import Table, Record
from lstore.index import Index
from typing import Any
from .lstore import hello_from_rust, RDatabase, Query
from .lstore import hello_from_rust, RDatabase, RQuery


class Query:
Expand All @@ -14,6 +14,7 @@ class Query:

def __init__(self, table: Table):
self.table = table
self.rquery = RQuery(table)

"""
# internal Method
Expand All @@ -23,7 +24,7 @@ def __init__(self, table: Table):
"""

def delete(self, primary_key: int):
pass
self.rquery.delete(primary_key)

"""
# Insert a record with specified columns
Expand All @@ -32,8 +33,7 @@ def delete(self, primary_key: int):
"""

def insert(self, *columns):
schema_encoding = "0" * self.table.num_columns
pass
self.rquery.insert(columns)

"""
# Read matching record with specified search key
Expand All @@ -48,7 +48,7 @@ def insert(self, *columns):
def select(
self, search_key: Any, search_key_index: int, projected_columns_index: int
):
pass
self.rquery.select(search_key, search_key_index, projected_columns_index)

"""
# Read matching record with specified search key
Expand Down
10 changes: 6 additions & 4 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl PageRange {
}
}

fn write(&mut self, new_rid: u64, values: Vec<u64>) {
// self.base_container.insert(new_rid, values);
fn write(&mut self, new_rid: u64, values: Vec<u64>) -> Record {
self.base_container.insert_record(new_rid, values)
}

fn read(&self, rid: u64) -> Option<Vec<u64>> {
Expand All @@ -50,6 +50,7 @@ pub struct RecordAddress {
pub offset: u64,
}

#[pyclass]
pub struct Record {
pub rid: u64,
pub addresses: Arc<Mutex<Vec<RecordAddress>>>,
Expand All @@ -76,9 +77,10 @@ pub struct RTable {
}

impl RTable {
pub fn write(&mut self, values: Vec<u64>) {
self.page_range.write(self.num_records, values);
pub fn write(&mut self, values: Vec<u64>) -> Record {
let rec = self.page_range.write(self.num_records, values);
self.num_records += 1;
return rec;
}

pub fn read(&self, rid: u64) -> Option<Vec<u64>> {
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use database::{RDatabase, RTable};
use database::{RDatabase, RTable, Record};
use pyo3::prelude::*;
use query::Query;
use query::RQuery;

pub mod container;
pub mod database;
Expand All @@ -19,8 +19,9 @@ fn hello_from_rust() -> PyResult<String> {
#[pymodule]
fn lstore(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<RDatabase>()?;
m.add_class::<Query>()?;
m.add_class::<RQuery>()?;
m.add_class::<RTable>()?;
m.add_class::<Record>()?;
m.add_function(wrap_pyfunction!(hello_from_rust, m)?)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pyo3::prelude::*;
static MAX_SIZE_RECORD: u64 = 512;

#[pyclass]
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct PhysicalPage {
pub data: [u64; 512],
pub num_records: u64,
Expand Down
14 changes: 8 additions & 6 deletions src/query.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
use super::database::RTable;
use super::database::{RTable, Record};
use pyo3::prelude::*;
use std::iter::zip;

#[pyclass]
pub struct Query {
pub struct RQuery {
pub table: RTable,
}

impl Query {
#[pymethods]
impl RQuery {
#[new]
fn new(table: RTable) -> Self {
Query { table }
RQuery { table }
}

fn delete(&mut self, primary_key: i64) {
// Delete the value in each column where the id == primary_key
// i.e. delete the whole record
}

fn insert(&mut self, values: Vec<u64>) {
self.table.write(values);
fn insert(&mut self, values: Vec<u64>) -> Record {
self.table.write(values)
}

fn select(
Expand Down