Skip to content

Commit

Permalink
chore(query): remove useless function map:get (#15245)
Browse files Browse the repository at this point in the history
* chore(query): remove useless function map:get

* chore(query): remove useless function map:get

* chore(query): remove useless function map:get
  • Loading branch information
sundy-li authored Apr 17, 2024
1 parent 68a51c4 commit 38b4fb7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 69 deletions.
27 changes: 0 additions & 27 deletions src/query/functions/src/scalars/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use databend_common_expression::types::MapType;
use databend_common_expression::types::NullType;
use databend_common_expression::types::NullableType;
use databend_common_expression::vectorize_with_builder_2_arg;
use databend_common_expression::Domain;
use databend_common_expression::FunctionDomain;
use databend_common_expression::FunctionRegistry;
use databend_common_expression::Value;
Expand Down Expand Up @@ -97,7 +96,6 @@ pub fn register(registry: &mut FunctionRegistry) {
|_, _, _| Value::Scalar(()),
);

// NOTE: order is matter, we first catch <K, Nullable<V>> here.
registry.register_combine_nullable_2_arg::<MapType<GenericType<0>, NullableType<GenericType<1>>>, GenericType<0>, GenericType<1>, _, _>(
"get",
|_, domain, _| {
Expand All @@ -121,29 +119,4 @@ pub fn register(registry: &mut FunctionRegistry) {
}
),
);

// NOTE: order is matter, we catch <K, V> here after <K, Nullable<V>>
registry.register_combine_nullable_2_arg::<MapType<GenericType<0>, GenericType<1>>, GenericType<0>, GenericType<1>, _, _>(
"get",
|_, domain, _| {
FunctionDomain::Domain(NullableDomain {
has_null: true,
value: domain.as_ref().and_then(|(_, val_domain)| match val_domain {
Domain::Nullable(nullable_domain) => nullable_domain.value.clone(),
_ => Some(Box::new(val_domain.clone())),
})
})
},
vectorize_with_builder_2_arg::<MapType<GenericType<0>, GenericType<1>>, GenericType<0>, NullableType<GenericType<1>>>(
|map, key, output, _| {
for (k, v) in map.iter() {
if k == key {
output.push(v);
return
}
}
output.push_null()
}
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2004,11 +2004,9 @@ Functions overloads:
9 get(Map(T0, NULL) NULL, T0 NULL) :: NULL
10 get(Map(T0, T1 NULL), T0) :: T1 NULL
11 get(Map(T0, T1 NULL) NULL, T0 NULL) :: T1 NULL
12 get(Map(T0, T1), T0) :: T1 NULL
13 get(Map(T0, T1) NULL, T0 NULL) :: T1 NULL
12 get FACTORY
13 get FACTORY
14 get FACTORY
15 get FACTORY
16 get FACTORY
0 get_by_keypath FACTORY
0 get_by_keypath_string FACTORY
0 get_ignore_case(Variant, String) :: Variant NULL
Expand Down
44 changes: 6 additions & 38 deletions src/query/sql/src/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,6 @@ impl<'a> TypeChecker<'a> {
}
}

#[async_backtrace::framed]
async fn resolve_window(
&mut self,
span: Span,
Expand Down Expand Up @@ -1290,7 +1289,6 @@ impl<'a> TypeChecker<'a> {
})
}

#[async_backtrace::framed]
async fn resolve_range_offset(&mut self, bound: &WindowFrameBound) -> Result<Option<Scalar>> {
match bound {
WindowFrameBound::Following(Some(box expr))
Expand All @@ -1311,7 +1309,6 @@ impl<'a> TypeChecker<'a> {
}
}

#[async_backtrace::framed]
async fn resolve_window_range_frame(&mut self, frame: WindowFrame) -> Result<WindowFuncFrame> {
let start_offset = self.resolve_range_offset(&frame.start_bound).await?;
let end_offset = self.resolve_range_offset(&frame.end_bound).await?;
Expand All @@ -1338,7 +1335,6 @@ impl<'a> TypeChecker<'a> {
})
}

#[async_backtrace::framed]
async fn resolve_window_frame(
&mut self,
span: Span,
Expand Down Expand Up @@ -1422,7 +1418,7 @@ impl<'a> TypeChecker<'a> {
}

/// Resolve general window function call.
#[async_backtrace::framed]
async fn resolve_general_window_function(
&mut self,
span: Span,
Expand Down Expand Up @@ -1486,7 +1482,6 @@ impl<'a> TypeChecker<'a> {
}
}

#[async_backtrace::framed]
async fn resolve_lag_lead_window_function(
&mut self,
func_name: &str,
Expand Down Expand Up @@ -1554,7 +1549,6 @@ impl<'a> TypeChecker<'a> {
}))
}

#[async_backtrace::framed]
async fn resolve_nth_value_window_function(
&mut self,
func_name: &str,
Expand Down Expand Up @@ -1627,7 +1621,6 @@ impl<'a> TypeChecker<'a> {
})
}

