Skip to content

Commit 3a5e862

Browse files
committed
move ut to it
1 parent 6775dc3 commit 3a5e862

File tree

5 files changed

+49
-44
lines changed

5 files changed

+49
-44
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ mod optimize;
2424
mod purge_drop;
2525
mod purge_truncate;
2626
mod read_plan;
27+
mod replace_into;
2728
mod table_analyze;
2829
mod truncate;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use common_exception::Result;
16+
use common_storages_fuse::FuseTable;
17+
18+
#[test]
19+
fn test_partition() -> Result<()> {
20+
use rand::Rng;
21+
let mut rng = rand::thread_rng();
22+
for _ in 0..100 {
23+
let number_segment: usize = rng.gen_range(1..100);
24+
25+
// do not matter, arbitrarily picked
26+
let format_version = 2;
27+
28+
let segments = (0..number_segment)
29+
.map(|idx| (format!("{idx}"), format_version))
30+
.collect::<Vec<_>>();
31+
32+
for _ in 0..100 {
33+
let num_partition: usize = if number_segment == 1 {
34+
1
35+
} else {
36+
rng.gen_range(1..number_segment)
37+
};
38+
39+
let chunks = FuseTable::partition_segments(&segments, num_partition);
40+
assert_eq!(chunks.len(), num_partition);
41+
for (idx, (segment_idx, _)) in chunks.clone().into_iter().flatten().enumerate() {
42+
assert_eq!(idx, segment_idx)
43+
}
44+
}
45+
}
46+
Ok(())
47+
}

src/query/storages/fuse/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,3 @@ tokio-rayon = "2.1.0"
5656
tracing = "0.1.36"
5757
typetag = "0.2.3"
5858
uuid = { version = "1.1.2", features = ["serde", "v4"] }
59-
60-
[dev-dependencies]
61-
rand = "0.8.5"

src/query/storages/fuse/src/operations/replace.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl FuseTable {
280280
Ok(items)
281281
}
282282

283-
fn partition_segments(
283+
pub fn partition_segments(
284284
segments: &[Location],
285285
num_partition: usize,
286286
) -> Vec<Vec<(SegmentIndex, Location)>> {
@@ -365,42 +365,3 @@ impl FuseTable {
365365
)
366366
}
367367
}
368-
369-
#[cfg(test)]
370-
mod tests {
371-
use super::*;
372-
373-
#[test]
374-
fn test_partition() -> Result<()> {
375-
use rand::Rng;
376-
377-
let mut rng = rand::thread_rng();
378-
379-
for _ in 0..100 {
380-
let number_segment: usize = rng.gen_range(1..100);
381-
382-
// do not matter, arbitrarily picked
383-
let format_version = 2;
384-
385-
let segments = (0..number_segment)
386-
.into_iter()
387-
.map(|idx| (format!("{idx}"), format_version))
388-
.collect::<Vec<_>>();
389-
390-
for _ in 0..100 {
391-
let num_partition: usize = if number_segment == 1 {
392-
1
393-
} else {
394-
rng.gen_range(1..number_segment)
395-
};
396-
397-
let chunks = FuseTable::partition_segments(&segments, num_partition);
398-
assert_eq!(chunks.len(), num_partition);
399-
for (idx, (segment_idx, _)) in chunks.clone().into_iter().flatten().enumerate() {
400-
assert_eq!(idx, segment_idx)
401-
}
402-
}
403-
}
404-
Ok(())
405-
}
406-
}

0 commit comments

Comments
 (0)