214990 {
214991 idx_t array_size = ArrayType::GetSize(result.GetType());
214992 bool all_lengths_match = true;
214993
214994 for (
idx_t i = 0; i < count; i++) {
214996 if (sel) {
214997 idx = sel->get_index(i);
214998 }
214999 if (!source_mask.RowIsValid(idx)) {
215000 continue;
215001 }
215002 auto str_array_size = VectorStringToList::CountPartsList(source_data[idx]);
215003 if (array_size != str_array_size) {
215004 if (all_lengths_match) {
215005 all_lengths_match = false;
215006 auto msg =
StringUtil::Format(
"Type VARCHAR with value '%s' can't be cast to the destination type %s"
215007 ", the size of the array must match the destination type",
215008 source_data[idx].GetString(), result.GetType().ToString());
215009 if (parameters.strict) {
215010 throw ConversionException(msg);
215011 }
215012 HandleCastError::AssignError(msg, parameters);
215013 }
215014 result_mask.SetInvalid(i);
215015 }
215016 }
215017
215018 auto child_count = array_size * count;
215019 Vector varchar_vector(LogicalType::VARCHAR, child_count);
215020 auto child_data = FlatVector::GetData<string_t>(varchar_vector);
215021
215022 VectorTryCastData vector_cast_data(result, parameters);
215024 for (
idx_t i = 0; i < count; i++) {
215026 if (sel) {
215027 idx = sel->get_index(i);
215028 }
215029
215030 if (!source_mask.RowIsValid(idx) || !result_mask.RowIsValid(i)) {
215031
215032 result_mask.SetInvalid(i);
215033
215034
215035 for (
idx_t j = 0; j < array_size; j++) {
215036 FlatVector::SetNull(varchar_vector, i * array_size + j, true);
215037 }
215038
215039 total += array_size;
215040 continue;
215041 }
215042
215043 if (!VectorStringToList::SplitStringList(source_data[idx], child_data, total, varchar_vector)) {
215044 auto error =
StringUtil::Format(
"Type VARCHAR with value '%s' can't be cast to the destination type %s",
215045 source_data[idx].GetString(), result.GetType().ToString());
215046 HandleVectorCastError::Operation<string_t>(error, result_mask, i, vector_cast_data);
215047 }
215048 }
215049 D_ASSERT(total == child_count);
215050
215052 auto &cast_data = parameters.cast_data->Cast<ArrayBoundCastData>();
215053 CastParameters child_parameters(parameters, cast_data.child_cast_info.cast_data, parameters.local_state);
215054 bool cast_result = cast_data.child_cast_info.function(varchar_vector, result_child, child_count, child_parameters);
215055
215056 return all_lengths_match && cast_result && vector_cast_data.all_converted;
215057}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of an array.
Definition duckdb.cpp:138574