Skip to content

Commit

Permalink
fix: block_entry.memory_size (#16230)
Browse files Browse the repository at this point in the history
* fix block_entry.memory_size

Signed-off-by: coldWater <[email protected]>

* fix

Signed-off-by: coldWater <[email protected]>

* fix

Signed-off-by: coldWater <[email protected]>

* refine

Signed-off-by: coldWater <[email protected]>

---------

Signed-off-by: coldWater <[email protected]>
  • Loading branch information
forsaken628 authored Aug 12, 2024
1 parent 493af79 commit 8467049
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/query/expression/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ impl TryFrom<DataBlock> for ArrowChunk<ArrayRef> {
impl BlockEntry {
pub fn memory_size(&self) -> usize {
match &self.value {
Value::Scalar(s) => std::mem::size_of_val(s),
Value::Scalar(s) => s.as_ref().memory_size(),
Value::Column(c) => c.memory_size(),
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/query/expression/tests/it/block.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use databend_common_expression::block_debug::box_render;
use databend_common_expression::types::number::NumberScalar;
use databend_common_expression::types::string::StringColumnBuilder;
use databend_common_expression::types::AnyType;
use databend_common_expression::types::DataType;
use databend_common_expression::types::Int32Type;
use databend_common_expression::types::NumberDataType;
use databend_common_expression::BlockEntry;
use databend_common_expression::Column;
use databend_common_expression::DataField;
use databend_common_expression::DataSchemaRefExt;
use databend_common_expression::FromData;
use databend_common_expression::Scalar;
use databend_common_expression::Value;

use crate::common::new_block;

Expand Down Expand Up @@ -56,3 +61,18 @@ fn test_box_render_block() {
└────────────────────┘"#;
assert_eq!(d, expected);
}

#[test]
fn test_block_entry_memory_size() {
let scalar_u8 = Scalar::Number(NumberScalar::UInt8(1));

let entry = BlockEntry::new(
DataType::Number(NumberDataType::UInt8),
Value::<AnyType>::Scalar(scalar_u8),
);
assert_eq!(1, entry.memory_size());

let scalar_str = Scalar::String("abc".to_string());
let entry = BlockEntry::new(DataType::String, Value::<AnyType>::Scalar(scalar_str));
assert_eq!(3, entry.memory_size());
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ remove @data/parquet/unload/uuid
query
copy into @data/parquet/unload/uuid/ from (select 1 as a) file_format = (type = parquet)
----
1 64 377
1 1 377

query error column id doesn't exist
copy into t_uuid from @data/parquet/unload/uuid file_format = (type = parquet) RETURN_FAILED_ONLY=TRUE
Expand All @@ -22,7 +22,7 @@ select * from t_uuid
query
copy into @data/parquet/unload/uuid/ from (select 1 as a) file_format = (type = parquet)
----
1 64 377
1 1 377

statement ok
truncate table t_uuid
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/0_stateless/05_hints/05_0001_set_var.result
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Asia/Shanghai
America/Toronto
2022-02-02 03:00:00
2022-02-01 14:00:00
1 64 415
1 13 415
Asia/Shanghai
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Error: APIError: ResponseError with 1063: Permission denied: privilege READ is r
Error: APIError: ResponseError with 1063: Permission denied: No privilege on database root_db for user b.
Error: APIError: ResponseError with 1063: Permission denied: No privilege on table root_table for user b.
Error: APIError: ResponseError with 1063: Permission denied: No privilege on table root_table for user b.
1 64 377
1 1 377
Error: APIError: ResponseError with 1063: Permission denied: privilege [Select] is required on 'default'.'default'.'t1' for user 'b'@'%' with roles [public]
Error: APIError: ResponseError with 1063: Permission denied: privilege [Read] is required on STAGE s3 for user 'b'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Database|Table|UDF|Stage.
Error: APIError: ResponseError with 1063: Permission denied: privilege [Select] is required on 'default'.'default'.'t' for user 'b'@'%' with roles [public]
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/1_stateful/00_stage/00_0012_stage_priv.result
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Error: APIError: ResponseError with 1063: Permission denied: privilege [Write] i
Error: APIError: ResponseError with 1063: Permission denied: privilege [Read] is required on STAGE presign_stage for user 'u1'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Database|Table|UDF|Stage.
000
Error: APIError: ResponseError with 1063: Permission denied: privilege [Write] is required on STAGE s3 for user 'u1'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Database|Table|UDF|Stage.
1 64 377
1 1 377
Error: APIError: ResponseError with 1063: Permission denied: privilege [Read] is required on STAGE s3 for user 'u1'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Database|Table|UDF|Stage.
Error: APIError: ResponseError with 1063: Permission denied: privilege READ is required on stage s3 for user 'u1'@'%'
Error: APIError: ResponseError with 1063: Permission denied: privilege READ is required on stage s3 for user 'u1'@'%'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sample.csv
Succeeded
96
227
168
null
1 'Beijing' 100 China
2 'Shanghai' 80 China
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sample.csv
96
227
168
null
1 'Beijing' 100 China
2 'Shanghai' 80 China
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sample.csv
96
227
168
null
1 'Beijing' 100 China
2 'Shanghai' 80 China
Expand Down

0 comments on commit 8467049

Please sign in to comment.