Skip to content

Commit d3427d2

Browse files
committed
chore: fix clippy warnings
1 parent 87a7d9f commit d3427d2

File tree

3 files changed

+82
-109
lines changed

3 files changed

+82
-109
lines changed

src/bin/argusdb.rs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::sync::Arc;
1515
use tokio::net::TcpListener;
1616
use tokio::sync::Mutex;
1717
use tracing::{Level, info, span};
18-
use tracing_subscriber;
1918

2019
use argusdb::db::DB;
2120
use argusdb::parser as argus_parser;
@@ -101,11 +100,7 @@ impl SimpleQueryHandler for ArgusHandler {
101100
Ok(s) => s,
102101
Err(e) => {
103102
return Ok(vec![Response::Error(Box::new(
104-
PgWireError::ApiError(Box::new(std::io::Error::new(
105-
std::io::ErrorKind::Other,
106-
e,
107-
)))
108-
.into(),
103+
PgWireError::ApiError(Box::new(std::io::Error::other(e))).into(),
109104
))]);
110105
}
111106
};
@@ -119,25 +114,17 @@ impl SimpleQueryHandler for ArgusHandler {
119114
} => {
120115
let count = documents.len();
121116
for doc in documents {
122-
db.insert(&collection, doc).map_err(|e| {
123-
PgWireError::ApiError(Box::new(std::io::Error::new(
124-
std::io::ErrorKind::Other,
125-
e,
126-
)))
127-
})?;
117+
db.insert(&collection, doc)
118+
.map_err(|e| PgWireError::ApiError(Box::new(std::io::Error::other(e))))?;
128119
}
129120
Ok(vec![Response::Execution(Tag::new(&format!(
130121
"INSERT 0 {}",
131122
count
132123
)))])
133124
}
134125
Statement::Select(plan) => {
135-
let iter = execute_plan(plan, &*db).map_err(|e| {
136-
PgWireError::ApiError(Box::new(std::io::Error::new(
137-
std::io::ErrorKind::Other,
138-
e,
139-
)))
140-
})?;
126+
let iter = execute_plan(plan, &db)
127+
.map_err(|e| PgWireError::ApiError(Box::new(std::io::Error::other(e))))?;
141128

142129
let mut rows_data = Vec::new();
143130
for (_, doc) in iter {
@@ -154,9 +141,7 @@ impl SimpleQueryHandler for ArgusHandler {
154141
let obj = first.as_object().unwrap();
155142
let fields: Vec<FieldInfo> = obj
156143
.keys()
157-
.map(|k| {
158-
FieldInfo::new(k.clone().into(), None, None, Type::JSON, FieldFormat::Text)
159-
})
144+
.map(|k| FieldInfo::new(k.clone(), None, None, Type::JSON, FieldFormat::Text))
160145
.collect();
161146
let fields = Arc::new(fields);
162147

@@ -180,21 +165,13 @@ impl SimpleQueryHandler for ArgusHandler {
180165
))])
181166
}
182167
Statement::CreateCollection { collection } => {
183-
db.create_collection(&collection).map_err(|e| {
184-
PgWireError::ApiError(Box::new(std::io::Error::new(
185-
std::io::ErrorKind::Other,
186-
e,
187-
)))
188-
})?;
168+
db.create_collection(&collection)
169+
.map_err(|e| PgWireError::ApiError(Box::new(std::io::Error::other(e))))?;
189170
Ok(vec![Response::Execution(Tag::new("CREATE COLLECTION"))])
190171
}
191172
Statement::DropCollection { collection } => {
192-
db.drop_collection(&collection).map_err(|e| {
193-
PgWireError::ApiError(Box::new(std::io::Error::new(
194-
std::io::ErrorKind::Other,
195-
e,
196-
)))
197-
})?;
173+
db.drop_collection(&collection)
174+
.map_err(|e| PgWireError::ApiError(Box::new(std::io::Error::other(e))))?;
198175
Ok(vec![Response::Execution(Tag::new("DROP COLLECTION"))])
199176
}
200177
Statement::ShowCollections => {

src/db.rs

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use std::path::PathBuf;
1010
use uuid::Uuid;
1111
use xorf::{BinaryFuse8, Filter};
1212

13+
type SourceIterator<'a> = Peekable<Box<dyn Iterator<Item = (String, Value)> + 'a>>;
14+
1315
struct MergedIterator<'a> {
14-
sources: Vec<Peekable<Box<dyn Iterator<Item = (String, Value)> + 'a>>>,
16+
sources: Vec<SourceIterator<'a>>,
1517
}
1618

1719
impl<'a> Iterator for MergedIterator<'a> {
@@ -238,7 +240,7 @@ impl Collection {
238240
}
239241

240242
fn scan(&self) -> impl Iterator<Item = (String, Value)> + '_ {
241-
let mut sources: Vec<Peekable<Box<dyn Iterator<Item = (String, Value)>>>> = Vec::new();
243+
let mut sources: Vec<SourceIterator> = Vec::new();
242244

243245
// 1. MemTable Iterator (Priority 0 - Highest)
244246
let mem_iter = self
@@ -290,18 +292,16 @@ impl Collection {
290292
let path = self.dir.join(format!("jstable-{}", i));
291293
if let Ok(mut iter) = jstable::JSTableIterator::new(path.to_str().unwrap()) {
292294
if iter.seek(start_offset).is_ok() {
293-
for res in iter {
294-
if let Ok((rid, doc)) = res {
295-
if rid == id {
296-
if doc.is_null() {
297-
return None; // Tombstone
298-
}
299-
return Some(doc);
300-
}
301-
if rid > id.to_string() {
302-
// Not found in this table (sorted)
303-
break;
295+
for (rid, doc) in iter.flatten() {
296+
if rid == id {
297+
if doc.is_null() {
298+
return None; // Tombstone
304299
}
300+
return Some(doc);
301+
}
302+
if rid.as_str() > id {
303+
// Not found in this table (sorted)
304+
break;
305305
}
306306
}
307307
}
@@ -344,63 +344,61 @@ impl DB {
344344
let mut collections = HashMap::new();
345345

346346
if let Ok(entries) = fs::read_dir(root_dir) {
347-
for entry in entries {
348-
if let Ok(entry) = entry {
349-
if entry.path().is_dir() {
350-
let dir_path = entry.path();
351-
352-
// Try to find collection name from JSTable-0
353-
let jstable_base_path = dir_path.join("jstable-0");
354-
let jstable_summary_path = dir_path.join("jstable-0.summary");
355-
let col_name = if jstable_summary_path.exists() {
356-
if let Ok(iter) =
357-
jstable::JSTableIterator::new(jstable_base_path.to_str().unwrap())
358-
{
359-
Some(iter.collection)
360-
} else {
361-
None
362-
}
347+
for entry in entries.flatten() {
348+
if entry.path().is_dir() {
349+
let dir_path = entry.path();
350+
351+
// Try to find collection name from JSTable-0
352+
let jstable_base_path = dir_path.join("jstable-0");
353+
let jstable_summary_path = dir_path.join("jstable-0.summary");
354+
let col_name = if jstable_summary_path.exists() {
355+
if let Ok(iter) =
356+
jstable::JSTableIterator::new(jstable_base_path.to_str().unwrap())
357+
{
358+
Some(iter.collection)
363359
} else {
364-
// Fallback to directory name (sanitized) if no jstable
365-
entry.file_name().to_str().map(|s| s.to_string())
366-
};
367-
368-
if let Some(name) = col_name {
369-
let mut collection = Collection::new(
370-
name.clone(),
371-
dir_path.clone(), // Clone dir_path for collection
372-
memtable_threshold,
373-
jstable_threshold,
374-
index_threshold,
375-
log_rotation_threshold,
376-
);
377-
378-
if log_rotation_threshold.is_some() {
379-
let log_path = dir_path.join("argus.log");
380-
let log_content =
381-
std::fs::read_to_string(&log_path).unwrap_or_default();
382-
for line in log_content.lines() {
383-
if line.is_empty() {
384-
continue;
385-
}
386-
if let Ok(entry) = serde_json::from_str::<LogEntry>(line) {
387-
match entry.op {
388-
Operation::Insert { id, doc } => {
389-
collection.memtable.insert(id, doc);
390-
}
391-
Operation::Update { id, doc } => {
392-
collection.memtable.update(&id, doc);
393-
}
394-
Operation::Delete { id } => {
395-
collection.memtable.delete(&id);
396-
}
360+
None
361+
}
362+
} else {
363+
// Fallback to directory name (sanitized) if no jstable
364+
entry.file_name().to_str().map(|s| s.to_string())
365+
};
366+
367+
if let Some(name) = col_name {
368+
let mut collection = Collection::new(
369+
name.clone(),
370+
dir_path.clone(), // Clone dir_path for collection
371+
memtable_threshold,
372+
jstable_threshold,
373+
index_threshold,
374+
log_rotation_threshold,
375+
);
376+
377+
if log_rotation_threshold.is_some() {
378+
let log_path = dir_path.join("argus.log");
379+
let log_content =
380+
std::fs::read_to_string(&log_path).unwrap_or_default();
381+
for line in log_content.lines() {
382+
if line.is_empty() {
383+
continue;
384+
}
385+
if let Ok(entry) = serde_json::from_str::<LogEntry>(line) {
386+
match entry.op {
387+
Operation::Insert { id, doc } => {
388+
collection.memtable.insert(id, doc);
389+
}
390+
Operation::Update { id, doc } => {
391+
collection.memtable.update(&id, doc);
392+
}
393+
Operation::Delete { id } => {
394+
collection.memtable.delete(&id);
397395
}
398396
}
399397
}
400398
}
401-
402-
collections.insert(name, collection);
403399
}
400+
401+
collections.insert(name, collection);
404402
}
405403
}
406404
}

src/parser.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ struct ArgusDialect;
1313

1414
impl Dialect for ArgusDialect {
1515
fn is_identifier_start(&self, ch: char) -> bool {
16-
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_' || ch == '$'
16+
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' || ch == '$'
1717
}
1818

1919
fn is_identifier_part(&self, ch: char) -> bool {
20-
('a'..='z').contains(&ch)
21-
|| ('A'..='Z').contains(&ch)
22-
|| ('0'..='9').contains(&ch)
20+
ch.is_ascii_lowercase()
21+
|| ch.is_ascii_uppercase()
22+
|| ch.is_ascii_digit()
2323
|| ch == '_'
2424
|| ch == '$'
2525
}
@@ -110,14 +110,12 @@ fn convert_query(query: &ast::Query) -> Result<LogicalPlan, String> {
110110
let mut limit_val = None;
111111
let mut offset_val = None;
112112

113-
if let Some(limit_clause) = &query.limit_clause {
114-
if let LimitClause::LimitOffset { limit, offset, .. } = limit_clause {
115-
if let Some(l) = limit {
116-
limit_val = Some(parse_limit_expr(l)?);
117-
}
118-
if let Some(o) = offset {
119-
offset_val = Some(parse_limit_expr(&o.value)?);
120-
}
113+
if let Some(LimitClause::LimitOffset { limit, offset, .. }) = &query.limit_clause {
114+
if let Some(l) = limit {
115+
limit_val = Some(parse_limit_expr(l)?);
116+
}
117+
if let Some(o) = offset {
118+
offset_val = Some(parse_limit_expr(&o.value)?);
121119
}
122120
}
123121

0 commit comments

Comments
 (0)