Skip to content

Commit 6b20ef8

Browse files
committed
chore: minor refactor for extract_scan_fields_from_projection()
1 parent 6fdcc08 commit 6b20ef8

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/query/service/src/sql/executor/physical_plan_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl PhysicalPlanBuilder {
126126
}
127127
if let Some(prewhere) = &scan.prewhere {
128128
// if there is a prewhere optimization,
129-
// we can prune `PhysicalScan`'s ouput schema.
129+
// we can prune `PhysicalScan`'s output schema.
130130
if prewhere.output_columns.contains(index) {
131131
name_mapping.insert(column.name().to_string(), index.to_string());
132132
}

src/query/service/src/storages/storage_table_read_plan.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use std::collections::BTreeMap;
1616
use std::sync::Arc;
1717

1818
use common_datavalues::DataField;
19+
use common_datavalues::DataSchema;
1920
use common_exception::Result;
2021
use common_legacy_planners::Extras;
2122
use common_legacy_planners::Projection;
2223
use common_legacy_planners::ReadDataSourcePlan;
2324
use common_legacy_planners::SourceInfo;
24-
use common_meta_app::schema::TableInfo;
2525

2626
use crate::sessions::QueryContext;
2727
use crate::storages::Table;
@@ -55,16 +55,21 @@ impl ToReadDataSourcePlan for dyn Table {
5555
push_downs: Option<Extras>,
5656
) -> Result<ReadDataSourcePlan> {
5757
let (statistics, parts) = self.read_partitions(ctx, push_downs.clone()).await?;
58+
5859
let table_info = self.get_table_info();
60+
let table_meta = &table_info.meta;
5961
let description = statistics.get_description(table_info);
6062

6163
let scan_fields = match (self.benefit_column_prune(), &push_downs) {
6264
(true, Some(push_downs)) => match &push_downs.prewhere {
63-
Some(prewhere) => {
64-
extract_scan_fields_from_projection(table_info, &prewhere.output_columns)
65-
}
65+
Some(prewhere) => extract_scan_fields_from_projection(
66+
&table_meta.schema,
67+
&prewhere.output_columns,
68+
),
6669
_ => match &push_downs.projection {
67-
Some(projection) => extract_scan_fields_from_projection(table_info, projection),
70+
Some(projection) => {
71+
extract_scan_fields_from_projection(&table_meta.schema, projection)
72+
}
6873
_ => None,
6974
},
7075
},
@@ -87,15 +92,13 @@ impl ToReadDataSourcePlan for dyn Table {
8792
}
8893

8994
fn extract_scan_fields_from_projection(
90-
table_info: &TableInfo,
95+
schema: &DataSchema,
9196
projection: &Projection,
9297
) -> Option<BTreeMap<usize, DataField>> {
9398
match projection {
9499
Projection::Columns(ref indices) => {
95-
if indices.len() < table_info.schema().fields().len() {
96-
let fields = indices
97-
.iter()
98-
.map(|i| table_info.schema().field(*i).clone());
100+
if indices.len() < schema.fields().len() {
101+
let fields = indices.iter().map(|i| schema.field(*i).clone());
99102

100103
Some((indices.iter().cloned().zip(fields)).collect::<BTreeMap<_, _>>())
101104
} else {
@@ -104,7 +107,7 @@ fn extract_scan_fields_from_projection(
104107
}
105108
Projection::InnerColumns(ref path_indices) => {
106109
let column_ids: Vec<usize> = path_indices.keys().cloned().collect();
107-
let new_schema = table_info.schema().inner_project(path_indices);
110+
let new_schema = schema.inner_project(path_indices);
108111
Some(
109112
(column_ids.iter().cloned().zip(new_schema.fields().clone()))
110113
.collect::<BTreeMap<_, _>>(),

0 commit comments

Comments
 (0)