From 871f343d4a9858fc7994cfe52838f9674e29ec3c Mon Sep 17 00:00:00 2001 From: Codetector Date: Mon, 29 Jul 2024 16:12:57 -0700 Subject: [PATCH] cleanup --- src/bin/page_explorer.rs | 6 ++++- src/bin/tablespace_sort.rs | 1 - src/innodb/charset.rs | 3 +-- src/innodb/mod.rs | 4 +-- src/innodb/table/field.rs | 2 +- src/innodb/table/mod.rs | 50 ++++++++++++++++++++++++++------------ src/innodb/table/row.rs | 11 ++++++--- 7 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/bin/page_explorer.rs b/src/bin/page_explorer.rs index 4054c3a..9a942fd 100644 --- a/src/bin/page_explorer.rs +++ b/src/bin/page_explorer.rs @@ -28,7 +28,11 @@ struct Arguments { #[arg(long)] limit: Option, - #[arg(short = 't', long = "table", help="Path to sql file containing create table statement to use as table definition for parsing")] + #[arg( + short = 't', + long = "table", + help = "Path to sql file containing create table statement to use as table definition for parsing" + )] table_def: Option, #[arg(short = 'o', long = "output", help = "JSON file to write output to")] diff --git a/src/bin/tablespace_sort.rs b/src/bin/tablespace_sort.rs index cacbc26..10fb673 100644 --- a/src/bin/tablespace_sort.rs +++ b/src/bin/tablespace_sort.rs @@ -25,7 +25,6 @@ impl Page { fn main() -> std::io::Result<()> { let args = Arguments::parse(); - let file = File::options().read(true).write(true).open(args.file)?; let mmap = unsafe { MmapMut::map_mut(&file)? }; diff --git a/src/innodb/charset.rs b/src/innodb/charset.rs index 0cfb24e..6a12fe5 100644 --- a/src/innodb/charset.rs +++ b/src/innodb/charset.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Error, Result}; +use anyhow::{Error, Result}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum InnoDBCharset { @@ -138,5 +138,4 @@ impl InnoDBCharset { InnoDBCharset::Utf8mb4 => 4, } } - } diff --git a/src/innodb/mod.rs b/src/innodb/mod.rs index f864e67..7744325 100644 --- a/src/innodb/mod.rs +++ b/src/innodb/mod.rs @@ -1,6 +1,6 @@ +pub mod charset; pub mod page; pub mod table; -pub mod charset; use std::{ error::Error, @@ -22,4 +22,4 @@ impl Display for InnoDBError { } } -impl Error for InnoDBError {} \ No newline at end of file +impl Error for InnoDBError {} diff --git a/src/innodb/table/field.rs b/src/innodb/table/field.rs index 09600b9..7cdc616 100644 --- a/src/innodb/table/field.rs +++ b/src/innodb/table/field.rs @@ -1,7 +1,7 @@ use std::u64; -use tracing::trace; use crate::innodb::charset::InnoDBCharset; +use tracing::trace; #[derive(Debug, Clone, PartialEq, Eq)] pub enum FieldType { diff --git a/src/innodb/table/mod.rs b/src/innodb/table/mod.rs index 5ed4f4d..a02ec1a 100644 --- a/src/innodb/table/mod.rs +++ b/src/innodb/table/mod.rs @@ -1,10 +1,9 @@ pub mod field; pub mod row; -use std::collections::{HashMap, HashSet}; +use std::collections::HashSet; use anyhow::{anyhow, Result}; -use bitvec::ptr::null; use field::{Field, FieldType}; use sqlparser::{ ast::{CharacterLength, ColumnOption, DataType, Statement, TableConstraint}, @@ -108,13 +107,11 @@ impl TableDefinition { DataType::MediumInt(_) => FieldType::MediumInt(true), DataType::Int(_) => FieldType::Int(true), DataType::BigInt(_) => FieldType::BigInt(true), - DataType::Custom(name, _) => { - match name.0[0].value.as_str() { - "mediumtext" => FieldType::Text((1<<24) - 1, charset), - "longtext" => FieldType::Text((1<<32) - 1, charset), - _ => unimplemented!("Custom: {} unhandled", name.0[0].value), - } - } + DataType::Custom(name, _) => match name.0[0].value.as_str() { + "mediumtext" => FieldType::Text((1 << 24) - 1, charset), + "longtext" => FieldType::Text((1 << 32) - 1, charset), + _ => unimplemented!("Custom: {} unhandled", name.0[0].value), + }, _ => unimplemented!("mapping of {:?}", column.data_type), }; @@ -137,7 +134,10 @@ impl TableDefinition { } } - assert!(table_def.primary_keys.len() > 0, "Table must have primary key"); + assert!( + table_def.primary_keys.len() > 0, + "Table must have primary key" + ); Ok(table_def) } else { @@ -220,13 +220,33 @@ mod test { ], non_key_fields: vec![ // name, type, nullable, signed, pk - Field::new("username", FieldType::Text(15, InnoDBCharset::Utf8mb4), false), - Field::new("password", FieldType::Text(255, InnoDBCharset::Utf8mb4), false), - Field::new("secmobicc", FieldType::Text(3, InnoDBCharset::Utf8mb4), false), - Field::new("secmobile", FieldType::Text(12, InnoDBCharset::Utf8mb4), false), + Field::new( + "username", + FieldType::Text(15, InnoDBCharset::Utf8mb4), + false, + ), + Field::new( + "password", + FieldType::Text(255, InnoDBCharset::Utf8mb4), + false, + ), + Field::new( + "secmobicc", + FieldType::Text(3, InnoDBCharset::Utf8mb4), + false, + ), + Field::new( + "secmobile", + FieldType::Text(12, InnoDBCharset::Utf8mb4), + false, + ), Field::new("email", FieldType::Text(255, InnoDBCharset::Utf8mb4), false), Field::new("myid", FieldType::Text(30, InnoDBCharset::Utf8mb4), false), - Field::new("myidkey", FieldType::Text(16, InnoDBCharset::Utf8mb4), false), + Field::new( + "myidkey", + FieldType::Text(16, InnoDBCharset::Utf8mb4), + false, + ), Field::new("regip", FieldType::Text(45, InnoDBCharset::Utf8mb4), false), Field::new("regdate", FieldType::Int(false), false), Field::new("lastloginip", FieldType::Int(true), false), diff --git a/src/innodb/table/row.rs b/src/innodb/table/row.rs index 4533a3a..6206254 100644 --- a/src/innodb/table/row.rs +++ b/src/innodb/table/row.rs @@ -5,7 +5,6 @@ use crate::innodb::page::index::record::{Record, RECORD_HEADER_FIXED_LENGTH}; use super::{field::FieldValue, TableDefinition}; use anyhow::Result; -use tracing::{debug, info}; pub struct Row<'a> { td: Arc, @@ -17,9 +16,13 @@ pub struct Row<'a> { record: Record<'a>, } -impl <'a> Debug for Row<'a> { +impl<'a> Debug for Row<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Row").field("null_map", &self.null_map).field("field_len_map", &self.field_len_map).field("record", &self.record).finish() + f.debug_struct("Row") + .field("null_map", &self.null_map) + .field("field_len_map", &self.field_len_map) + .field("record", &self.record) + .finish() } } @@ -141,4 +144,4 @@ impl<'a> Row<'a> { values } -} \ No newline at end of file +}