Skip to content

Commit

Permalink
Merge pull request #5269 from xudong963/neat
Browse files Browse the repository at this point in the history
chore(planner): make code neat with `DataField::new()`
  • Loading branch information
BohuTANG authored May 10, 2022
2 parents ed635e9 + ed7688e commit d20d7a4
Showing 1 changed file with 9 additions and 39 deletions.
48 changes: 9 additions & 39 deletions query/src/sql/exec/data_schema_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use common_datavalues::DataField;
use common_datavalues::DataSchemaRef;
use common_datavalues::DataSchemaRefExt;
use common_datavalues::DataTypeImpl;
use common_exception::ErrorCode;
use common_exception::Result;
use common_planners::Expression;
Expand Down Expand Up @@ -46,11 +45,7 @@ impl<'a> DataSchemaBuilder<'a> {
new_data_fields.push(data_field);
continue;
}
let field = if data_field.is_nullable() {
DataField::new_nullable(data_field.name(), data_field.data_type().clone())
} else {
DataField::new(data_field.name(), data_field.data_type().clone())
};
let field = DataField::new(data_field.name(), data_field.data_type().clone());
new_data_fields.push(field);
}
Ok(DataSchemaRefExt::create(new_data_fields))
Expand Down Expand Up @@ -78,12 +73,7 @@ impl<'a> DataSchemaBuilder<'a> {
for index in plan.columns.iter() {
let column_entry = self.metadata.column(*index);
let field_name = format_field_name(column_entry.name.as_str(), *index);
let field = if matches!(column_entry.data_type, DataTypeImpl::Nullable(_)) {
DataField::new_nullable(field_name.as_str(), column_entry.data_type.clone())
} else {
DataField::new(field_name.as_str(), column_entry.data_type.clone())
};

let field = DataField::new(field_name.as_str(), column_entry.data_type.clone());
fields.push(field);
}

Expand All @@ -95,12 +85,7 @@ impl<'a> DataSchemaBuilder<'a> {
for index in columns {
let column_entry = self.metadata.column(*index);
let field_name = column_entry.name.clone();
let field = if matches!(column_entry.data_type, DataTypeImpl::Nullable(_)) {
DataField::new_nullable(field_name.as_str(), column_entry.data_type.clone())
} else {
DataField::new(field_name.as_str(), column_entry.data_type.clone())
};

let field = DataField::new(field_name.as_str(), column_entry.data_type.clone());
fields.push(field);
}

Expand All @@ -124,11 +109,7 @@ impl<'a> DataSchemaBuilder<'a> {
if input_schema.has_field(expr_name.as_str()) {
continue;
}
let field = if expr.nullable(&input_schema)? {
DataField::new_nullable(expr_name.as_str(), expr.to_data_type(&input_schema)?)
} else {
DataField::new(expr_name.as_str(), expr.to_data_type(&input_schema)?)
};
let field = DataField::new(expr_name.as_str(), expr.to_data_type(&input_schema)?);
fields.push(field);
}
Ok(DataSchemaRefExt::create(fields))
Expand All @@ -154,17 +135,10 @@ impl<'a> DataSchemaBuilder<'a> {
if input_schema.has_field(expr_name.as_str()) {
continue;
}
let field = if arg_inner_expr.nullable(&input_schema)? {
DataField::new_nullable(
expr_name.as_str(),
arg_inner_expr.to_data_type(&input_schema)?,
)
} else {
DataField::new(
expr_name.as_str(),
arg_inner_expr.to_data_type(&input_schema)?,
)
};
let field = DataField::new(
expr_name.as_str(),
arg_inner_expr.to_data_type(&input_schema)?,
);
fields.push(field);
agg_inner_expressions.push(arg_inner_expr.clone())
}
Expand Down Expand Up @@ -201,11 +175,7 @@ impl<'a> DataSchemaBuilder<'a> {
for expr in exprs.iter() {
let expr_name = expr.column_name().clone();
if !input_schema.has_field(expr_name.as_str()) {
let field = if expr.nullable(input_schema)? {
DataField::new_nullable(expr_name.as_str(), expr.to_data_type(input_schema)?)
} else {
DataField::new(expr_name.as_str(), expr.to_data_type(input_schema)?)
};
let field = DataField::new(expr_name.as_str(), expr.to_data_type(input_schema)?);
fields.push(field);
}
}
Expand Down

0 comments on commit d20d7a4

Please sign in to comment.