Skip to content

Commit

Permalink
Update Rust toolchain version to 1.76 (gluesql#1487)
Browse files Browse the repository at this point in the history
* Update Rust toolchain version to 1.76
* Make clippy happy
  • Loading branch information
panarch authored May 15, 2024
1 parent c4f905e commit 23132bb
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 107 deletions.
5 changes: 1 addition & 4 deletions core/src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ impl Select {
let group_by = if group_by.is_empty() {
"".to_owned()
} else {
format!(
"GROUP BY {}",
group_by.iter().map(|item| to_sql(item)).join(", ")
)
format!("GROUP BY {}", group_by.iter().map(to_sql).join(", "))
};

let having = match having {
Expand Down
5 changes: 2 additions & 3 deletions core/src/ast_builder/index_item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ impl<'a> Prebuild<IndexItem> for IndexItemNode<'a> {
} => {
let (index_operator, expr) = cmp_expr.unzip();
let expr_result: Option<Expr> = expr.map(ExprNode::try_into).transpose()?;
let cmp_expr_result: Option<(IndexOperator, Expr)> = index_operator
.zip(expr_result)
.map(|(index_operator, expr)| (index_operator, expr));
let cmp_expr_result: Option<(IndexOperator, Expr)> =
index_operator.zip(expr_result);

Ok(IndexItem::NonClustered {
name,
Expand Down
22 changes: 0 additions & 22 deletions core/src/data/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,6 @@ impl Ord for Key {

impl PartialOrd for Key {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (self, other) {
(Key::I8(l), Key::I8(r)) => Some(l.cmp(r)),
(Key::I16(l), Key::I16(r)) => Some(l.cmp(r)),
(Key::I32(l), Key::I32(r)) => Some(l.cmp(r)),
(Key::I64(l), Key::I64(r)) => Some(l.cmp(r)),
(Key::U8(l), Key::U8(r)) => Some(l.cmp(r)),
(Key::U16(l), Key::U16(r)) => Some(l.cmp(r)),
(Key::U32(l), Key::U32(r)) => Some(l.cmp(r)),
(Key::U64(l), Key::U64(r)) => Some(l.cmp(r)),
(Key::U128(l), Key::U128(r)) => Some(l.cmp(r)),
(Key::Decimal(l), Key::Decimal(r)) => Some(l.cmp(r)),
(Key::Bool(l), Key::Bool(r)) => Some(l.cmp(r)),
(Key::Str(l), Key::Str(r)) => Some(l.cmp(r)),
(Key::Bytea(l), Key::Bytea(r)) => Some(l.cmp(r)),
(Key::Inet(l), Key::Inet(r)) => Some(l.cmp(r)),
(Key::Date(l), Key::Date(r)) => Some(l.cmp(r)),
(Key::Timestamp(l), Key::Timestamp(r)) => Some(l.cmp(r)),
(Key::Time(l), Key::Time(r)) => Some(l.cmp(r)),
(Key::Interval(l), Key::Interval(r)) => l.partial_cmp(r),
(Key::Uuid(l), Key::Uuid(r)) => Some(l.cmp(r)),
_ => None,
};
Some(self.cmp(other))
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Schema {
})
.collect::<Result<Vec<_>>>()?;

let create_table = statements.get(0).ok_or(SchemaParseError::CannotParseDDL)?;
let create_table = statements.first().ok_or(SchemaParseError::CannotParseDDL)?;
let create_table = translate(create_table)?;

match create_table {
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/value/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ mod tests {

#[test]
fn evaluate_cmp_with_literal() {
let num = |n| Literal::Number(Cow::Owned(BigDecimal::try_from(n).unwrap()));
let num = |n| Literal::Number(Cow::Owned(BigDecimal::from(n)));
let text = |v: &str| Literal::Text(Cow::Owned(v.to_owned()));

let test = |value: Value, literal, expected| {
Expand Down
4 changes: 2 additions & 2 deletions core/src/data/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ impl Value {
}
let from = &String::from(self);
let sub = &String::from(sub_val);
let position = str_position(&from[(start - 1) as usize..].to_owned(), sub) as i64;
let position = str_position(&from[(start - 1) as usize..], sub) as i64;
let position = match position {
0 => 0,
_ => position + start - 1,
Expand All @@ -887,7 +887,7 @@ impl Value {
}
}

fn str_position(from_str: &String, sub_str: &String) -> usize {
fn str_position(from_str: &str, sub_str: &str) -> usize {
if from_str.is_empty() || sub_str.is_empty() {
return 0;
}
Expand Down
37 changes: 15 additions & 22 deletions core/src/executor/aggregate/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,30 +222,23 @@ impl<'a, T: GStore> State<'a, T> {
values, contexts, ..
} = self;

stream::iter(
values
.into_iter()
.map(|(k, v)| (k, v))
.chunks(size)
.into_iter()
.enumerate(),
)
.then(|(i, entries)| {
let next = contexts.get(i).map(Rc::clone);
stream::iter(values.into_iter().chunks(size).into_iter().enumerate())
.then(|(i, entries)| {
let next = contexts.get(i).map(Rc::clone);

async move {
let aggregated = stream::iter(entries)
.then(|((_, aggr), (_, aggr_value))| async move {
aggr_value.export().await.map(|value| (aggr, value))
})
.try_collect::<HashMap<&'a Aggregate, Value>>()
.await?;
async move {
let aggregated = stream::iter(entries)
.then(|((_, aggr), (_, aggr_value))| async move {
aggr_value.export().await.map(|value| (aggr, value))
})
.try_collect::<HashMap<&'a Aggregate, Value>>()
.await?;

Ok((Some(aggregated), next))
}
})
.try_collect::<Vec<(Option<ValuesMap<'a>>, Option<Rc<RowContext<'a>>>)>>()
.await
Ok((Some(aggregated), next))
}
})
.try_collect::<Vec<(Option<ValuesMap<'a>>, Option<Rc<RowContext<'a>>>)>>()
.await
}

pub async fn accumulate(
Expand Down
16 changes: 6 additions & 10 deletions core/src/executor/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async fn join<'a, T: GStore>(
storage,
table_alias,
filter_context.as_ref().map(Rc::clone),
Some(&project_context).map(Rc::clone),
Some(Rc::clone(&project_context)),
where_clause,
row,
)
Expand All @@ -166,7 +166,7 @@ async fn join<'a, T: GStore>(
let rows = stream::iter(rows)
.filter_map(|row| {
let filter_context = filter_context.as_ref().map(Rc::clone);
let project_context = Some(&project_context).map(Rc::clone);
let project_context = Some(Rc::clone(&project_context));

async {
check_where_clause(
Expand Down Expand Up @@ -248,14 +248,10 @@ impl<'a> JoinExecutor<'a> {
filter_context,
));

let hash_key: Key = evaluate(
storage,
Some(&filter_context).map(Rc::clone),
None,
key_expr,
)
.await?
.try_into()?;
let hash_key: Key =
evaluate(storage, Some(Rc::clone(&filter_context)), None, key_expr)
.await?
.try_into()?;

if matches!(hash_key, Key::None) {
return Ok(None);
Expand Down
3 changes: 1 addition & 2 deletions core/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl AlterTable for MockStorage {}
impl Index for MockStorage {}
impl IndexMut for MockStorage {}
impl Transaction for MockStorage {}
impl Metadata for MockStorage {}

#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -158,5 +159,3 @@ mod tests {
assert!(matches!(block_on(storage.fetch_schema("Foo")), Ok(None)));
}
}

impl Metadata for MockStorage {}
2 changes: 1 addition & 1 deletion core/src/translate/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn translate_data_type(sql_data_type: &SqlDataType) -> Result<DataType> {
SqlDataType::Uuid => Ok(DataType::Uuid),
SqlDataType::Decimal(SqlExactNumberInfo::None) => Ok(DataType::Decimal),
SqlDataType::Custom(name, _idents) => {
let name = name.0.get(0).map(|v| v.value.to_uppercase());
let name = name.0.first().map(|v| v.value.to_uppercase());

match name.as_deref() {
Some("MAP") => Ok(DataType::Map),
Expand Down
6 changes: 3 additions & 3 deletions core/src/translate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub fn translate(sql_statement: &SqlStatement) -> Result<Statement> {
SqlStatement::ShowFunctions { filter: None } => {
Ok(Statement::ShowVariable(Variable::Functions))
}
SqlStatement::ShowVariable { variable } => match (variable.len(), variable.get(0)) {
SqlStatement::ShowVariable { variable } => match (variable.len(), variable.first()) {
(1, Some(keyword)) => match keyword.value.to_uppercase().as_str() {
"VERSION" => Ok(Statement::ShowVariable(Variable::Version)),
v => Err(TranslateError::UnsupportedShowVariableKeyword(v.to_owned()).into()),
Expand Down Expand Up @@ -280,7 +280,7 @@ pub fn translate_assignment(sql_assignment: &SqlAssignment) -> Result<Assignment

Ok(Assignment {
id: id
.get(0)
.first()
.ok_or(TranslateError::UnreachableEmptyIdent)?
.value
.to_owned(),
Expand All @@ -306,7 +306,7 @@ fn translate_object_name(sql_object_name: &SqlObjectName) -> Result<String> {
}

sql_object_name
.get(0)
.first()
.map(|v| v.value.to_owned())
.ok_or_else(|| TranslateError::UnreachableEmptyObject.into())
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/translate/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn translate_select(sql_select: &SqlSelect) -> Result<Select> {
return Err(TranslateError::SelectDistinctNotSupported.into());
}

let from = match from.get(0) {
let from = match from.first() {
Some(sql_table_with_joins) => translate_table_with_joins(sql_table_with_joins)?,
None => TableWithJoins {
relation: TableFactor::Series {
Expand Down Expand Up @@ -170,7 +170,7 @@ fn translate_table_factor(sql_table_factor: &SqlTableFactor) -> Result<TableFact
})
.collect::<Result<Vec<_>>>()?;

match translate_function_arg_exprs(function_arg_exprs)?.get(0) {
match translate_function_arg_exprs(function_arg_exprs)?.first() {
Some(expr) => Ok(translate_expr(expr)?),
None => Err(TranslateError::LackOfArgs.into()),
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.72"
channel = "1.76"
components = ["rustfmt", "clippy"]
1 change: 0 additions & 1 deletion storages/json-storage/src/store_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl StoreMut for JsonStorage {
.map_storage_err(JsonStorageError::TableDoesNotExist)?;

let file = OpenOptions::new()
.write(true)
.append(true)
.open(self.jsonl_path(&schema.table_name))
.map_storage_err()?;
Expand Down
30 changes: 14 additions & 16 deletions storages/sled-storage/src/alter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ impl AlterTable for SledStorage {
.iter()
.any(|ColumnDef { name, .. }| name == new_column_name)
{
return Err(
return Err(ConflictableTransactionError::Abort(
AlterTableError::AlreadyExistingColumn(new_column_name.to_owned()).into(),
)
.map_err(ConflictableTransactionError::Abort);
));
}

let i = column_defs
Expand Down Expand Up @@ -282,8 +281,9 @@ impl AlterTable for SledStorage {
{
let adding_column = column_def.name.to_owned();

return Err(AlterTableError::AlreadyExistingColumn(adding_column).into())
.map_err(ConflictableTransactionError::Abort);
return Err(ConflictableTransactionError::Abort(
AlterTableError::AlreadyExistingColumn(adding_column).into(),
));
}

let ColumnDef {
Expand All @@ -304,8 +304,9 @@ impl AlterTable for SledStorage {
}
(None, true) => Value::Null,
(None, false) => {
return Err(AlterTableError::DefaultValueRequired(column_def.clone()).into())
.map_err(ConflictableTransactionError::Abort);
return Err(ConflictableTransactionError::Abort(
AlterTableError::DefaultValueRequired(column_def.clone()).into(),
));
}
};

Expand All @@ -324,10 +325,9 @@ impl AlterTable for SledStorage {
let values = match row {
DataRow::Vec(values) => values,
DataRow::Map(_) => {
return Err(Error::StorageMsg(
return Err(ConflictableTransactionError::Abort(Error::StorageMsg(
"conflict - add_column failed: schemaless row found".to_owned(),
))
.map_err(ConflictableTransactionError::Abort);
)));
}
};
let row = values
Expand Down Expand Up @@ -439,10 +439,9 @@ impl AlterTable for SledStorage {
return Ok(TxPayload::Success);
}
(None, false) => {
return Err(
return Err(ConflictableTransactionError::Abort(
AlterTableError::DroppingColumnNotFound(column_name.to_owned()).into(),
)
.map_err(ConflictableTransactionError::Abort);
));
}
};

Expand All @@ -461,10 +460,9 @@ impl AlterTable for SledStorage {
let values = match row {
DataRow::Vec(values) => values,
DataRow::Map(_) => {
return Err(Error::StorageMsg(
return Err(ConflictableTransactionError::Abort(Error::StorageMsg(
"conflict - drop_column failed: schemaless row found".to_owned(),
))
.map_err(ConflictableTransactionError::Abort);
)));
}
};

Expand Down
10 changes: 6 additions & 4 deletions storages/sled-storage/src/index_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ impl IndexMut for SledStorage {
.map_err(ConflictableTransactionError::Abort)?;

if indexes.iter().any(|index| index.name == index_name) {
return Err(IndexError::IndexNameAlreadyExists(index_name.to_owned()).into())
.map_err(ConflictableTransactionError::Abort);
return Err(ConflictableTransactionError::Abort(
IndexError::IndexNameAlreadyExists(index_name.to_owned()).into(),
));
}

let index = SchemaIndex {
Expand Down Expand Up @@ -180,8 +181,9 @@ impl IndexMut for SledStorage {
let index = match index.into_iter().next() {
Some(index) => index,
None => {
return Err(IndexError::IndexNameDoesNotExist(index_name.to_owned()).into())
.map_err(ConflictableTransactionError::Abort);
return Err(ConflictableTransactionError::Abort(
IndexError::IndexNameDoesNotExist(index_name.to_owned()).into(),
));
}
};

Expand Down
20 changes: 9 additions & 11 deletions storages/sled-storage/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ pub fn acquire(
autocommit,
} => (*txid, *created_at, *autocommit),
State::Idle => {
return Err(Error::StorageMsg(
return Err(ConflictableTransactionError::Abort(Error::StorageMsg(
"conflict - cannot acquire lock from idle state".to_owned(),
))
.map_err(ConflictableTransactionError::Abort);
)));
}
};

Expand All @@ -135,24 +134,23 @@ pub fn acquire(
.as_millis();

if tx_timeout.map(|tx_timeout| now - created_at >= tx_timeout) == Some(true) {
return Err(Error::StorageMsg(
return Err(ConflictableTransactionError::Abort(Error::StorageMsg(
"acquire failed - expired transaction has used (timeout)".to_owned(),
))
.map_err(ConflictableTransactionError::Abort);
)));
} else if gc_txid.is_some() && Some(txid) <= gc_txid {
return Err(Error::StorageMsg(
return Err(ConflictableTransactionError::Abort(Error::StorageMsg(
"acquire failed - expired transaction has used (txid)".to_owned(),
))
.map_err(ConflictableTransactionError::Abort);
)));
}

let txid = match lock_txid {
Some(lock_txid) => {
if tx_timeout.map(|tx_timeout| now - lock_created_at >= tx_timeout) == Some(true) {
return Ok(LockAcquired::RollbackAndRetry { lock_txid });
} else if txid != lock_txid {
return Err(Error::StorageMsg("database is locked".to_owned()))
.map_err(ConflictableTransactionError::Abort);
return Err(ConflictableTransactionError::Abort(Error::StorageMsg(
"database is locked".to_owned(),
)));
}

txid
Expand Down
Loading

0 comments on commit 23132bb

Please sign in to comment.