Skip to content

Commit

Permalink
Fix test & refactor FieldDef
Browse files Browse the repository at this point in the history
  • Loading branch information
mamcx committed Dec 8, 2023
1 parent b5dce48 commit eafa8c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/core/src/db/datastore/locking_tx_datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ mod tests {
IndexDef {
columns: NonEmpty::new(1.into()),
index_name: "name_idx".into(),
is_unique: true,
is_unique: false,
index_type: IndexType::BTree,
},
])
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/sql/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ impl From {

/// Returns all the fields matching `f` as a `Vec<FromField>`,
/// including the ones inside the joins.
pub fn find_field(&self, f: &str) -> Result<Vec<FieldDef>, RelationError> {
pub fn find_field<'a>(&'a self, f: &'a str) -> Result<Vec<FieldDef>, RelationError> {
let field = extract_table_field(f)?;
let fields = self.iter_tables().flat_map(|t| {
t.columns().iter().filter_map(|column| {
if column.col_name == field.field {
Some(FieldDef {
column: column.clone(),
table_name: field.table.unwrap_or(&t.table_name).to_string(),
column,
table_name: field.table.unwrap_or(&t.table_name),
})
} else {
None
Expand All @@ -195,7 +195,7 @@ impl From {

/// Checks if the field `named` matches exactly once in all the tables
/// including the ones inside the joins
pub fn resolve_field(&self, named: &str) -> Result<FieldDef, PlanError> {
pub fn resolve_field<'a>(&'a self, named: &'a str) -> Result<FieldDef, PlanError> {
let fields = self.find_field(named)?;

match fields.len() {
Expand Down
23 changes: 8 additions & 15 deletions crates/sats/src/db/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,27 +279,20 @@ impl From<&ColumnSchema> for ProductTypeElement {

/// For get the original `table_name` for where a [ColumnSchema] belongs.
#[derive(Debug, Clone)]
pub struct FieldDef {
pub column: ColumnSchema,
pub table_name: String,
pub struct FieldDef<'a> {
pub column: &'a ColumnSchema,
pub table_name: &'a str,
}

impl From<FieldDef> for FieldName {
impl From<FieldDef<'_>> for FieldName {
fn from(value: FieldDef) -> Self {
FieldName::named(&value.table_name, &value.column.col_name)
}
}

impl From<&FieldDef> for FieldName {
fn from(value: &FieldDef) -> Self {
FieldName::named(&value.table_name, &value.column.col_name)
FieldName::named(value.table_name, &value.column.col_name)
}
}

impl From<FieldDef> for ProductTypeElement {
impl From<FieldDef<'_>> for ProductTypeElement {
fn from(value: FieldDef) -> Self {
let f: FieldName = (&value).into();
ProductTypeElement::new(value.column.col_type, Some(f.to_string()))
ProductTypeElement::new(value.column.col_type.clone(), Some(value.column.col_name.clone()))
}
}

Expand Down Expand Up @@ -479,7 +472,7 @@ pub struct TableSchema {
pub table_type: StTableType,
pub table_access: StAccess,
/// Cache for `row_type_for_table` in the data store.
pub row_type: ProductType,
row_type: ProductType,
}

impl TableSchema {
Expand Down

0 comments on commit eafa8c6

Please sign in to comment.