This binder is used to throw when the child expression is of a type that is not allowed.
361708 {
361709 auto operator_type = op.GetExpressionType();
361710 if (operator_type == ExpressionType::GROUPING_FUNCTION) {
361711 return BindGroupingFunction(op, depth);
361712 }
361713
361714
361715
361716 ErrorData error;
361717 if (operator_type == ExpressionType::OPERATOR_TRY) {
361718 D_ASSERT(op.children.size() == 1);
361720 TryOperatorBinder try_operator_binder(binder, context);
361721 try_operator_binder.BindChild(op.children[0], depth, error);
361722 } else {
361723 for (
idx_t i = 0; i < op.children.size(); i++) {
361724 BindChild(op.children[i], depth, error);
361725 }
361726 }
361727
361728 if (error.HasError()) {
361729 return BindResult(std::move(error));
361730 }
361731
361732
361733 string function_name;
361734 switch (op.GetExpressionType()) {
361735 case ExpressionType::OPERATOR_UNPACK:
361736 return BindResult("UNPACK not allowed here, should have been resolved earlier");
361737 case ExpressionType::ARRAY_EXTRACT: {
361738 D_ASSERT(op.children[0]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361739 auto &b_exp = BoundExpression::GetExpression(*op.children[0]);
361740 const auto &b_exp_type = b_exp->return_type;
361741 if (b_exp_type.id() == LogicalTypeId::MAP) {
361742 function_name = "map_extract_value";
361743 } else if (b_exp_type.IsJSONType() && op.children.size() == 2) {
361744 function_name = "json_extract";
361745
361746 auto &i_exp = BoundExpression::GetExpression(*op.children[1]);
361747 if (i_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT &&
361748 !i_exp->Cast<BoundConstantExpression>().value.IsNull()) {
361749 auto &const_exp = i_exp->Cast<BoundConstantExpression>();
361750 if (const_exp.value.TryCastAs(context, LogicalType::UINTEGER)) {
361751
361752 auto index = UIntegerValue::Get(const_exp.value);
361754 const_exp.return_type = LogicalType::VARCHAR;
361755 } else if (const_exp.return_type.id() == LogicalType::VARCHAR) {
361756
361758 const_exp.return_type = LogicalType::VARCHAR;
361759 }
361760 }
361761 } else if (b_exp_type.id() == LogicalTypeId::VARIANT && op.children.size() == 2) {
361762 function_name = "variant_extract";
361763 auto &i_exp = BoundExpression::GetExpression(*op.children[1]);
361764 if (i_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
361765 auto &const_exp = i_exp->Cast<BoundConstantExpression>();
361766 if (!const_exp.value.IsNull() && const_exp.return_type.IsNumeric()) {
361767 const_exp.value = const_exp.value.DefaultCastAs(LogicalType::UINTEGER, true);
361768 const_exp.return_type = LogicalType::UINTEGER;
361769 }
361770 }
361771 } else {
361772 function_name = "array_extract";
361773 }
361774 break;
361775 }
361776 case ExpressionType::ARRAY_SLICE:
361777 function_name = "array_slice";
361778 break;
361779 case ExpressionType::STRUCT_EXTRACT: {
361780 D_ASSERT(op.children.size() == 2);
361781 D_ASSERT(op.children[0]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361782 D_ASSERT(op.children[1]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361783 auto &extract_exp = BoundExpression::GetExpression(*op.children[0]);
361784 if (extract_exp->HasParameter() || extract_exp->return_type.id() == LogicalTypeId::UNKNOWN) {
361785 throw ParameterNotResolvedException();
361786 }
361787 auto &name_exp = BoundExpression::GetExpression(*op.children[1]);
361788 const auto &extract_expr_type = extract_exp->return_type;
361789 if (extract_expr_type.id() != LogicalTypeId::STRUCT && extract_expr_type.id() != LogicalTypeId::UNION &&
361790 extract_expr_type.id() != LogicalTypeId::MAP && extract_expr_type.id() != LogicalTypeId::SQLNULL &&
361791 !extract_expr_type.IsJSONType() && extract_expr_type.id() != LogicalTypeId::VARIANT) {
361793 "Cannot extract field %s from expression \"%s\" because it is not a struct, union, map, or json",
361794 name_exp->ToString(), extract_exp->ToString()));
361795 }
361796 if (extract_expr_type.id() == LogicalTypeId::UNION) {
361797 function_name = "union_extract";
361798 } else if (extract_expr_type.id() == LogicalTypeId::MAP) {
361799 function_name = "map_extract_value";
361800 } else if (extract_expr_type.id() == LogicalTypeId::VARIANT) {
361801 function_name = "variant_extract";
361802 auto &i_exp = BoundExpression::GetExpression(*op.children[1]);
361803 if (i_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
361804 auto &const_exp = i_exp->Cast<BoundConstantExpression>();
361805 if (!const_exp.value.IsNull()) {
361807 const_exp.return_type = LogicalType::VARCHAR;
361808 }
361809 }
361810 } else if (extract_expr_type.IsJSONType()) {
361811 function_name = "json_extract";
361812
361813 if (name_exp->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) {
361814 auto &const_exp = name_exp->Cast<BoundConstantExpression>();
361815 if (!const_exp.value.IsNull()) {
361817 const_exp.return_type = LogicalType::VARCHAR;
361818 }
361819 }
361820 } else {
361821 function_name = "struct_extract";
361822 }
361823 break;
361824 }
361825 case ExpressionType::ARRAY_CONSTRUCTOR:
361826 function_name = "list_value";
361827 break;
361828 case ExpressionType::ARROW:
361829 function_name = "json_extract";
361830 break;
361831 case ExpressionType::OPERATOR_TRY: {
361832 auto &expr = BoundExpression::GetExpression(*op.children[0]);
361833 if (expr->HasSubquery()) {
361834 throw BinderException("TRY can not be used in combination with a scalar subquery");
361835 }
361836 if (expr->IsVolatile()) {
361837 throw BinderException("TRY can not be used in combination with a volatile function");
361838 }
361839 break;
361840 }
361841 default:
361842 break;
361843 }
361844 if (!function_name.empty()) {
361845 auto function = make_uniq_base<ParsedExpression, FunctionExpression>(function_name, std::move(op.children));
361847 }
361848
361849 vector<unique_ptr<Expression>> children;
361850 for (
idx_t i = 0; i < op.children.size(); i++) {
361851 D_ASSERT(op.children[i]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION);
361852 children.push_back(std::move(BoundExpression::GetExpression(*op.children[i])));
361853 }
361854
361855 LogicalType result_type = ResolveOperatorType(op, children);
361856 if (op.GetExpressionType() == ExpressionType::OPERATOR_COALESCE) {
361857 if (children.empty()) {
361858 throw BinderException("COALESCE needs at least one child");
361859 }
361860 if (children.size() == 1) {
361861 return BindResult(std::move(children[0]));
361862 }
361863 }
361864
361865 auto result = make_uniq<BoundOperatorExpression>(op.GetExpressionType(), result_type);
361866 for (auto &child : children) {
361867 result->children.push_back(std::move(child));
361868 }
361869 return BindResult(std::move(result));
361870}