-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin writing unit test for Float/Double
- Loading branch information
1 parent
ec4c2f5
commit a5b234f
Showing
6 changed files
with
108 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE `float_sample` ( | ||
`text` char(20) NOT NULL, | ||
`single_f` float DEFAULT NULL, | ||
`double_f` double DEFAULT NULL, | ||
PRIMARY KEY (`text`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::{ | ||
fs::{read_to_string, File}, | ||
io::Read, | ||
path::PathBuf, sync::Arc, | ||
}; | ||
|
||
use innodb::innodb::{ | ||
buffer_manager::DummyBufferMangaer, charset::InnoDBCharset, page::{index::{record::RecordType, IndexPage}, Page, PageType}, table::{ | ||
field::{Field, FieldType}, row::Row, TableDefinition | ||
} | ||
}; | ||
|
||
#[test] | ||
#[ignore] | ||
fn test_parsing_table_with_floats() { | ||
let sql = read_to_string( | ||
PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
.join("test_data") | ||
.join("double_test_table.sql"), | ||
) | ||
.unwrap(); | ||
|
||
let reference = TableDefinition { | ||
name: String::from("float_sample"), | ||
cluster_columns: vec![Field::new( | ||
"text", | ||
FieldType::Text(20, InnoDBCharset::Utf8mb4), | ||
false, | ||
)], | ||
data_columns: vec![ | ||
Field::new("single_f", FieldType::Float, true), | ||
Field::new("double_f", FieldType::Double, true), | ||
], | ||
}; | ||
|
||
let parsed_table = Arc::new(TableDefinition::try_from_sql_statement(&sql).expect("Failed to parse SQL")); | ||
assert_eq!(parsed_table.as_ref(), &reference); | ||
|
||
let mut table_content_file = File::open( | ||
PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
.join("test_data") | ||
.join("float_sample.ibd"), | ||
) | ||
.expect("Can't open test table"); | ||
|
||
|
||
let buf_mgr = DummyBufferMangaer; | ||
let mut buffer = Vec::<u8>::new(); | ||
buffer.resize(16384, 0); | ||
|
||
loop { | ||
match table_content_file.read_exact(&mut buffer) { | ||
Ok(_) => { | ||
let page = Page::from_bytes(&buffer).unwrap(); | ||
if page.header.page_type == PageType::Index { | ||
let index = IndexPage::try_from_page(page).unwrap(); | ||
assert_eq!(index.index_header.index_id, 960, "Wrong Index ID"); | ||
let mut record = index.infimum().unwrap(); | ||
while record.next().is_some() { | ||
|
||
if record.header.record_type == RecordType::Conventional { | ||
let row = Row::try_from_record_and_table(&record, &parsed_table).expect("Failed to parse row"); | ||
let values = row.parse_values(&buf_mgr); | ||
} | ||
|
||
record = record.next().unwrap(); | ||
} | ||
assert_eq!(record.header.record_type, RecordType::Supremum); | ||
} | ||
} | ||
Err(_) => break, | ||
} | ||
} | ||
} |