Skip to content

Commit

Permalink
fix: move some code out of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
roeap committed Dec 16, 2023
1 parent 360e240 commit d14eae8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions kernel/src/scan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,19 @@ impl Scan {
.partition_columns
.iter()
.map(|column| {
Ok((
column,
self.schema()
.field(column)
.ok_or(Error::Generic("Unexpected partition column".to_string()))?,
))
self.schema()
.field(column)
.ok_or(Error::Generic("Unexpected partition column".to_string()))
})
.collect::<DeltaResult<Vec<_>>>()?;
partition_fields.reverse();

let select_fields = read_schema
.fields()
.iter()
.map(|f| Expression::Column(f.name().to_string()))
.collect_vec();

self.files(table_client)?
.map(|res| {
let add = res?;
Expand All @@ -202,20 +205,17 @@ impl Scan {
} else {
let mut fields =
Vec::with_capacity(partition_fields.len() + batch.num_columns());
for (column, field) in &partition_fields {
for field in &partition_fields {
let value_expression =
if let Some(Some(value)) = add.partition_values.get(*column) {
if let Some(Some(value)) = add.partition_values.get(field.name()) {
Expression::Literal(get_partition_value(value, field.data_type())?)
} else {
// TODO: is it allowed to assume null for missing partition values?
Expression::Literal(Scalar::Null(field.data_type().clone()))
};
fields.push(value_expression);
}

for field in read_schema.fields() {
fields.push(Expression::Column(field.name().to_string()));
}
fields.extend(select_fields.clone());

let evaluator = table_client.get_expression_handler().get_evaluator(
read_schema.clone(),
Expand Down

0 comments on commit d14eae8

Please sign in to comment.