Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Codetector1374 committed Jul 29, 2024
1 parent da6a424 commit 871f343
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/bin/page_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ struct Arguments {
#[arg(long)]
limit: Option<usize>,

#[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<PathBuf>,

#[arg(short = 'o', long = "output", help = "JSON file to write output to")]
Expand Down
1 change: 0 additions & 1 deletion src/bin/tablespace_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)? };
Expand Down
3 changes: 1 addition & 2 deletions src/innodb/charset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Error, Result};
use anyhow::{Error, Result};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InnoDBCharset {
Expand Down Expand Up @@ -138,5 +138,4 @@ impl InnoDBCharset {
InnoDBCharset::Utf8mb4 => 4,
}
}

}
4 changes: 2 additions & 2 deletions src/innodb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod charset;
pub mod page;
pub mod table;
pub mod charset;

use std::{
error::Error,
Expand All @@ -22,4 +22,4 @@ impl Display for InnoDBError {
}
}

impl Error for InnoDBError {}
impl Error for InnoDBError {}
2 changes: 1 addition & 1 deletion src/innodb/table/field.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
50 changes: 35 additions & 15 deletions src/innodb/table/mod.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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),
};

Expand All @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 7 additions & 4 deletions src/innodb/table/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableDefinition>,
Expand All @@ -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()
}
}

Expand Down Expand Up @@ -141,4 +144,4 @@ impl<'a> Row<'a> {

values
}
}
}

0 comments on commit 871f343

Please sign in to comment.