#[async_backtrace::framed]
async fn resolve_ntile_window_function(
&mut self,
args: &[ScalarExpr],
Expand Down Expand Up @@ -1662,7 +1655,7 @@ impl<'a> TypeChecker<'a> {
}

/// Resolve aggregation function call.
#[async_backtrace::framed]
async fn resolve_aggregate_function(
&mut self,
span: Span,
Expand Down Expand Up @@ -1838,7 +1831,6 @@ impl<'a> TypeChecker<'a> {
}
}

#[async_backtrace::framed]
async fn resolve_lambda_function(
&mut self,
span: Span,
Expand Down Expand Up @@ -2008,7 +2000,6 @@ impl<'a> TypeChecker<'a> {
Ok(Box::new((lambda_func, data_type)))
}

#[async_backtrace::framed]
async fn resolve_score_search_function(
&mut self,
span: Span,
Expand Down Expand Up @@ -2373,7 +2364,7 @@ impl<'a> TypeChecker<'a> {
}

/// Resolve function call.
#[async_backtrace::framed]
pub async fn resolve_function(
&mut self,
span: Span,
Expand Down Expand Up @@ -2520,7 +2511,6 @@ impl<'a> TypeChecker<'a> {
/// would be transformed into `FunctionCall`, except comparison
/// expressions, conjunction(`AND`) and disjunction(`OR`).
#[async_recursion::async_recursion]
#[async_backtrace::framed]
pub async fn resolve_binary_op(
&mut self,
span: Span,
Expand Down Expand Up @@ -2581,7 +2571,6 @@ impl<'a> TypeChecker<'a> {

/// Resolve unary expressions.
#[async_recursion::async_recursion]
#[async_backtrace::framed]
pub async fn resolve_unary_op(
&mut self,
span: Span,
Expand All @@ -2602,7 +2591,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
pub async fn resolve_extract_expr(
&mut self,
span: Span,
Expand Down Expand Up @@ -2648,7 +2636,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
pub async fn resolve_date_add(
&mut self,
span: Span,
Expand All @@ -2674,7 +2661,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
pub async fn resolve_date_trunc(
&mut self,
span: Span,
Expand Down Expand Up @@ -2742,7 +2728,6 @@ impl<'a> TypeChecker<'a> {
}
}

#[async_backtrace::framed]
pub async fn resolve_subquery(
&mut self,
typ: SubqueryType,
Expand Down Expand Up @@ -2863,7 +2848,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn try_rewrite_sugar_function(
&mut self,
span: Span,
Expand Down Expand Up @@ -3255,7 +3239,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_trim_function(
&mut self,
span: Span,
Expand Down Expand Up @@ -3315,7 +3298,6 @@ impl<'a> TypeChecker<'a> {
// TODO(leiysky): use an array builder function instead, since we should allow declaring
// an array with variable as element.
#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_array(
&mut self,
span: Span,
Expand All @@ -3331,7 +3313,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_map(
&mut self,
span: Span,
Expand All @@ -3355,7 +3336,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_tuple(
&mut self,
span: Span,
Expand All @@ -3371,7 +3351,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_like(
&mut self,
op: &BinaryOperator,
Expand Down Expand Up @@ -3412,7 +3391,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_udf(
&mut self,
span: Span,
Expand Down Expand Up @@ -3450,7 +3428,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_udf_server(
&mut self,
span: Span,
Expand Down Expand Up @@ -3515,7 +3492,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_udf_script(
&mut self,
span: Span,
Expand Down Expand Up @@ -3558,7 +3534,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_lambda_udf(
&mut self,
span: Span,
Expand Down Expand Up @@ -3608,7 +3583,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_cast_to_variant(
&mut self,
span: Span,
Expand All @@ -3624,9 +3598,8 @@ impl<'a> TypeChecker<'a> {
if let ScalarExpr::BoundColumnRef(BoundColumnRef { ref column, .. }) = scalar {
let column_entry = self.metadata.read().column(column.index).clone();
if let ColumnEntry::BaseTableColumn(BaseTableColumn { data_type, .. }) = column_entry {
let new_scalar = self
.rewrite_cast_to_variant(span, scalar, &data_type, is_try)
.await;
let new_scalar =
Self::rewrite_cast_to_variant(span, scalar, &data_type, is_try).await;
let return_type = if is_try || source_type.is_nullable() {
DataType::Nullable(Box::new(DataType::Variant))
} else {
Expand All @@ -3639,9 +3612,7 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn rewrite_cast_to_variant(
&mut self,
span: Span,
scalar: &ScalarExpr,
data_type: &TableDataType,
Expand Down Expand Up @@ -3672,8 +3643,7 @@ impl<'a> TypeChecker<'a> {

let value =
if matches!(field_type.remove_nullable(), TableDataType::Tuple { .. }) {
self.rewrite_cast_to_variant(span, &value, field_type, is_try)
.await
Self::rewrite_cast_to_variant(span, &value, field_type, is_try).await
} else {
value
};
Expand Down Expand Up @@ -3712,7 +3682,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_map_access(
&mut self,
expr: &Expr,
Expand Down Expand Up @@ -3814,7 +3783,6 @@ impl<'a> TypeChecker<'a> {
}

#[async_recursion::async_recursion]
#[async_backtrace::framed]
async fn resolve_tuple_map_access_pushdown(
&mut self,
span: Span,
Expand Down

0 comments on commit 38b4fb7

Please sign in to comment.