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
| 4689 | |
| 4690 | /// Generic function used to plan both array subqueries and list subqueries |
| 4691 | fn 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> |
| 4701 | where |
| 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 {}{}", |
no test coverage detected