Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Oct 26, 2020
1 parent 443e225 commit 1d12563
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
4 changes: 4 additions & 0 deletions example/options.blam
Expand Up @@ -8,6 +8,7 @@ table Exchanges {
table Accounts {
#[unique_key]
name: String,
#[foreign_key(Exchanges.name)
exchange: String,
}

Expand All @@ -33,9 +34,12 @@ table Spy {
}

table Txns {
#[foreign_key(Account.name)
account: String,
symbol: String,
#[foreign_key(Spy.date)
opening_date: Date,
#[foreign_key(Spy.date)
expiration_date: Date,
callput: String { "Call" | "Put" },
buysell: String { "Buy" | "Sell" },
Expand Down
45 changes: 40 additions & 5 deletions src/main.rs
Expand Up @@ -45,6 +45,8 @@ enum UniqueIndex {
struct JoinCriteria {
self_column: String,
other_column: String,
self_name: String,
other_name: String,
}

struct SelectCriteria {
Expand Down Expand Up @@ -73,28 +75,28 @@ impl Table {
ColumnData::Integer(ref key_column) => {
let mut index = BTreeMap::new();
for (row_idx, key) in key_column.iter().enumerate() {
index.insert(key.clone(), row_idx);
assert!(index.insert(key.clone(), row_idx).is_none());
}
UniqueIndex::Integer(index)
}
ColumnData::Float(ref key_column) => {
let mut index = BTreeMap::new();
for (row_idx, key) in key_column.iter().enumerate() {
index.insert(FloatOrd(key.clone()), row_idx);
assert!(index.insert(FloatOrd(key.clone()), row_idx).is_none());
}
UniqueIndex::Float(index)
}
ColumnData::String(ref key_column) => {
let mut index = BTreeMap::new();
for (row_idx, key) in key_column.iter().enumerate() {
index.insert(key.clone(), row_idx);
assert!(index.insert(key.clone(), row_idx).is_none());
}
UniqueIndex::String(index)
}
ColumnData::Date(ref key_column) => {
let mut index = BTreeMap::new();
for (row_idx, key) in key_column.iter().enumerate() {
index.insert(key.clone(), row_idx);
assert!(index.insert(key.clone(), row_idx).is_none());
}
UniqueIndex::Date(index)
}
Expand All @@ -121,7 +123,40 @@ impl Table {
let join_self_column = self.columns.get(join_self_column_idx).expect("self_idx");
let join_other_column = self.columns.get(join_other_column_idx).expect("other_idx");

panic!()
assert!(join_other_column.unique_key);

let mut rows = 0;
let mut old_columns = Vec::new();
let mut new_columns = Vec::new();
let mut name_to_idx = BTreeMap::new();
let mut unique_indexes = BTreeMap::new();

for column in &self.columns {
let table_name = &crit.self_name;
let column_name = format!("{}.{}", table_name, column.name);
let new_column = Column {
name: column_name,
data: column.data.clone(),
unique_key: column.unique_key,
};

old_columns.push(new_column);

if column.unique_key {
panic!()
}
}

old_columns.extend(new_columns.into_iter());

let columns = old_columns;

Table {
rows,
columns,
name_to_idx,
unique_indexes,
}
}

fn select(&self, crit: SelectCriteria) -> Table { panic!() }
Expand Down

0 comments on commit 1d12563

Please sign in to comment.