MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_vector_like_subquery

Function plan_vector_like_subquery

src/sql/src/plan/query.rs:4691–4804  ·  view source on GitHub ↗

Generic function used to plan both array subqueries and list subqueries

(
    ecx: &ExprContext,
    query: &Query<Aug>,
    is_unsupported_type: F1,
    vector_create: F2,
    aggregate_concat: F3,
    binary_concat: BinaryFunc,
    empty_literal: F4,
    vector_type_str

Source from the content-addressed store, hash-verified

4689
4690/// Generic function used to plan both array subqueries and list subqueries
4691fn plan_vector_like_subquery<F1, F2, F3, F4>(
4692 ecx: &ExprContext,
4693 query: &Query<Aug>,
4694 is_unsupported_type: F1,
4695 vector_create: F2,
4696 aggregate_concat: F3,
4697 binary_concat: BinaryFunc,
4698 empty_literal: F4,
4699 vector_type_string: &str,
4700) -> Result<CoercibleScalarExpr, PlanError>
4701where
4702 F1: Fn(&SqlScalarType) -> bool,
4703 F2: Fn(SqlScalarType) -> VariadicFunc,
4704 F3: Fn(Vec<ColumnOrder>) -> AggregateFunc,
4705 F4: Fn(SqlScalarType) -> HirScalarExpr,
4706{
4707 if !ecx.allow_subqueries {
4708 sql_bail!("{} does not allow subqueries", ecx.name)
4709 }
4710
4711 let mut qcx = ecx.derived_query_context();
4712 let mut planned_query = plan_query(&mut qcx, query)?;
4713 if planned_query.limit.is_some()
4714 || !planned_query
4715 .offset
4716 .clone()
4717 .try_into_literal_int64()
4718 .is_ok_and(|offset| offset == 0)
4719 {
4720 planned_query.expr = HirRelationExpr::top_k(
4721 planned_query.expr,
4722 vec![],
4723 planned_query.order_by.clone(),
4724 planned_query.limit,
4725 planned_query.offset,
4726 planned_query.group_size_hints.limit_input_group_size,
4727 );
4728 }
4729
4730 if planned_query.project.len() != 1 {
4731 sql_bail!(
4732 "Expected subselect to return 1 column, got {} columns",
4733 planned_query.project.len()
4734 );
4735 }
4736
4737 let project_column = *planned_query.project.get(0).unwrap();
4738 let elem_type = qcx
4739 .relation_type(&planned_query.expr)
4740 .column_types
4741 .get(project_column)
4742 .cloned()
4743 .unwrap()
4744 .scalar_type();
4745
4746 if is_unsupported_type(&elem_type) {
4747 bail_unsupported!(format!(
4748 "cannot build array from subquery because return type {}{}",

Callers 2

plan_list_subqueryFunction · 0.85
plan_array_subqueryFunction · 0.85

Calls 15

plan_queryFunction · 0.85
derived_query_contextMethod · 0.80
is_someMethod · 0.80
unwrapMethod · 0.80
relation_typeMethod · 0.80
enumerateMethod · 0.80
cloneMethod · 0.45
lenMethod · 0.45
getMethod · 0.45
scalar_typeMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected