Skip to content

Commit

Permalink
Merge branch '3.0' into feat/new-libtaos-with-ws
Browse files Browse the repository at this point in the history
  • Loading branch information
qevolg committed Dec 30, 2024
2 parents 189cc86 + 76004da commit 9ccb44d
Show file tree
Hide file tree
Showing 40 changed files with 6,805 additions and 523 deletions.
1 change: 0 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rustflags = [
"-Wclippy::unnecessary_struct_initialization",
"-Wclippy::unused_peekable",
"-Wclippy::unused_rounding",
"-Wclippy::useless_let_if_seq",
"-Wclippy::while_float",

# Pedantic Group
Expand Down
5 changes: 5 additions & 0 deletions taos-query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ tokio = { version = "1", features = [
lazy_static = "1.4"
derive_builder = "0.12.0"
tracing = { version = "0.1", features = ["log"] }
uuid = { version = "1.11.0", features = [
"v4",
"fast-rng",
"macro-diagnostics",
] }

[dev-dependencies]
flate2 = "1"
Expand Down
45 changes: 4 additions & 41 deletions taos-query/src/common/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,6 @@ impl RawBlock {
unsafe { (v as *const u64).read_unaligned() == 0x7FFFFF0000000000 }
}

// const BOOL_NULL: u8 = 0x2;
// const TINY_INT_NULL: i8 = i8::MIN;
// const SMALL_INT_NULL: i16 = i16::MIN;
// const INT_NULL: i32 = i32::MIN;
// const BIG_INT_NULL: i64 = i64::MIN;
// const FLOAT_NULL: f32 = 0x7FF00000i32 as f32;
// const DOUBLE_NULL: f64 = 0x7FFFFF0000000000i64 as f64;
// const U_TINY_INT_NULL: u8 = u8::MAX;
// const U_SMALL_INT_NULL: u16 = u16::MAX;
// const U_INT_NULL: u32 = u32::MAX;
// const U_BIG_INT_NULL: u64 = u64::MAX;

let layout = Rc::new(RefCell::new(Layout::INLINE_DEFAULT.with_schema_changed()));

let bytes = bytes.into();
Expand All @@ -273,8 +261,7 @@ impl RawBlock {

for (i, (field, length)) in fields.iter().zip(lengths).enumerate() {
macro_rules! _primitive_view {
($ty:ident, $prim:ty) => {
{
($ty:ident, $prim:ty) => {{
debug_assert_eq!(field.bytes(), *length);
// column start
let start = offset;
Expand All @@ -283,31 +270,17 @@ impl RawBlock {
// byte slice from start to end: `[start, end)`.
let data = bytes.slice(start..offset);
let nulls = NullBits::from_iter((0..rows).map(|row| unsafe {
paste::paste!{ [<$ty:snake _is_null>] (
paste::paste! { [<$ty:snake _is_null>] (
data
.as_ptr()
.offset(row as isize * std::mem::size_of::<$prim>() as isize)
as *const $prim,
) }
}));
// value as target type
// let value_slice = unsafe {
// std::slice::from_raw_parts(
// transmute::<*const u8, *const $prim>(data.as_ptr()),
// rows,
// )
// };

// Set data lengths for v3-compatible block.
data_lengths[i] = data.len() as u32;

// generate nulls bitmap.
// let nulls = NullsMut::from_bools(
// value_slice
// .iter()
// .map(|v| paste::paste!{ [<$ty:snake _is_null>](v as _) })
// // .map(|b| *b as u64 == paste::paste! { [<$ty:snake:upper _NULL>] }),
// )
// .into_nulls();
// build column view
let column = paste::paste! { ColumnView::$ty([<$ty View>] { nulls, data }) };
columns.push(column);
Expand Down Expand Up @@ -831,10 +804,6 @@ impl RawBlock {
self.columns.get_unchecked(col).get_ref_unchecked(row)
}

// unsafe fn get_col_unchecked(&self, col: usize) -> &ColumnView {
// self.columns.get_unchecked(col)
// }

pub fn to_values(&self) -> Vec<Vec<Value>> {
self.rows().map(RowView::into_values).collect_vec()
}
Expand All @@ -859,13 +828,6 @@ impl RawBlock {
PrettyBlock::new(self)
}

// pub fn fields_iter(&self) -> impl Iterator<Item = Field> + '_ {
// self.schemas()
// .iter()
// .zip(self.field_names())
// .map(|(schema, name)| Field::new(name, schema.ty, schema.len))
// }

pub fn to_create(&self) -> Option<MetaCreate> {
self.table_name().map(|table_name| MetaCreate::Normal {
table_name: table_name.to_string(),
Expand Down Expand Up @@ -1029,6 +991,7 @@ impl crate::prelude::sync::Inlinable for InlineBlock {
Ok(self.0.len())
}
}

#[async_trait::async_trait]
impl crate::prelude::AsyncInlinable for InlineBlock {
async fn read_inlined<R: tokio::io::AsyncRead + Send + Unpin>(
Expand Down
20 changes: 0 additions & 20 deletions taos-query/src/common/raw/views/big_int_unsigned_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,6 @@ impl ExactSizeIterator for UBigIntViewIter<'_> {
}
}

impl<A: Into<Option<Item>>> FromIterator<A> for UBigIntView {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let (nulls, mut values): (Vec<bool>, Vec<_>) = iter
.into_iter()
.map(|v| match v.into() {
Some(v) => (false, v),
None => (true, Item::default()),
})
.unzip();
Self {
nulls: NullBits::from_iter(nulls),
data: Bytes::from({
let (ptr, len, cap) = (values.as_mut_ptr(), values.len(), values.capacity());
std::mem::forget(values);
unsafe { Vec::from_raw_parts(ptr as *mut u8, len * ITEM_SIZE, cap * ITEM_SIZE) }
}),
}
}
}

#[test]
fn test_slice() {
let data = [0, 1, Item::MIN, Item::MAX];
Expand Down
20 changes: 0 additions & 20 deletions taos-query/src/common/raw/views/big_int_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,6 @@ impl ExactSizeIterator for BigIntViewIter<'_> {
}
}

impl<A: Into<Option<Item>>> FromIterator<A> for View {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let (nulls, mut values): (Vec<bool>, Vec<_>) = iter
.into_iter()
.map(|v| match v.into() {
Some(v) => (false, v),
None => (true, Item::default()),
})
.unzip();
Self {
nulls: NullBits::from_iter(nulls),
data: Bytes::from({
let (ptr, len, cap) = (values.as_mut_ptr(), values.len(), values.capacity());
std::mem::forget(values);
unsafe { Vec::from_raw_parts(ptr as *mut u8, len * ITEM_SIZE, cap * ITEM_SIZE) }
}),
}
}
}

#[test]
fn test_slice() {
let data = [0, 1, 2, i64::MAX];
Expand Down
20 changes: 0 additions & 20 deletions taos-query/src/common/raw/views/bool_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,26 +251,6 @@ impl ExactSizeIterator for BoolViewIter<'_> {
}
}

impl<A: Into<Option<bool>>> FromIterator<A> for BoolView {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let (nulls, mut values): (Vec<bool>, Vec<_>) = iter
.into_iter()
.map(|v| match v.into() {
Some(v) => (false, v),
None => (true, false),
})
.unzip();
Self {
nulls: NullBits::from_iter(nulls),
data: Bytes::from({
let (ptr, len, cap) = (values.as_mut_ptr(), values.len(), values.capacity());
std::mem::forget(values);
unsafe { Vec::from_raw_parts(ptr as *mut u8, len, cap) }
}),
}
}
}

#[test]
fn test_bool_slice() {
let data = [true, false, false, true];
Expand Down
21 changes: 0 additions & 21 deletions taos-query/src/common/raw/views/double_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,27 +258,6 @@ impl ExactSizeIterator for DoubleViewIter<'_> {
}
}

impl<A: Into<Option<Item>>> FromIterator<A> for View {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let (nulls, mut values): (Vec<bool>, Vec<_>) = iter
.into_iter()
.map(|v| match v.into() {
Some(v) => (false, v),
None => (true, Item::default()),
})
.unzip();
// dbg!()
Self {
nulls: NullBits::from_iter(nulls),
data: Bytes::from({
let (ptr, len, cap) = (values.as_mut_ptr(), values.len(), values.capacity());
std::mem::forget(values);
unsafe { Vec::from_raw_parts(ptr as *mut u8, len * ITEM_SIZE, cap * ITEM_SIZE) }
}),
}
}
}

#[test]
fn test_slice() {
let data = [0., 1., Item::MIN, Item::MAX];
Expand Down
20 changes: 0 additions & 20 deletions taos-query/src/common/raw/views/float_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,6 @@ impl ExactSizeIterator for FloatViewIter<'_> {
}
}

impl<A: Into<Option<Item>>> FromIterator<A> for View {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let (nulls, mut values): (Vec<bool>, Vec<_>) = iter
.into_iter()
.map(|v| match v.into() {
Some(v) => (false, v),
None => (true, Item::default()),
})
.unzip();
Self {
nulls: NullBits::from_iter(nulls),
data: Bytes::from({
let (ptr, len, cap) = (values.as_mut_ptr(), values.len(), values.capacity());
std::mem::forget(values);
unsafe { Vec::from_raw_parts(ptr as *mut u8, len * ITEM_SIZE, cap * ITEM_SIZE) }
}),
}
}
}

#[test]
fn test_slice() {
let data = [0., 1., Item::MIN, Item::MAX];
Expand Down
20 changes: 0 additions & 20 deletions taos-query/src/common/raw/views/int_unsigned_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,26 +253,6 @@ impl ExactSizeIterator for UIntViewIter<'_> {
}
}

impl<A: Into<Option<Item>>> FromIterator<A> for View {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let (nulls, mut values): (Vec<bool>, Vec<_>) = iter
.into_iter()
.map(|v| match v.into() {
Some(v) => (false, v),
None => (true, Item::default()),
})
.unzip();
Self {
nulls: NullBits::from_iter(nulls),
data: Bytes::from({
let (ptr, len, cap) = (values.as_mut_ptr(), values.len(), values.capacity());
std::mem::forget(values);
unsafe { Vec::from_raw_parts(ptr as *mut u8, len * ITEM_SIZE, cap * ITEM_SIZE) }
}),
}
}
}

#[test]
fn test_slice() {
let data = [0, 1, Item::MIN, Item::MAX];
Expand Down
83 changes: 51 additions & 32 deletions taos-query/src/common/raw/views/int_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,40 +259,59 @@ impl ExactSizeIterator for IntViewIter<'_> {
}
}

impl<A: Into<Option<Item>>> FromIterator<A> for View {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
let (nulls, mut values): (Vec<bool>, Vec<_>) = iter
.into_iter()
.map(|v| match v.into() {
Some(v) => (false, v),
None => (true, Item::default()),
})
.unzip();
Self {
nulls: NullBits::from_iter(nulls),
data: Bytes::from({
let (ptr, len, cap) = (values.as_mut_ptr(), values.len(), values.capacity());
std::mem::forget(values);
unsafe { Vec::from_raw_parts(ptr as *mut u8, len * ITEM_SIZE, cap * ITEM_SIZE) }
}),
#[cfg(test)]
mod tests {
use byteorder::{BigEndian, ByteOrder};

use crate::views::int_view::{Item, View, ITEM_SIZE};

#[test]
fn test_slice() {
let data = [0, 1, Item::MIN, Item::MAX];
let view = View::from_iter(data);
dbg!(&view);
let slice = view.slice(1..3);
dbg!(&slice);

let data = [None, Some(Item::MIN), Some(Item::MAX), None];
let view = View::from_iter(data);
dbg!(&view);
let range = 1..4;
let slice = view.slice(range.clone()).unwrap();
for (v, i) in slice.iter().zip(range) {
assert_eq!(v, data[i]);
}
}
}

#[test]
fn test_slice() {
let data = [0, 1, Item::MIN, Item::MAX];
let view = View::from_iter(data);
dbg!(&view);
let slice = view.slice(1..3);
dbg!(&slice);

let data = [None, Some(Item::MIN), Some(Item::MAX), None];
let view = View::from_iter(data);
dbg!(&view);
let range = 1..4;
let slice = view.slice(range.clone()).unwrap();
for (v, i) in slice.iter().zip(range) {
assert_eq!(v, data[i]);
#[cfg(target_endian = "little")]
#[test]
fn test_from_iterator() {
let data = [0x12345678];
let view = View::from_iter(data);
let bytes = view.data;
assert_eq!(bytes.to_vec(), vec![0x78, 0x56, 0x34, 0x12]);
}

#[cfg(target_endian = "little")]
#[test]
fn test_from_iterator_mock_big_endian() {
let mut bytes = [0u8; 16];
BigEndian::write_i32(&mut bytes, 0x12345678);
BigEndian::write_i32(&mut bytes[4..], 0x78563412);
BigEndian::write_i32(&mut bytes[8..], 0x12131415);
BigEndian::write_i32(&mut bytes[12..], 0x51413121);

for i in (0..bytes.len()).step_by(ITEM_SIZE) {
let j = i + ITEM_SIZE;
let val = Item::from_be_bytes(bytes[i..j].try_into().unwrap());
bytes[i..j].copy_from_slice(&val.to_le_bytes());
}

let expect = vec![
0x78, 0x56, 0x34, 0x12, 0x12, 0x34, 0x56, 0x78, 0x15, 0x14, 0x13, 0x12, 0x21, 0x31,
0x41, 0x51,
];

assert_eq!(bytes.to_vec(), expect);
}
}
Loading

0 comments on commit 9ccb44d

Please sign in to comment.