-
Notifications
You must be signed in to change notification settings - Fork 751
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
Draft RFC for support nullable_number_type. #4158
Changes from 1 commit
7da4751
6b4c1a0
ad32db7
b6c3236
45fa6ac
e07f654
ed82093
6d4f70f
ccc7184
d5b7080
c5c0c6f
3b63562
5b2a254
9e5c84b
42b69e1
021040b
637defe
4f39389
ff23347
2735492
030296d
c881781
21fbc6b
96f23b8
bc73c8e
d7a2981
4ae8e58
6b1bd76
e69d363
2d2f65e
154ac39
673763a
01650d9
a51609e
952f912
9f5971c
5c86e89
bebe5be
581e339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: wang.zhen <wangzhenaaa7@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,14 +32,14 @@ impl DataBlock { | |
let mut group_key_len = 0; | ||
for col in column_names { | ||
let column = block.try_column_by_name(col)?; | ||
let _typ = if column.is_nullable() { | ||
let typ = if column.is_nullable() { | ||
remove_nullable(&column.data_type()) | ||
} else { | ||
column.data_type() | ||
}; | ||
if _typ.data_type_id().is_integer() { | ||
if typ.data_type_id().is_integer() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can support |
||
// If column is nullable, we will add one byte to identify `null` value for every row. | ||
group_key_len += _typ.data_type_id().numeric_byte_size()?; | ||
group_key_len += typ.data_type_id().numeric_byte_size()?; | ||
if column.is_nullable() { | ||
group_key_len += 1; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,32 +251,31 @@ where T: PrimitiveType | |
|
||
let mut res = Vec::with_capacity(group_fields.len()); | ||
let mut offsize = 0; | ||
let mut null_part_offset = 0; | ||
|
||
init_nullable_offset_via_fields(&mut null_part_offset, group_fields)?; | ||
let mut null_part_offset = init_nullable_offset_via_fields(group_fields)?; | ||
for f in group_fields.iter() { | ||
let data_type = f.data_type(); | ||
let mut deserializer = data_type.create_deserializer(rows); | ||
let reader = vec8.as_slice(); | ||
if !data_type.is_nullable() { | ||
deserializer.de_batch(&reader[offsize..], step, rows)?; | ||
res.push(deserializer.finish_to_column()); | ||
offsize += data_type.data_type_id().numeric_byte_size()?; | ||
} else { | ||
let nullable_type_size = remove_nullable(data_type) | ||
.data_type_id() | ||
.numeric_byte_size()?; | ||
deserializer.de_batch_with_nullable( | ||
&reader[offsize..], | ||
step, | ||
rows, | ||
null_part_offset, | ||
&mut null_part_offset, | ||
nullable_type_size, | ||
)?; | ||
res.push(deserializer.finish_to_column()); | ||
null_part_offset += 1; | ||
} | ||
if data_type.is_nullable() { | ||
offsize += remove_nullable(data_type) | ||
.data_type_id() | ||
.numeric_byte_size()?; | ||
} else { | ||
offsize += data_type.data_type_id().numeric_byte_size()?; | ||
|
||
offsize += nullable_type_size; | ||
} | ||
} | ||
Ok(res) | ||
|
@@ -304,8 +303,7 @@ where | |
|
||
let group_columns_has_nullable_one = check_group_columns_has_nullable(group_columns); | ||
if group_columns_has_nullable_one { | ||
let mut null_part_offset = 0; | ||
init_nullable_offset(&mut null_part_offset, group_columns)?; | ||
let mut null_part_offset = init_nullable_offset(group_columns)?; | ||
while size > 0 { | ||
build_keys_with_nullable_column( | ||
size, | ||
|
@@ -384,30 +382,29 @@ where | |
|
||
/// Init the nullable part's offset in bytes. It follows the values part. | ||
#[inline] | ||
fn init_nullable_offset(null_part_offset: &mut usize, group_keys: &[&ColumnRef]) -> Result<()> { | ||
fn init_nullable_offset(group_keys: &[&ColumnRef]) -> Result<usize> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. group_keys.iter().map(|c| c.data_type().numeric_byte_size().unwrap()).sum() |
||
let mut _null_part_offset = 0; | ||
for group_key_column in group_keys { | ||
*null_part_offset += remove_nullable(&group_key_column.data_type()) | ||
_null_part_offset += remove_nullable(&group_key_column.data_type()) | ||
.data_type_id() | ||
.numeric_byte_size()?; | ||
} | ||
Ok(()) | ||
Ok(_null_part_offset) | ||
} | ||
|
||
/// Init the nullable part's offset in bytes. It follows the values part. | ||
#[inline] | ||
fn init_nullable_offset_via_fields( | ||
null_part_offset: &mut usize, | ||
group_fields: &[DataField], | ||
) -> Result<()> { | ||
fn init_nullable_offset_via_fields(group_fields: &[DataField]) -> Result<usize> { | ||
let mut null_part_offset = 0; | ||
for f in group_fields { | ||
let f_typ = f.data_type(); | ||
if f_typ.is_nullable() { | ||
*null_part_offset += remove_nullable(f_typ).data_type_id().numeric_byte_size()?; | ||
null_part_offset += remove_nullable(f_typ).data_type_id().numeric_byte_size()?; | ||
} else { | ||
*null_part_offset += f_typ.data_type_id().numeric_byte_size()?; | ||
null_part_offset += f_typ.data_type_id().numeric_byte_size()?; | ||
} | ||
} | ||
Ok(()) | ||
Ok(null_part_offset) | ||
} | ||
|
||
#[inline] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,20 +52,15 @@ impl TypeDeserializer for NullableDeserializer { | |
reader: &[u8], | ||
step: usize, | ||
rows: usize, | ||
null_offset: usize, | ||
null_offset: &mut usize, | ||
type_size: usize, | ||
) -> Result<()> { | ||
for row in 0..rows { | ||
let mut reader = &reader[step * row..]; | ||
self.inner.de(&mut reader)?; | ||
// null_offset -= self.inner().to_physical_type; | ||
// todo, We should get the length of missed bytes which caused | ||
// by self.inner.de method. | ||
if reader[null_offset - 1] & 1 == 1 { | ||
self.bitmap.push(false); | ||
} else { | ||
self.bitmap.push(true); | ||
} | ||
self.bitmap.push(reader[*null_offset - type_size] & 1 != 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. !=1 ---> |
||
} | ||
*null_offset -= type_size; | ||
Ok(()) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
NULL 2 | ||
0 4 | ||
1 1 | ||
2 3 | ||
NULL 0 2 | ||
0 0 1 | ||
0 1 1 | ||
0 2 1 | ||
0 3 1 | ||
1 NULL 1 | ||
1 0 1 | ||
2 1 1 | ||
2 2 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE t(a UInt64, b UInt32) Engine = Fuse; | ||
INSERT INTO t(a,b) SELECT if (number % 3 = 1, null, number) as a, number + 3 as b FROM numbers(10); | ||
SELECT a%3 as c, count(1) as d from t GROUP BY c ORDER BY c, d; | ||
SELECT a%3 as c, a%4 as d, count(0) as f FROM t GROUP BY c,d ORDER BY c,d,f; | ||
DROP table t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
remove_nullable
directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove_nullable is c~.