Skip to content

Commit 9ef5453

Browse files
committed
add block serializer
1 parent 619fd6f commit 9ef5453

37 files changed

+1635
-704
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/native/src/write/writer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl<W: Write> NativeWriter<W> {
7676
}
7777

7878
/// Consumes itself into the inner writer
79-
pub fn into_inner(self) -> W {
80-
self.writer.w
79+
pub fn inner_mut(&mut self) -> &mut W {
80+
&mut self.writer.w
8181
}
8282

8383
/// Writes the header and first (schema) message to the file.

src/query/catalog/src/table_args.rs

-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::cmp::Ordering;
1615
use std::collections::HashMap;
1716

1817
use databend_common_exception::ErrorCode;
@@ -132,15 +131,6 @@ pub fn u64_literal(val: u64) -> Scalar {
132131
Scalar::Number(NumberScalar::UInt64(val))
133132
}
134133

135-
pub fn cmp_with_null(v1: &Scalar, v2: &Scalar) -> Ordering {
136-
match (v1.is_null(), v2.is_null()) {
137-
(true, true) => Ordering::Equal,
138-
(true, false) => Ordering::Greater,
139-
(false, true) => Ordering::Less,
140-
(false, false) => v1.cmp(v2),
141-
}
142-
}
143-
144134
pub fn parse_sequence_args(table_args: &TableArgs, func_name: &str) -> Result<String> {
145135
let args = table_args.expect_all_positioned(func_name, Some(1))?;
146136
let sequence = string_value(&args[0])?;

src/query/service/src/test_kits/block_writer.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use databend_common_io::constants::DEFAULT_BLOCK_BUFFER_SIZE;
2121
use databend_common_io::constants::DEFAULT_BLOCK_INDEX_BUFFER_SIZE;
2222
use databend_common_sql::BloomIndexColumns;
2323
use databend_common_storages_fuse::io::serialize_block;
24+
use databend_common_storages_fuse::io::BloomIndexBuilder;
2425
use databend_common_storages_fuse::io::TableMetaLocationGenerator;
2526
use databend_common_storages_fuse::io::WriteSettings;
2627
use databend_common_storages_fuse::FuseStorageFormat;
@@ -127,12 +128,9 @@ impl<'a> BlockWriter<'a> {
127128
let bloom_index_cols = BloomIndexColumns::All;
128129
let bloom_columns_map =
129130
bloom_index_cols.bloom_index_fields(schema.clone(), BloomIndex::supported_type)?;
130-
let maybe_bloom_index = BloomIndex::try_create(
131-
FunctionContext::default(),
132-
location.1,
133-
block,
134-
bloom_columns_map,
135-
)?;
131+
let mut builder = BloomIndexBuilder::create(FunctionContext::default(), bloom_columns_map);
132+
builder.add_block(block)?;
133+
let maybe_bloom_index = builder.finalize()?;
136134
if let Some(bloom_index) = maybe_bloom_index {
137135
let index_block = bloom_index.serialize_to_data_block()?;
138136
let filter_schema = bloom_index.filter_schema;

src/query/storages/common/index/tests/it/bloom_pruner.rs renamed to src/query/service/tests/it/storages/fuse/bloom_pruner.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Datafuse Labs.
1+
// Copyright 2021 Datafuse Labs
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,14 +17,23 @@ use std::collections::HashMap;
1717
use std::io::Write;
1818
use std::sync::Arc;
1919

20+
use databend_common_column::buffer::Buffer;
2021
use databend_common_expression::type_check;
2122
use databend_common_expression::type_check::check_function;
22-
use databend_common_expression::types::array::ArrayColumn;
2323
use databend_common_expression::types::map::KvColumn;
2424
use databend_common_expression::types::map::KvPair;
25-
use databend_common_expression::types::number::NumberScalar;
26-
use databend_common_expression::types::number::UInt8Type;
27-
use databend_common_expression::types::*;
25+
use databend_common_expression::types::AnyType;
26+
use databend_common_expression::types::ArrayColumn;
27+
use databend_common_expression::types::DataType;
28+
use databend_common_expression::types::DateType;
29+
use databend_common_expression::types::Int16Type;
30+
use databend_common_expression::types::Int32Type;
31+
use databend_common_expression::types::Int8Type;
32+
use databend_common_expression::types::NumberDataType;
33+
use databend_common_expression::types::NumberScalar;
34+
use databend_common_expression::types::StringType;
35+
use databend_common_expression::types::UInt8Type;
36+
use databend_common_expression::types::VariantType;
2837
use databend_common_expression::BlockEntry;
2938
use databend_common_expression::Column;
3039
use databend_common_expression::ColumnRef;
@@ -42,18 +51,17 @@ use databend_common_expression::TableSchema;
4251
use databend_common_expression::Value;
4352
use databend_common_functions::test_utils::parse_raw_expr;
4453
use databend_common_functions::BUILTIN_FUNCTIONS;
45-
use databend_storages_common_index::filters::BlockFilter as LatestBloom;
54+
use databend_common_storages_fuse::io::BloomIndexBuilder;
4655
use databend_storages_common_index::filters::Xor8Filter;
4756
use databend_storages_common_index::BloomIndex;
4857
use databend_storages_common_index::FilterEvalResult;
4958
use databend_storages_common_index::Index;
5059
use databend_storages_common_table_meta::meta::ColumnStatistics;
51-
use databend_storages_common_table_meta::meta::Versioned;
5260
use goldenfile::Mint;
5361

5462
#[test]
5563
fn test_bloom_filter() {
56-
let mut mint = Mint::new("tests/it/testdata");
64+
let mut mint = Mint::new("tests/it/storages/testdata");
5765
let file = &mut mint.new_goldenfile("test_bloom_filter.txt").unwrap();
5866

5967
test_base(file);
@@ -478,14 +486,10 @@ fn eval_index_expr(
478486
BloomIndex::calculate_scalar_digest(&func_ctx, scalar, &ty).unwrap()
479487
});
480488
}
481-
let index = BloomIndex::try_create(
482-
func_ctx.clone(),
483-
LatestBloom::VERSION,
484-
block,
485-
bloom_columns.clone(),
486-
)
487-
.unwrap()
488-
.unwrap();
489+
490+
let mut builder = BloomIndexBuilder::create(func_ctx.clone(), bloom_columns.clone());
491+
builder.add_block(block).unwrap();
492+
let index = builder.finalize().unwrap().unwrap();
489493

490494
let column_stats = block
491495
.columns()

src/query/service/tests/it/storages/fuse/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#![allow(clippy::too_many_arguments)]
1616
mod bloom_index_meta_size;
17+
mod bloom_pruner;
1718
mod conflict;
1819
mod io;
1920
mod meta;

src/query/service/tests/it/storages/fuse/statistics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ fn test_ft_stats_block_stats() -> databend_common_exception::Result<()> {
8484
#[test]
8585
fn test_ft_stats_block_stats_with_column_distinct_count() -> databend_common_exception::Result<()> {
8686
let schema = Arc::new(TableSchema::new(vec![
87-
TableField::new("a", TableDataType::Number(NumberDataType::Int32)),
88-
TableField::new("b", TableDataType::String),
87+
TableField::new_from_column_id("a", TableDataType::Number(NumberDataType::Int32), 0),
88+
TableField::new_from_column_id("b", TableDataType::String, 1),
8989
]));
9090

9191
let block = DataBlock::new_from_columns(vec![

0 commit comments

Comments
 (0)