Skip to content

Commit f284cdc

Browse files
committed
fix: fix native internal column bug
1 parent ca231f9 commit f284cdc

File tree

3 files changed

+31
-63
lines changed

3 files changed

+31
-63
lines changed

src/query/storages/fuse/src/operations/read/native_data_source_deserializer.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,29 @@ impl NativeDeserializeDataTransform {
282282
Ok(())
283283
}
284284

285+
fn fill_block_meta_index(data_block: DataBlock, fuse_part: &FusePartInfo) -> Result<DataBlock> {
286+
// Fill `BlockMetaInfoPtr` if query internal columns
287+
let meta: Option<BlockMetaInfoPtr> =
288+
Some(Box::new(fuse_part.block_meta_index().unwrap().to_owned()));
289+
data_block.add_meta(meta)
290+
}
291+
285292
/// All columns are default values, not need to read.
286293
fn finish_process_with_default_values(&mut self) -> Result<()> {
287294
let _ = self.chunks.pop_front();
288295
let part = self.parts.pop_front().unwrap();
289-
let part = FusePartInfo::from_part(&part)?;
296+
let fuse_part = FusePartInfo::from_part(&part)?;
290297

291-
let num_rows = part.nums_rows;
298+
let num_rows = fuse_part.nums_rows;
292299
let data_block = self.block_reader.build_default_values_block(num_rows)?;
293300
let data_block = data_block.resort(&self.src_schema, &self.output_schema)?;
294301

302+
let data_block = if !self.block_reader.query_internal_columns() {
303+
data_block
304+
} else {
305+
Self::fill_block_meta_index(data_block, fuse_part)?
306+
};
307+
295308
self.add_block(data_block)?;
296309

297310
self.inited = false;
@@ -304,10 +317,16 @@ impl NativeDeserializeDataTransform {
304317
fn finish_process_with_empty_block(&mut self) -> Result<()> {
305318
let _ = self.chunks.pop_front();
306319
let part = self.parts.pop_front().unwrap();
307-
let part = FusePartInfo::from_part(&part)?;
320+
let fuse_part = FusePartInfo::from_part(&part)?;
308321

309-
let num_rows = part.nums_rows;
322+
let num_rows = fuse_part.nums_rows;
310323
let data_block = DataBlock::new(vec![], num_rows);
324+
let data_block = if !self.block_reader.query_internal_columns() {
325+
data_block
326+
} else {
327+
Self::fill_block_meta_index(data_block, fuse_part)?
328+
};
329+
311330
self.add_block(data_block)?;
312331
Ok(())
313332
}

tests/sqllogictests/suites/base/00_dummy/05_0031_internal_column

Lines changed: 0 additions & 51 deletions
This file was deleted.

tests/sqllogictests/suites/base/05_ddl/05_0031_internal_column

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ statement ok
55
DROP TABLE IF EXISTS `05_0031_t`
66

77
statement ok
8-
CREATE TABLE `05_0031_t`(a int)
8+
CREATE TABLE `05_0031_t`(a int, b int default 2)
99

1010
statement error 1110
1111
ALTER TABLE `05_0031_t` ADD COLUMN _row_id float
@@ -14,17 +14,17 @@ statement error 1110
1414
CREATE TABLE `05_0031_t_1`(_row_id int)
1515

1616
statement ok
17-
INSERT INTO TABLE `05_0031_t` values(1),(2)
17+
INSERT INTO TABLE `05_0031_t` (a) values(1),(2)
1818

1919
statement ok
20-
INSERT INTO TABLE `05_0031_t` values(3)
20+
INSERT INTO TABLE `05_0031_t` (a) values(3)
2121

2222
query II
23-
SELECT a,_row_id FROM `05_0031_t` order by _row_id
23+
SELECT b,_row_id,a FROM `05_0031_t` order by _row_id
2424
----
25-
1 0
26-
2 1
27-
3 4194304
25+
2 0 1
26+
2 1 2
27+
2 4194304 3
2828

2929
query II
3030
SELECT a,_row_id FROM `05_0031_t` where _row_id = 0
@@ -35,7 +35,7 @@ statement ok
3535
DROP TABLE IF EXISTS `05_0031_t_1`
3636

3737
statement ok
38-
CREATE TABLE `05_0031_t_1`(b int)
38+
CREATE TABLE `05_0031_t_1`(c int)
3939

4040
statement ok
4141
INSERT INTO TABLE `05_0031_t_1` values(5),(6)

0 commit comments

Comments
 (0)