Skip to content

Commit

Permalink
display u256 conversions in print_schema()
Browse files Browse the repository at this point in the history
  • Loading branch information
sslivkoff committed Aug 30, 2023
1 parent ed390ad commit a5c7b73
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
15 changes: 12 additions & 3 deletions crates/cli/src/summaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::time::SystemTime;
use thousands::Separable;

use cryo_freeze::{
BlockChunk, Chunk, ChunkData, Datatype, FileOutput, FreezeSummary, MultiQuery, Source, Table,
TransactionChunk,
BlockChunk, Chunk, ChunkData, ColumnType, Datatype, FileOutput, FreezeSummary, MultiQuery,
Source, Table, TransactionChunk,
};

const TITLE_R: u8 = 0;
Expand Down Expand Up @@ -123,7 +123,16 @@ fn print_schema(name: &Datatype, schema: &Table) {
print_header("schema for ".to_string() + name.dataset().name());
for column in schema.columns() {
if let Some(column_type) = schema.column_type(column) {
print_bullet(column, column_type.as_str());
if column_type == ColumnType::UInt256 {
for uint256_type in schema.u256_types.iter() {
print_bullet(
column.to_owned() + uint256_type.suffix().as_str(),
uint256_type.to_columntype().as_str(),
);
}
} else {
print_bullet(column, column_type.as_str());
}
}
}
println!();
Expand Down
33 changes: 33 additions & 0 deletions crates/freeze/src/types/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub enum U256Type {
Binary,
/// String representation
String,
/// F32 representation
F32,
/// F64 representation
F64,
/// Decimal128 representation
Expand All @@ -57,6 +59,34 @@ pub enum U256Type {
U64Low,
}

impl U256Type {
/// convert U256Type to Columntype
pub fn to_columntype(&self) -> ColumnType {
match self {
U256Type::Binary => ColumnType::Binary,
U256Type::String => ColumnType::String,
U256Type::F32 => ColumnType::Float32,
U256Type::F64 => ColumnType::Float64,
U256Type::Decimal128 => ColumnType::Decimal128,
U256Type::U64High => ColumnType::UInt64,
U256Type::U64Low => ColumnType::UInt64,
}
}

/// get column name suffix of U256Type
pub fn suffix(&self) -> String {
match self {
U256Type::Binary => "_binary".to_string(),
U256Type::String => "_string".to_string(),
U256Type::F32 => "_f32".to_string(),
U256Type::F64 => "_f64".to_string(),
U256Type::U64High => "_u64_high".to_string(),
U256Type::U64Low => "_u64_low".to_string(),
U256Type::Decimal128 => "_decimal128".to_string(),
}
}
}

/// datatype of column
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ColumnType {
Expand All @@ -70,6 +100,8 @@ pub enum ColumnType {
Int32,
/// Int64 column type
Int64,
/// Float32 column type
Float32,
/// Float64 column type
Float64,
/// Decimal128 column type
Expand All @@ -91,6 +123,7 @@ impl ColumnType {
ColumnType::UInt256 => "uint256",
ColumnType::Int32 => "int32",
ColumnType::Int64 => "int64",
ColumnType::Float32 => "float32",
ColumnType::Float64 => "float64",
ColumnType::Decimal128 => "decimal128",
ColumnType::String => "string",
Expand Down

0 comments on commit a5c7b73

Please sign in to comment.