Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun committed Jan 16, 2025
1 parent 43e096c commit db2d889
Showing 1 changed file with 70 additions and 71 deletions.
141 changes: 70 additions & 71 deletions src/query/storages/common/stage/src/read/columnar/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub fn project_columnar(
if from_field.data_type == to_field.data_type {
expr
} else {
// note: tuple field name is dropped here, matched by pos here
if load_can_auto_cast_to(
&from_field.data_type().into(),
&to_field.data_type().into(),
Expand All @@ -88,83 +87,83 @@ pub fn project_columnar(
&to_field.data_type().into(),
&BUILTIN_FUNCTIONS,
)?
} else {
if fmt == StageFileFormatType::Orc && !matches!(missing_as, NullAs::Error) {
// special cast for tuple type, fill in default values for the missing fields.
match (
from_field.data_type.remove_nullable(),
to_field.data_type.remove_nullable(),
) {
(
TableDataType::Array(box TableDataType::Nullable(
box TableDataType::Tuple {
fields_name: from_fields_name,
fields_type: _from_fields_type,
},
)),
TableDataType::Array(box TableDataType::Nullable(
box TableDataType::Tuple {
fields_name: to_fields_name,
fields_type: _to_fields_type,
},
)),
) => {
let mut v = vec![];
for to in to_fields_name.iter() {
match from_fields_name.iter().position(|k| k == to) {
Some(p) => v.push(p as i32),
None => v.push(-1),
};
}
let name = v
.iter()
.map(|v| v.to_string())
.collect::<Vec<_>>()
.join(",");
Expr::ColumnRef {
span: None,
id: pos,
data_type: from_field.data_type().into(),
display_name: format!("#!{name}",),
}
}
(
TableDataType::Tuple {
} else if fmt == StageFileFormatType::Orc
&& !matches!(missing_as, NullAs::Error)
{
// special cast for tuple type, fill in default values for the missing fields.
match (
from_field.data_type.remove_nullable(),
to_field.data_type.remove_nullable(),
) {
(
TableDataType::Array(box TableDataType::Nullable(
box TableDataType::Tuple {
fields_name: from_fields_name,
fields_type: from_fields_type,
fields_type: _from_fields_type,
},
TableDataType::Tuple {
)),
TableDataType::Array(box TableDataType::Nullable(
box TableDataType::Tuple {
fields_name: to_fields_name,
fields_type: to_fields_type,
fields_type: _to_fields_type,
},
) => project_tuple(
expr,
from_field,
to_field,
&from_fields_name,
&from_fields_type,
&to_fields_name,
&to_fields_type,
)?,
(_, _) => {
return Err(ErrorCode::BadDataValueType(format!(
"fail to load file {}: Cannot cast column {} from {:?} to {:?}",
location,
field_name,
from_field.data_type(),
to_field.data_type()
)));
)),
) => {
let mut v = vec![];
for to in to_fields_name.iter() {
match from_fields_name.iter().position(|k| k == to) {
Some(p) => v.push(p as i32),
None => v.push(-1),
};
}
let name = v
.iter()
.map(|v| v.to_string())
.collect::<Vec<_>>()
.join(",");
Expr::ColumnRef {
span: None,
id: pos,
data_type: from_field.data_type().into(),
display_name: format!("#!{name}",),
}
}
} else {
return Err(ErrorCode::BadDataValueType(format!(
"fail to load file {}: Cannot cast column {} from {:?} to {:?}",
location,
field_name,
from_field.data_type(),
to_field.data_type()
)));
(
TableDataType::Tuple {
fields_name: from_fields_name,
fields_type: from_fields_type,
},
TableDataType::Tuple {
fields_name: to_fields_name,
fields_type: to_fields_type,
},
) => project_tuple(
expr,
from_field,
to_field,
&from_fields_name,
&from_fields_type,
&to_fields_name,
&to_fields_type,
)?,
(_, _) => {
return Err(ErrorCode::BadDataValueType(format!(
"fail to load file {}: Cannot cast column {} from {:?} to {:?}",
location,
field_name,
from_field.data_type(),
to_field.data_type()
)));
}
}
} else {
return Err(ErrorCode::BadDataValueType(format!(
"fail to load file {}: Cannot cast column {} from {:?} to {:?}",
location,
field_name,
from_field.data_type(),
to_field.data_type()
)));
}
}
}
Expand Down

0 comments on commit db2d889

Please sign in to comment.