Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename Datatype to DataType #278

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bindings/python/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use pyo3::{pyclass, pymethods};
use tonbo::record::{Datatype, Value, ValueDesc};
use tonbo::record::{DataType as TonboDataType, Value, ValueDesc};

use crate::datatype::DataType;

Expand Down Expand Up @@ -60,13 +60,13 @@ impl Display for Column {

impl From<Column> for ValueDesc {
fn from(col: Column) -> Self {
let datatype = Datatype::from(col.datatype);
let datatype = TonboDataType::from(col.datatype);
ValueDesc::new(col.name, datatype, col.nullable)
}
}
impl From<Column> for Value {
fn from(col: Column) -> Self {
let datatype = Datatype::from(col.datatype);
let datatype = TonboDataType::from(col.datatype);
Value::new(datatype, col.name, col.value, col.nullable)
}
}
50 changes: 25 additions & 25 deletions bindings/python/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use pyo3::{pyclass, PyObject, Python, ToPyObject};
use tonbo::record::Datatype;
use tonbo::record::DataType as TonboDataType;

#[pyclass]
#[derive(PartialEq, Clone)]
Expand Down Expand Up @@ -75,38 +75,38 @@ impl DataType {
}
}

impl From<DataType> for Datatype {
impl From<DataType> for TonboDataType {
fn from(datatype: DataType) -> Self {
match datatype {
DataType::UInt8 => Datatype::UInt8,
DataType::UInt16 => Datatype::UInt16,
DataType::UInt32 => Datatype::UInt32,
DataType::UInt64 => Datatype::UInt64,
DataType::Int8 => Datatype::Int8,
DataType::Int16 => Datatype::Int16,
DataType::Int32 => Datatype::Int32,
DataType::Int64 => Datatype::Int64,
DataType::String => Datatype::String,
DataType::Boolean => Datatype::Boolean,
DataType::Bytes => Datatype::Bytes,
DataType::UInt8 => TonboDataType::UInt8,
DataType::UInt16 => TonboDataType::UInt16,
DataType::UInt32 => TonboDataType::UInt32,
DataType::UInt64 => TonboDataType::UInt64,
DataType::Int8 => TonboDataType::Int8,
DataType::Int16 => TonboDataType::Int16,
DataType::Int32 => TonboDataType::Int32,
DataType::Int64 => TonboDataType::Int64,
DataType::String => TonboDataType::String,
DataType::Boolean => TonboDataType::Boolean,
DataType::Bytes => TonboDataType::Bytes,
}
}
}

impl From<&DataType> for Datatype {
impl From<&DataType> for TonboDataType {
fn from(datatype: &DataType) -> Self {
match datatype {
DataType::UInt8 => Datatype::UInt8,
DataType::UInt16 => Datatype::UInt16,
DataType::UInt32 => Datatype::UInt32,
DataType::UInt64 => Datatype::UInt64,
DataType::Int8 => Datatype::Int8,
DataType::Int16 => Datatype::Int16,
DataType::Int32 => Datatype::Int32,
DataType::Int64 => Datatype::Int64,
DataType::String => Datatype::String,
DataType::Boolean => Datatype::Boolean,
DataType::Bytes => Datatype::Bytes,
DataType::UInt8 => TonboDataType::UInt8,
DataType::UInt16 => TonboDataType::UInt16,
DataType::UInt32 => TonboDataType::UInt32,
DataType::UInt64 => TonboDataType::UInt64,
DataType::Int8 => TonboDataType::Int8,
DataType::Int16 => TonboDataType::Int16,
DataType::Int32 => TonboDataType::Int32,
DataType::Int64 => TonboDataType::Int64,
DataType::String => TonboDataType::String,
DataType::Boolean => TonboDataType::Boolean,
DataType::Bytes => TonboDataType::Bytes,
}
}
}
26 changes: 13 additions & 13 deletions bindings/python/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use pyo3::{
types::{PyBytes, PyDict, PyDictMethods},
Bound, Py, PyAny, Python,
};
use tonbo::record::{Datatype, Value};
use tonbo::record::{DataType as TonboDataType, Value};

use crate::{column::Column, datatype::DataType, range};

pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>) -> Bound<PyDict> {
let dict = PyDict::new_bound(py);
for (idx, col) in record.iter().enumerate() {
match &col.datatype {
Datatype::UInt8 => {
TonboDataType::UInt8 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -24,7 +24,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::UInt16 => {
TonboDataType::UInt16 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -36,7 +36,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::UInt32 => {
TonboDataType::UInt32 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -48,7 +48,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::UInt64 => {
TonboDataType::UInt64 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -60,7 +60,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::Int8 => {
TonboDataType::Int8 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -72,7 +72,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::Int16 => {
TonboDataType::Int16 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -84,7 +84,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::Int32 => {
TonboDataType::Int32 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -96,7 +96,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::Int64 => {
TonboDataType::Int64 => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -108,7 +108,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::String => {
TonboDataType::String => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -120,7 +120,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::Boolean => {
TonboDataType::Boolean => {
if idx == primary_key_index {
dict.set_item(
col.name.clone(),
Expand All @@ -132,7 +132,7 @@ pub(crate) fn to_dict(py: Python, primary_key_index: usize, record: Vec<Value>)
dict.set_item(col.name.clone(), value).unwrap();
}
}
Datatype::Bytes => {
TonboDataType::Bytes => {
if idx == primary_key_index {
let value = col.value.as_ref().downcast_ref::<Vec<u8>>().unwrap();
let v = PyBytes::new_bound(py, value);
Expand Down Expand Up @@ -183,7 +183,7 @@ pub(crate) fn to_key(

pub(crate) fn to_col(py: Python, col: &Column, key: Py<PyAny>) -> Value {
Value::new(
Datatype::from(&col.datatype),
TonboDataType::from(&col.datatype),
col.name.to_owned(),
to_key(py, &col.datatype, key),
col.nullable,
Expand Down
12 changes: 6 additions & 6 deletions examples/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fs, sync::Arc};
use fusio::path::Path;
use tonbo::{
executor::tokio::TokioExecutor,
record::{Datatype, DynRecord, DynSchema, Value, ValueDesc},
record::{DataType, DynRecord, DynSchema, Value, ValueDesc},
DbOption, DB,
};

Expand All @@ -13,8 +13,8 @@ async fn main() {

let schema = DynSchema::new(
vec![
ValueDesc::new("foo".into(), Datatype::String, false),
ValueDesc::new("bar".into(), Datatype::Int32, true),
ValueDesc::new("foo".into(), DataType::String, false),
ValueDesc::new("bar".into(), DataType::Int32, true),
],
0,
);
Expand All @@ -32,12 +32,12 @@ async fn main() {
txn.insert(DynRecord::new(
vec![
Value::new(
Datatype::String,
DataType::String,
"foo".into(),
Arc::new("hello".to_owned()),
false,
),
Value::new(Datatype::Int32, "bar".into(), Arc::new(1), true),
Value::new(DataType::Int32, "bar".into(), Arc::new(1), true),
],
0,
));
Expand All @@ -47,7 +47,7 @@ async fn main() {

db.get(
&Value::new(
Datatype::String,
DataType::String,
"foo".into(),
Arc::new("hello".to_owned()),
false,
Expand Down
10 changes: 5 additions & 5 deletions src/compaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pub(crate) mod tests {
immutable::{tests::TestSchema, Immutable},
mutable::Mutable,
},
record::{Datatype, DynRecord, DynSchema, Record, Schema, Value, ValueDesc},
record::{DataType, DynRecord, DynSchema, Record, Schema, Value, ValueDesc},
scope::Scope,
tests::Test,
timestamp::Timestamp,
Expand Down Expand Up @@ -750,7 +750,7 @@ pub(crate) mod tests {
let temp_dir = tempfile::tempdir().unwrap();
let manager = StoreManager::new(FsOptions::Local, vec![]).unwrap();
let schema = DynSchema::new(
vec![ValueDesc::new("id".to_owned(), Datatype::Int32, false)],
vec![ValueDesc::new("id".to_owned(), DataType::Int32, false)],
0,
);
let option = DbOption::new(
Expand All @@ -768,7 +768,7 @@ pub(crate) mod tests {
let mut batch1_data = vec![];
let mut batch2_data = vec![];
for i in 0..40 {
let col = Value::new(Datatype::Int32, "id".to_owned(), Arc::new(i), false);
let col = Value::new(DataType::Int32, "id".to_owned(), Arc::new(i), false);
if i % 4 == 0 {
continue;
}
Expand Down Expand Up @@ -806,11 +806,11 @@ pub(crate) mod tests {
.unwrap();
assert_eq!(
scope.min,
Value::new(Datatype::Int32, "id".to_owned(), Arc::new(2), false)
Value::new(DataType::Int32, "id".to_owned(), Arc::new(2), false)
);
assert_eq!(
scope.max,
Value::new(Datatype::Int32, "id".to_owned(), Arc::new(39), false)
Value::new(DataType::Int32, "id".to_owned(), Arc::new(39), false)
);
}

Expand Down
12 changes: 6 additions & 6 deletions src/inmem/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ mod tests {
use super::Mutable;
use crate::{
inmem::immutable::tests::TestSchema,
record::{test::StringSchema, Datatype, DynRecord, DynSchema, Record, Value, ValueDesc},
record::{test::StringSchema, DataType, DynRecord, DynSchema, Record, Value, ValueDesc},
tests::{Test, TestRef},
timestamp::Timestamped,
trigger::TriggerFactory,
Expand Down Expand Up @@ -388,8 +388,8 @@ mod tests {
let temp_dir = tempfile::tempdir().unwrap();
let schema = DynSchema::new(
vec![
ValueDesc::new("age".to_string(), Datatype::Int8, false),
ValueDesc::new("height".to_string(), Datatype::Int16, true),
ValueDesc::new("age".to_string(), DataType::Int8, false),
ValueDesc::new("height".to_string(), DataType::Int16, true),
],
0,
);
Expand All @@ -413,9 +413,9 @@ mod tests {
LogType::Full,
DynRecord::new(
vec![
Value::new(Datatype::Int8, "age".to_string(), Arc::new(1_i8), false),
Value::new(DataType::Int8, "age".to_string(), Arc::new(1_i8), false),
Value::new(
Datatype::Int16,
DataType::Int16,
"height".to_string(),
Arc::new(1236_i16),
true,
Expand All @@ -434,7 +434,7 @@ mod tests {
assert_eq!(
entry.key(),
&Timestamped::new(
Value::new(Datatype::Int8, "age".to_string(), Arc::new(1_i8), false),
Value::new(DataType::Int8, "age".to_string(), Arc::new(1_i8), false),
0_u32.into()
)
);
Expand Down
Loading
Loading