Skip to content

Commit 295218d

Browse files
committed
add test
1 parent 37c1f15 commit 295218d

File tree

3 files changed

+75
-29
lines changed

3 files changed

+75
-29
lines changed

src/query/storages/fuse/src/fuse_column.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ impl FuseTableColumnStatisticsProvider {
3636
column_distinct_values: Option<HashMap<ColumnId, u64>>,
3737
row_count: u64,
3838
) -> Self {
39+
let distinct_map = column_distinct_values.as_ref();
3940
let column_stats = column_stats
4041
.into_iter()
4142
.map(|(column_id, stat)| {
42-
let ndv = column_distinct_values.as_ref().map_or(row_count, |map| {
43-
map.get(&column_id).map_or(row_count, |v| *v)
44-
});
43+
let ndv = distinct_map
44+
.and_then(|map| map.get(&column_id).cloned())
45+
.or(stat.distinct_of_values)
46+
.unwrap_or(row_count);
4547
let stat = BasicColumnStatistics {
4648
min: Datum::from_scalar(stat.min),
4749
max: Datum::from_scalar(stat.max),

tests/data/parquet/use_logic_type.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,42 @@
44
from datetime import datetime, date
55

66
data = {
7-
'timestamp_ms': [
7+
"timestamp_ms": [
88
datetime(2023, 1, 1, 12, 0, 0),
99
datetime(2023, 1, 2, 12, 30, 15),
10-
datetime(2023, 1, 3, 18, 45, 30)
10+
datetime(2023, 1, 3, 18, 45, 30),
1111
],
12-
'timestamp_us': [
12+
"timestamp_us": [
1313
datetime(2023, 1, 1, 12, 0, 0, 123456),
1414
datetime(2023, 1, 2, 12, 30, 15, 789012),
15-
datetime(2023, 1, 3, 18, 45, 30, 999999)
15+
datetime(2023, 1, 3, 18, 45, 30, 999999),
1616
],
17-
'timestamp_ns': [
18-
pd.Timestamp('2023-01-01 12:00:00.123456789'),
19-
pd.Timestamp('2023-01-02 12:30:15.987654321'),
20-
pd.Timestamp('2023-01-03 18:45:30.999999999')
21-
],
22-
'date32': [
23-
date(2023, 1, 1),
24-
date(2023, 1, 15),
25-
date(2023, 2, 28)
17+
"timestamp_ns": [
18+
pd.Timestamp("2023-01-01 12:00:00.123456789"),
19+
pd.Timestamp("2023-01-02 12:30:15.987654321"),
20+
pd.Timestamp("2023-01-03 18:45:30.999999999"),
2621
],
22+
"date32": [date(2023, 1, 1), date(2023, 1, 15), date(2023, 2, 28)],
2723
}
2824

29-
df = pd.DataFrame({
30-
'timestamp_ms': data['timestamp_ms'],
31-
'timestamp_us': data['timestamp_us'],
32-
'timestamp_ns': data['timestamp_ns'],
33-
'date32': pd.to_datetime(data['date32']).date,
34-
})
25+
df = pd.DataFrame(
26+
{
27+
"timestamp_ms": data["timestamp_ms"],
28+
"timestamp_us": data["timestamp_us"],
29+
"timestamp_ns": data["timestamp_ns"],
30+
"date32": pd.to_datetime(data["date32"]).date,
31+
}
32+
)
3533

36-
schema = pa.schema([
37-
pa.field('timestamp_ms', pa.timestamp('ms')),
38-
pa.field('timestamp_us', pa.timestamp('us')),
39-
pa.field('timestamp_ns', pa.timestamp('ns')),
40-
pa.field('date32', pa.date32()),
41-
])
34+
schema = pa.schema(
35+
[
36+
pa.field("timestamp_ms", pa.timestamp("ms")),
37+
pa.field("timestamp_us", pa.timestamp("us")),
38+
pa.field("timestamp_ns", pa.timestamp("ns")),
39+
pa.field("date32", pa.date32()),
40+
]
41+
)
4242

4343
table = pa.Table.from_pandas(df, schema=schema)
4444

45-
pq.write_table(table, 'timestamp_types_example.parquet', version='2.6')
45+
pq.write_table(table, "timestamp_types_example.parquet", version="2.6")

tests/sqllogictests/suites/base/09_fuse_engine/09_0020_analyze.test

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,49 @@ select count(*) from t_string where str_val between '3.0' and '7.0';
199199
statement ok
200200
DROP TABLE t_string
201201

202+
statement ok
203+
create or replace table t2(a int, b int);
204+
205+
query I
206+
insert into t2 values(1,1),(2,2);
207+
----
208+
2
209+
210+
query I
211+
insert into t2 values(2,2),(4,4);
212+
----
213+
2
214+
215+
query I
216+
delete from t2 where a=1;
217+
----
218+
1
219+
220+
statement ok
221+
analyze table t2 noscan;
222+
223+
query TII
224+
select name, row_count, ndv from system.columns where table = 't2' and database = 'db_09_0020' order by name;
225+
----
226+
a 3 3
227+
b 3 3
228+
229+
statement ok
230+
analyze table t2;
231+
232+
query TII
233+
select name, row_count, ndv from system.columns where table = 't2' and database = 'db_09_0020' order by name;
234+
----
235+
a 3 2
236+
b 3 2
237+
238+
query I
239+
select count() from fuse_snapshot('db_09_0020','t2');
240+
----
241+
5
242+
243+
statement ok
244+
DROP TABLE t2;
245+
202246
statement ok
203247
DROP DATABASE db_09_0020

0 commit comments

Comments
 (0)