------------------------------------------------------------------------------ ARRAY -> ARRAY ------------------------------------------------------------------------------
| 39 | // ARRAY -> ARRAY |
| 40 | //------------------------------------------------------------------------------ |
| 41 | static bool ArrayToArrayCast(Vector &source, Vector &result, idx_t count, CastParameters ¶meters) { |
| 42 | auto source_array_size = ArrayType::GetSize(source.GetType()); |
| 43 | auto target_array_size = ArrayType::GetSize(result.GetType()); |
| 44 | if (source_array_size != target_array_size) { |
| 45 | // Cant cast between arrays of different sizes |
| 46 | auto msg = StringUtil::Format("Cannot cast array of size %u to array of size %u", source_array_size, |
| 47 | target_array_size); |
| 48 | HandleCastError::AssignError(msg, parameters); |
| 49 | if (!parameters.strict) { |
| 50 | // if this was a TRY_CAST, we know every row will fail, so just return null |
| 51 | result.SetVectorType(VectorType::CONSTANT_VECTOR); |
| 52 | ConstantVector::SetNull(result, true); |
| 53 | return false; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | auto &cast_data = parameters.cast_data->Cast<ArrayBoundCastData>(); |
| 58 | if (source.GetVectorType() == VectorType::CONSTANT_VECTOR) { |
| 59 | result.SetVectorType(VectorType::CONSTANT_VECTOR); |
| 60 | |
| 61 | if (ConstantVector::IsNull(source)) { |
| 62 | ConstantVector::SetNull(result, true); |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | auto &source_cc = ArrayVector::GetEntry(source); |
| 67 | auto &result_cc = ArrayVector::GetEntry(result); |
| 68 | |
| 69 | // If the array vector is constant, the child vector must be flat (or constant if array size is 1) |
| 70 | D_ASSERT(source_cc.GetVectorType() == VectorType::FLAT_VECTOR || source_array_size == 1); |
| 71 | |
| 72 | CastParameters child_parameters(parameters, cast_data.child_cast_info.cast_data, parameters.local_state); |
| 73 | bool all_ok = cast_data.child_cast_info.function(source_cc, result_cc, source_array_size, child_parameters); |
| 74 | return all_ok; |
| 75 | } else { |
| 76 | // Flatten if not constant |
| 77 | source.Flatten(count); |
| 78 | result.SetVectorType(VectorType::FLAT_VECTOR); |
| 79 | |
| 80 | FlatVector::SetValidity(result, FlatVector::Validity(source)); |
| 81 | auto &source_cc = ArrayVector::GetEntry(source); |
| 82 | auto &result_cc = ArrayVector::GetEntry(result); |
| 83 | |
| 84 | CastParameters child_parameters(parameters, cast_data.child_cast_info.cast_data, parameters.local_state); |
| 85 | bool all_ok = |
| 86 | cast_data.child_cast_info.function(source_cc, result_cc, count * source_array_size, child_parameters); |
| 87 | return all_ok; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | //------------------------------------------------------------------------------ |
| 92 | // ARRAY -> VARCHAR |
no test coverage detected