12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ use std:: collections:: BTreeMap ;
15
16
use std:: collections:: HashSet ;
16
17
17
18
use databend_common_base:: base:: tokio;
18
19
use databend_common_catalog:: plan:: InternalColumn ;
19
20
use databend_common_catalog:: plan:: InternalColumnMeta ;
20
- use databend_common_catalog:: plan:: Partitions ;
21
+ use databend_common_catalog:: plan:: PartInfoPtr ;
21
22
use databend_common_exception:: Result ;
23
+ use databend_common_expression:: block_debug:: pretty_format_blocks;
22
24
use databend_common_expression:: DataBlock ;
25
+ use databend_common_expression:: FieldIndex ;
23
26
use databend_common_expression:: BLOCK_NAME_COL_NAME ;
24
27
use databend_common_expression:: ROW_ID_COL_NAME ;
25
28
use databend_common_expression:: SEGMENT_NAME_COL_NAME ;
26
29
use databend_common_expression:: SNAPSHOT_NAME_COL_NAME ;
30
+ use databend_common_pipeline_core:: Pipeline ;
27
31
use databend_common_sql:: binder:: INTERNAL_COLUMN_FACTORY ;
32
+ use databend_common_sql:: executor:: table_read_plan:: ToReadDataSourcePlan ;
28
33
use databend_common_sql:: Planner ;
29
34
use databend_common_storages_fuse:: io:: MetaReaders ;
30
35
use databend_common_storages_fuse:: FuseBlockPartInfo ;
31
36
use databend_common_storages_fuse:: FuseTable ;
32
37
use databend_query:: interpreters:: InterpreterFactory ;
38
+ use databend_query:: pipelines:: executor:: ExecutorSettings ;
39
+ use databend_query:: pipelines:: executor:: QueryPipelineExecutor ;
33
40
use databend_query:: test_kits:: * ;
34
41
use databend_storages_common_cache:: LoadParams ;
35
42
use databend_storages_common_table_meta:: meta:: SegmentInfo ;
@@ -39,11 +46,11 @@ use databend_storages_common_table_meta::table::OPT_KEY_SNAPSHOT_LOCATION;
39
46
use futures:: TryStreamExt ;
40
47
41
48
fn expected_data_block (
42
- parts : & Partitions ,
49
+ parts : & Vec < PartInfoPtr > ,
43
50
internal_columns : & Vec < InternalColumn > ,
44
51
) -> Result < Vec < DataBlock > > {
45
- let mut data_blocks = Vec :: with_capacity ( parts. partitions . len ( ) ) ;
46
- for part in & parts. partitions {
52
+ let mut data_blocks = Vec :: with_capacity ( parts. len ( ) ) ;
53
+ for part in parts {
47
54
let fuse_part = FuseBlockPartInfo :: from_part ( part) ?;
48
55
let num_rows = fuse_part. nums_rows ;
49
56
let block_meta = fuse_part. block_meta_index . as_ref ( ) . unwrap ( ) ;
@@ -65,28 +72,22 @@ fn expected_data_block(
65
72
}
66
73
data_blocks. push ( DataBlock :: new ( columns, num_rows) ) ;
67
74
}
68
- data_blocks. reverse ( ) ;
69
75
70
76
Ok ( data_blocks)
71
77
}
72
78
73
79
fn check_data_block ( expected : Vec < DataBlock > , blocks : Vec < DataBlock > ) -> Result < ( ) > {
74
- let expected_data_block = DataBlock :: concat ( & expected) ?. consume_convert_to_full ( ) ;
75
- let data_block = DataBlock :: concat ( & blocks) ?. consume_convert_to_full ( ) ;
76
-
77
- for ( expected_column, column) in expected_data_block
78
- . columns ( )
79
- . iter ( )
80
- . zip ( data_block. columns ( ) )
81
- {
82
- assert_eq ! ( expected_column. data_type, column. data_type) ;
83
- assert_eq ! ( expected_column. value, column. value) ;
84
- }
80
+ let expected_blocks = pretty_format_blocks ( & expected) ?;
81
+ let expected_str: Vec < & str > = expected_blocks. split ( '\n' ) . collect ( ) ;
82
+ databend_common_expression:: block_debug:: assert_blocks_sorted_eq (
83
+ expected_str,
84
+ blocks. as_slice ( ) ,
85
+ ) ;
85
86
86
87
Ok ( ( ) )
87
88
}
88
89
89
- async fn check_partitions ( parts : & Partitions , fixture : & TestFixture ) -> Result < ( ) > {
90
+ async fn check_partitions ( parts : & Vec < PartInfoPtr > , fixture : & TestFixture ) -> Result < ( ) > {
90
91
let mut segment_name = HashSet :: new ( ) ;
91
92
let mut block_name = HashSet :: new ( ) ;
92
93
@@ -129,7 +130,7 @@ async fn check_partitions(parts: &Partitions, fixture: &TestFixture) -> Result<(
129
130
}
130
131
}
131
132
132
- for part in & parts. partitions {
133
+ for part in parts {
133
134
let fuse_part = FuseBlockPartInfo :: from_part ( part) ?;
134
135
let block_meta = fuse_part. block_meta_index . as_ref ( ) . unwrap ( ) ;
135
136
assert_eq ! (
@@ -166,6 +167,11 @@ async fn test_internal_column() -> Result<()> {
166
167
. get_internal_column( BLOCK_NAME_COL_NAME )
167
168
. unwrap( ) ,
168
169
] ;
170
+ let internal_columns_map = internal_columns
171
+ . iter ( )
172
+ . enumerate ( )
173
+ . map ( |( i, col) | ( i, col. clone ( ) ) )
174
+ . collect :: < BTreeMap < FieldIndex , InternalColumn > > ( ) ;
169
175
170
176
// insert 5 times
171
177
let n = 5 ;
@@ -188,7 +194,34 @@ async fn test_internal_column() -> Result<()> {
188
194
let blocks = res. try_collect :: < Vec < DataBlock > > ( ) . await ?;
189
195
190
196
let table = fixture. latest_default_table ( ) . await ?;
191
- let ( _, parts) = table. read_partitions ( ctx. clone ( ) , None , true ) . await ?;
197
+ let data_source_plan = table
198
+ . read_plan (
199
+ ctx. clone ( ) ,
200
+ None ,
201
+ Some ( internal_columns_map. clone ( ) ) ,
202
+ false ,
203
+ false ,
204
+ )
205
+ . await ?;
206
+
207
+ let mut dummy_pipeline = Pipeline :: create ( ) ;
208
+ let parts = if let Some ( mut prune_pipeline) =
209
+ table. build_prune_pipeline ( ctx. clone ( ) , & data_source_plan, & mut dummy_pipeline) ?
210
+ {
211
+ let fuse_table = FuseTable :: try_from_table ( table. as_ref ( ) ) ?;
212
+ let rx = fuse_table. pruned_result_receiver . lock ( ) . clone ( ) . unwrap ( ) ;
213
+ prune_pipeline. set_max_threads ( 1 ) ;
214
+ let settings = ExecutorSettings :: try_create ( ctx. clone ( ) ) ?;
215
+ let executor = QueryPipelineExecutor :: create ( prune_pipeline, settings) ?;
216
+ executor. execute ( ) ?;
217
+ let mut parts = Vec :: new ( ) ;
218
+ while let Ok ( Ok ( segment) ) = rx. recv ( ) . await {
219
+ parts. push ( segment) ;
220
+ }
221
+ parts
222
+ } else {
223
+ data_source_plan. parts . partitions . clone ( )
224
+ } ;
192
225
let expected = expected_data_block ( & parts, & internal_columns) ?;
193
226
check_partitions ( & parts, & fixture) . await ?;
194
227
check_data_block ( expected, blocks) ?;
@@ -213,7 +246,35 @@ async fn test_internal_column() -> Result<()> {
213
246
let blocks = res. try_collect :: < Vec < DataBlock > > ( ) . await ?;
214
247
215
248
let table = fixture. latest_default_table ( ) . await ?;
216
- let ( _, parts) = table. read_partitions ( ctx. clone ( ) , None , true ) . await ?;
249
+ let data_source_plan = table
250
+ . read_plan (
251
+ ctx. clone ( ) ,
252
+ None ,
253
+ Some ( internal_columns_map. clone ( ) ) ,
254
+ false ,
255
+ false ,
256
+ )
257
+ . await ?;
258
+
259
+ let mut dummy_pipeline = Pipeline :: create ( ) ;
260
+ let parts = if let Some ( mut prune_pipeline) =
261
+ table. build_prune_pipeline ( ctx. clone ( ) , & data_source_plan, & mut dummy_pipeline) ?
262
+ {
263
+ let fuse_table = FuseTable :: try_from_table ( table. as_ref ( ) ) ?;
264
+ let rx = fuse_table. pruned_result_receiver . lock ( ) . clone ( ) . unwrap ( ) ;
265
+ prune_pipeline. set_max_threads ( 1 ) ;
266
+ let settings = ExecutorSettings :: try_create ( ctx. clone ( ) ) ?;
267
+ let executor = QueryPipelineExecutor :: create ( prune_pipeline, settings) ?;
268
+ executor. execute ( ) ?;
269
+ let mut parts = Vec :: new ( ) ;
270
+ while let Ok ( Ok ( segment) ) = rx. recv ( ) . await {
271
+ parts. push ( segment) ;
272
+ }
273
+ parts
274
+ } else {
275
+ data_source_plan. parts . partitions . clone ( )
276
+ } ;
277
+
217
278
let expected = expected_data_block ( & parts, & internal_columns) ?;
218
279
check_partitions ( & parts, & fixture) . await ?;
219
280
check_data_block ( expected, blocks) ?;
0 commit comments