Skip to content

Commit

Permalink
chore(expr): remove run_auto_type (databendlabs#11612)
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy authored May 29, 2023
1 parent e38f7eb commit 501c0c7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions src/query/expression/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,42 +85,6 @@ impl<'a> Evaluator<'a> {
}
}

/// TODO(sundy/andy): refactor this if we got better idea
pub fn run_auto_type(&self, expr: &Expr) -> Result<Value<AnyType>> {
let column_refs = expr.column_refs();

let mut columns = self.input_columns.columns().to_vec();
for (index, datatype) in column_refs.iter() {
let column = &columns[*index];
if datatype != &column.data_type {
let value = self.run(&Expr::Cast {
span: None,
is_try: false,
expr: Box::new(Expr::ColumnRef {
span: None,
id: *index,
data_type: column.data_type.clone(),
display_name: String::new(),
}),
dest_type: datatype.clone(),
})?;

columns[*index] = BlockEntry {
data_type: datatype.clone(),
value,
};
}
}

let new_blocks = DataBlock::new_with_meta(
columns,
self.input_columns.num_rows(),
self.input_columns.get_meta().cloned(),
);
let new_evaluator = Evaluator::new(&new_blocks, self.func_ctx, self.fn_registry);
new_evaluator.run(expr)
}

pub fn run(&self, expr: &Expr) -> Result<Value<AnyType>> {
self.partial_run(expr, None)
}
Expand Down
4 changes: 2 additions & 2 deletions src/query/service/src/api/rpc/flight_scatter_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl FlightScatter for OneHashKeyFlightScatter {
let evaluator = Evaluator::new(&data_block, &self.func_ctx, &BUILTIN_FUNCTIONS);
let num = data_block.num_rows();

let indices = evaluator.run_auto_type(&self.indices_scalar).unwrap();
let indices = evaluator.run(&self.indices_scalar).unwrap();
let indices = get_hash_values(&indices, num)?;
let data_blocks = DataBlock::scatter(&data_block, &indices, self.scatter_size)?;

Expand All @@ -141,7 +141,7 @@ impl FlightScatter for HashFlightScatter {
let indices = if !self.hash_key.is_empty() {
let mut hash_keys = vec![];
for expr in &self.hash_key {
let indices = evaluator.run_auto_type(expr).unwrap();
let indices = evaluator.run(expr).unwrap();
let indices = get_hash_values(&indices, num)?;
hash_keys.push(indices)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl JoinHashTable {
let func_ctx = self.ctx.get_function_context()?;
let evaluator = Evaluator::new(merged_block, &func_ctx, &BUILTIN_FUNCTIONS);
let predicates = evaluator
.run_auto_type(&filter)?
.run(&filter)?
.try_downcast::<BooleanType>()
.unwrap();

Expand All @@ -234,7 +234,7 @@ impl JoinHashTable {
let func_ctx = self.ctx.get_function_context()?;
let evaluator = Evaluator::new(merged_block, &func_ctx, &BUILTIN_FUNCTIONS);

let filter_vector: Value<AnyType> = evaluator.run_auto_type(filter)?;
let filter_vector: Value<AnyType> = evaluator.run(filter)?;
let filter_vector =
filter_vector.convert_to_full_column(filter.data_type(), merged_block.num_rows());

Expand Down

0 comments on commit 501c0c7

Please sign in to comment.