| 9 | namespace function { |
| 10 | |
| 11 | static std::unique_ptr<FunctionBindData> bindFunc(const ScalarBindFuncInput& input) { |
| 12 | std::vector<StructField> fields; |
| 13 | if (input.arguments.size() > INVALID_STRUCT_FIELD_IDX - 1) { |
| 14 | throw BinderException(std::format("Too many fields in STRUCT literal (max {}, got {})", |
| 15 | INVALID_STRUCT_FIELD_IDX - 1, input.arguments.size())); |
| 16 | } |
| 17 | std::unordered_set<std::string> fieldNameSet; |
| 18 | for (auto i = 0u; i < input.arguments.size(); i++) { |
| 19 | auto& argument = input.arguments[i]; |
| 20 | if (argument->getDataType().getLogicalTypeID() == LogicalTypeID::ANY) { |
| 21 | argument->cast(LogicalType::STRING()); |
| 22 | } |
| 23 | if (i >= input.optionalArguments.size()) { |
| 24 | throw BinderException( |
| 25 | std::format("Cannot infer field name for {}.", argument->toString())); |
| 26 | } |
| 27 | auto fieldName = input.optionalArguments[i]; |
| 28 | if (fieldNameSet.contains(fieldName)) { |
| 29 | throw BinderException(std::format("Found duplicate field {} in STRUCT.", fieldName)); |
| 30 | } else { |
| 31 | fieldNameSet.insert(fieldName); |
| 32 | } |
| 33 | fields.emplace_back(fieldName, argument->getDataType().copy()); |
| 34 | } |
| 35 | const auto resultType = LogicalType::STRUCT(std::move(fields)); |
| 36 | return FunctionBindData::getSimpleBindData(input.arguments, resultType); |
| 37 | } |
| 38 | |
| 39 | void StructPackFunctions::compileFunc(FunctionBindData* /*bindData*/, |
| 40 | const std::vector<std::shared_ptr<ValueVector>>& parameters, |
nothing calls this directly
no test coverage detected