Skip to content

Commit

Permalink
fix cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
phiresky committed Jul 17, 2022
1 parent 8aa283a commit 0ae1335
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn zstd_compress_fn<'a>(
ValueRef::Null => None,
ValueRef::Blob(d) => Some(Arc::new(wrap_encoder_dict(d.to_vec(), level))),
ValueRef::Integer(_) => Some(
encoder_dict_from_ctx(&ctx, arg_dict, level)
encoder_dict_from_ctx(ctx, arg_dict, level)
.context("loading dictionary from int")?,
),
other => anyhow::bail!(
Expand Down Expand Up @@ -139,7 +139,7 @@ pub(crate) fn zstd_decompress_fn<'a>(
ValueRef::Null => None,
ValueRef::Blob(d) => Some(Arc::new(wrap_decoder_dict(d.to_vec()))),
ValueRef::Integer(_) => {
Some(decoder_dict_from_ctx(&ctx, arg_dict).context("load dict")?)
Some(decoder_dict_from_ctx(ctx, arg_dict).context("load dict")?)
}
other => anyhow::bail!(
"dict argument must be int or blob, got {}",
Expand All @@ -153,7 +153,7 @@ pub(crate) fn zstd_decompress_fn<'a>(
} else {
ctx.get(arg_is_compact).context("argument 'compact'")?
};
let dict_ref = dict.as_ref().map(|e| -> &DecoderDictionary { &e });
let dict_ref = dict.as_ref().map(|e| -> &DecoderDictionary { e });

zstd_decompress_inner(input_value, dict_ref, output_text, compact)
}
Expand All @@ -167,7 +167,7 @@ fn zstd_decompress_inner<'a>(
let vec = {
let out = Vec::new();
let mut decoder = match &dict {
Some(dict) => zstd::stream::write::Decoder::with_prepared_dictionary(out, &dict),
Some(dict) => zstd::stream::write::Decoder::with_prepared_dictionary(out, dict),
None => zstd::stream::write::Decoder::new(out),
}
.context("dict load doesn't work")?;
Expand Down
8 changes: 6 additions & 2 deletions src/dict_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub fn encoder_dict_from_ctx<'a>(
let db = unsafe { ctx.get_connection()? }; // SAFETY: This might be unsafe depending on how the connection is used. See https://github.com/rusqlite/rusqlite/issues/643#issuecomment-640181213
let db_handle_pointer = unsafe { db.handle() } as usize; // SAFETY: We're only getting the pointer as an int, not using the raw connection

let res = match DICTS.write().unwrap().entry((db_handle_pointer, id, level)) {
let mut dicts_write = DICTS.write().unwrap();
let entry = dicts_write.entry((db_handle_pointer, id, level));
let res = match entry {
lru_time_cache::Entry::Vacant(e) => e.insert({
log::debug!(
"loading encoder dictionary {} level {} (should only happen once per 10s)",
Expand Down Expand Up @@ -83,7 +85,9 @@ pub fn decoder_dict_from_ctx<'a>(
let id: i32 = ctx.get(arg_index)?;
let db = unsafe { ctx.get_connection()? }; // SAFETY: This might be unsafe depending on how the connection is used. See https://github.com/rusqlite/rusqlite/issues/643#issuecomment-640181213
let db_handle_pointer = unsafe { db.handle() } as usize; // SAFETY: We're only getting the pointer as an int, not using the raw connection
let res = match DICTS.write().unwrap().entry((db_handle_pointer, id)) {
let mut dicts_write = DICTS.write().unwrap();
let entry = dicts_write.entry((db_handle_pointer, id));
let res = match entry {
lru_time_cache::Entry::Vacant(e) => e.insert({
log::debug!(
"loading decoder dictionary {} (should only happen once per 10s)",
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ pub fn load_with_loglevel(
default_log_level: LogLevel,
) -> anyhow::Result<()> {
init_logging(default_log_level);
crate::add_functions::add_functions(&connection)
crate::add_functions::add_functions(connection)
}
36 changes: 18 additions & 18 deletions src/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ pub struct TransparentCompressConfig {

fn pretty_bytes(bytes: i64) -> String {
if bytes >= 1_000_000_000 {
return format!("{:.2}GB", bytes as f64 / 1e9);
format!("{:.2}GB", bytes as f64 / 1e9)
} else if bytes >= 1_000_000 {
return format!("{:.2}MB", bytes as f64 / 1e6);
format!("{:.2}MB", bytes as f64 / 1e6)
} else if bytes >= 1_000 {
return format!("{:.2}kB", bytes as f64 / 1e3);
format!("{:.2}kB", bytes as f64 / 1e3)
} else {
return format!("{}B", bytes);
format!("{}B", bytes)
}
}

Expand Down Expand Up @@ -199,7 +199,7 @@ pub fn zstd_enable_transparent<'a>(ctx: &Context) -> anyhow::Result<ToSqlOutput<
);
log::debug!("dict_id_columns query {:?}", query);
db.prepare(&query)?
.query_map(params![], |row| Ok(row.get("from")?))
.query_map(params![], |row| row.get("from"))
.context("Could not get dicts ids info")?
.collect::<Result<Vec<String>, _>>()?
} else {
Expand All @@ -225,7 +225,7 @@ pub fn zstd_enable_transparent<'a>(ctx: &Context) -> anyhow::Result<ToSqlOutput<
if table_already_enabled {
&new_table_name
} else {
&table_name
table_name
}
))?
.query_map(params![], |row| {
Expand Down Expand Up @@ -279,7 +279,7 @@ pub fn zstd_enable_transparent<'a>(ctx: &Context) -> anyhow::Result<ToSqlOutput<
let query = format!(
"select ({}) as dict_chooser from {} limit 1",
config.dict_chooser,
escape_sqlite_identifier(&table_name)
escape_sqlite_identifier(table_name)
);
// small sanity check of chooser statement
db.query_row(&query, params![], |row| row.get::<_, String>(0))
Expand All @@ -291,7 +291,7 @@ pub fn zstd_enable_transparent<'a>(ctx: &Context) -> anyhow::Result<ToSqlOutput<
// can't use prepared statement at these positions
if !table_already_enabled {
let rename_query =
format_sqlite!("alter table {} rename to {}", &table_name, &new_table_name);
format_sqlite!("alter table {} rename to {}", table_name, &new_table_name);
log::debug!("[run] {}", &rename_query);
db.execute(&rename_query, params![])
.context("Could not rename table")?;
Expand Down Expand Up @@ -435,7 +435,7 @@ fn create_or_replace_view(
) -> anyhow::Result<()> {
if table_already_enabled {
// this drops the existing triggers as well
let dropview_query = format!(r#"drop view {}"#, escape_sqlite_identifier(&table_name));
let dropview_query = format!(r#"drop view {}"#, escape_sqlite_identifier(table_name));
log::debug!("[run] {}", &dropview_query);
db.execute(&dropview_query, params![])
.context("Could not drop view")?;
Expand Down Expand Up @@ -473,9 +473,9 @@ fn create_or_replace_view(
select {}
from {}
"#,
escape_sqlite_identifier(&table_name),
escape_sqlite_identifier(table_name),
select_columns_escaped,
escape_sqlite_identifier(&internal_table_name)
escape_sqlite_identifier(internal_table_name)
);
log::debug!("[run] {}", &createview_query);
db.execute(&createview_query, params![])
Expand Down Expand Up @@ -530,8 +530,8 @@ fn create_insert_trigger(
end;
",
escape_sqlite_identifier(&trigger_name),
escape_sqlite_identifier(&table_name),
escape_sqlite_identifier(&internal_table_name),
escape_sqlite_identifier(table_name),
escape_sqlite_identifier(internal_table_name),
columns_selection.join(", "),
insert_selection.join(",\n"),
);
Expand Down Expand Up @@ -559,8 +559,8 @@ fn create_delete_trigger(
end;
",
trg_name = escape_sqlite_identifier(&trigger_name),
view = escape_sqlite_identifier(&table_name),
backing_table = escape_sqlite_identifier(&internal_table_name),
view = escape_sqlite_identifier(table_name),
backing_table = escape_sqlite_identifier(internal_table_name),
primary_key_condition = primary_key_condition
);
log::debug!("[run] {}", &deletetrigger_query);
Expand Down Expand Up @@ -606,8 +606,8 @@ fn create_update_triggers(
end;
",
trg_name = escape_sqlite_identifier(&trigger_name),
view_name = escape_sqlite_identifier(&table_name),
backing_table = escape_sqlite_identifier(&internal_table_name),
view_name = escape_sqlite_identifier(table_name),
backing_table = escape_sqlite_identifier(internal_table_name),
upd_col = escape_sqlite_identifier(&col.name),
update = update,
primary_key_condition = primary_key_condition
Expand All @@ -621,7 +621,7 @@ fn create_update_triggers(

fn get_configs(db: &rusqlite::Connection) -> Result<Vec<TransparentCompressConfig>, anyhow::Error> {
// if the table `_zstd_configs` does not exist yet, transparent compression hasn't been used yet, so return an empty array
if !check_table_exists(&db, "_zstd_configs") {
if !check_table_exists(db, "_zstd_configs") {
return Ok(vec![]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn format_blob(b: ValueRef) -> String {
/// see https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted
///
pub fn escape_sqlite_identifier(identifier: &str) -> String {
format!("`{}`", identifier.replace("`", "``"))
format!("`{}`", identifier.replace('`', "``"))
}

/**
Expand Down

0 comments on commit 0ae1335

Please sign in to comment.