Merge branch 'main' into 'validation-tests'

# Conflicts:
#   minisql/src/schema.rs
This commit is contained in:
Jindřich Moravec 2024-01-28 17:57:47 +01:00
commit 6ed6e5c816
11 changed files with 163 additions and 76 deletions

View file

@ -6,5 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bimap = "0.6.3"
bimap = { version = "0.6.3", features = ["serde"] }
serde = { version = "1.0.196", features = ["derive"] }
thiserror = "1.0.50"

View file

@ -1,7 +1,8 @@
use crate::type_system::{IndexableValue, Uuid};
use std::collections::{BTreeMap, HashSet};
use serde::{Deserialize, Serialize};
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ColumnIndex {
index: BTreeMap<IndexableValue, HashSet<Uuid>>,
}

View file

@ -2,11 +2,12 @@ use crate::type_system::Value;
use crate::operation::InsertionValues;
use std::ops::{Index, IndexMut};
use std::slice::SliceIndex;
use serde::{Deserialize, Serialize};
use crate::restricted_row::RestrictedRow;
pub type ColumnPosition = usize;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Row(Vec<Value>);
impl<Idx> Index<Idx> for Row

View file

@ -1,4 +1,5 @@
use std::collections::{BTreeMap, HashMap, HashSet};
use serde::{Deserialize, Serialize};
use crate::error::RuntimeError;
use crate::internals::column_index::ColumnIndex;
@ -8,7 +9,7 @@ use crate::schema::{ColumnName, TableSchema, TableName};
use crate::result::DbResult;
use crate::type_system::{IndexableValue, Uuid, Value};
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct Table {
schema: TableSchema,
rows: Rows, // TODO: Consider wrapping this in a lock. Also consider if we need to have the

View file

@ -4,6 +4,7 @@ use crate::internals::table::Table;
use crate::operation::{Operation, Condition};
use crate::result::DbResult;
use bimap::BiMap;
use serde::{Deserialize, Serialize};
use crate::restricted_row::RestrictedRow;
// Use `TablePosition` as index
@ -11,7 +12,7 @@ pub type Tables = Vec<Table>;
pub type TablePosition = usize;
// ==============Interpreter================
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct State {
table_name_position_mapping: BiMap<TableName, TablePosition>,
tables: Tables,

View file

@ -3,10 +3,11 @@ use crate::operation::{InsertionValues, ColumnSelection};
use crate::result::DbResult;
use crate::type_system::{DbType, IndexableValue, Uuid, Value};
use bimap::BiMap;
use serde::{Deserialize, Serialize};
// Note that it is nice to split metadata from the data because
// then you can give the metadata to the parser without giving it the data.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TableSchema {
table_name: TableName, // used for descriptive errors
primary_key: ColumnPosition,

View file

@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use crate::error::TypeConversionError;
// ==============Types================
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum DbType {
String,
Int,
@ -15,14 +16,14 @@ pub type Uuid = u64;
// TODO: What about nulls? I would rather not have that in SQL, it sucks.
// I would rather have non-nullable values by default,
// and something like an explicit Option type for nulls.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Value {
Number(f64), // TODO: Can't put floats as keys in maps, since they don't implement Eq. What to
// do?
Indexable(IndexableValue),
}
#[derive(Debug, Ord, Eq, Clone, PartialOrd, PartialEq)]
#[derive(Debug, Ord, Eq, Clone, PartialOrd, PartialEq, Serialize, Deserialize)]
pub enum IndexableValue {
String(String),
Int(u64),