(
ecx: &ExprContext,
entries: &[MapEntry<Aug>],
type_hint: Option<&SqlScalarType>,
)
| 5053 | } |
| 5054 | |
| 5055 | fn plan_map( |
| 5056 | ecx: &ExprContext, |
| 5057 | entries: &[MapEntry<Aug>], |
| 5058 | type_hint: Option<&SqlScalarType>, |
| 5059 | ) -> Result<CoercibleScalarExpr, PlanError> { |
| 5060 | let (value_type, exprs) = if entries.is_empty() { |
| 5061 | if let Some(SqlScalarType::Map { value_type, .. }) = type_hint { |
| 5062 | (value_type.without_modifiers(), vec![]) |
| 5063 | } else { |
| 5064 | sql_bail!("cannot determine type of empty map"); |
| 5065 | } |
| 5066 | } else { |
| 5067 | let type_hint = match type_hint { |
| 5068 | Some(SqlScalarType::Map { value_type, .. }) => Some(&**value_type), |
| 5069 | _ => None, |
| 5070 | }; |
| 5071 | |
| 5072 | let mut keys = vec![]; |
| 5073 | let mut values = vec![]; |
| 5074 | for MapEntry { key, value } in entries { |
| 5075 | let key = plan_expr(ecx, key)?.type_as(ecx, &SqlScalarType::String)?; |
| 5076 | let value = match value { |
| 5077 | // Special case nested MAP expressions so we can plumb |
| 5078 | // the type hint through. |
| 5079 | Expr::Map(entries) => plan_map(ecx, entries, type_hint)?, |
| 5080 | _ => plan_expr(ecx, value)?, |
| 5081 | }; |
| 5082 | keys.push(key); |
| 5083 | values.push(value); |
| 5084 | } |
| 5085 | let values = coerce_homogeneous_exprs(&ecx.with_name("MAP"), values, type_hint)?; |
| 5086 | let value_type = ecx.scalar_type(&values[0]).without_modifiers(); |
| 5087 | let out = itertools::interleave(keys, values).collect(); |
| 5088 | (value_type, out) |
| 5089 | }; |
| 5090 | |
| 5091 | if matches!(value_type, SqlScalarType::Char { .. }) { |
| 5092 | bail_unsupported!("char map"); |
| 5093 | } |
| 5094 | |
| 5095 | let expr = HirScalarExpr::call_variadic(MapBuild { value_type }, exprs); |
| 5096 | Ok(expr.into()) |
| 5097 | } |
| 5098 | |
| 5099 | /// Coerces a list of expressions such that all input expressions will be cast |
| 5100 | /// to the same type. If successful, returns a new list of expressions in the |
no test coverage detected