MCPcopy Create free account
hub / github.com/apache/arrow / GetConverter

Function GetConverter

cpp/src/arrow/flight/sql/odbc/odbc_impl/util.cc:909–1022  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

907}
908
909ArrayConvertTask GetConverter(Type::type original_type_id, CDataType target_type) {
910 // The else statement has a convert the works for the most case of array
911 // conversion. In case, we find conversion that the default one can't handle
912 // we can include some additional if-else statement with the logic to handle
913 // it
914 if (original_type_id == Type::STRING && target_type == CDataType_TIME) {
915 return [=](const std::shared_ptr<Array>& original_array) {
916 arrow::compute::StrptimeOptions options("%H:%M", TimeUnit::MICRO, false);
917
918 auto converted_result = arrow::compute::Strptime({original_array}, options);
919 auto first_converted_array = CheckConversion(converted_result);
920
921 arrow::compute::CastOptions cast_options;
922 cast_options.to_type = time64(TimeUnit::MICRO);
923 return CheckConversion(
924 arrow::compute::CallFunction("cast", {first_converted_array}, &cast_options));
925 };
926 } else if (original_type_id == Type::TIME32 && target_type == CDataType_TIMESTAMP) {
927 return [=](const std::shared_ptr<Array>& original_array) {
928 arrow::compute::CastOptions cast_options;
929 cast_options.to_type = arrow::int32();
930
931 auto first_converted_array =
932 CheckConversion(arrow::compute::Cast(original_array, cast_options));
933
934 cast_options.to_type = arrow::int64();
935
936 auto second_converted_array =
937 CheckConversion(arrow::compute::Cast(first_converted_array, cast_options));
938
939 auto seconds_from_epoch = GetTodayTimeFromEpoch();
940
941 auto third_converted_array = CheckConversion(
942 arrow::compute::Add(second_converted_array,
943 std::make_shared<Int64Scalar>(seconds_from_epoch * 1000)));
944
945 arrow::compute::CastOptions cast_options_2;
946 cast_options_2.to_type = arrow::timestamp(TimeUnit::MILLI);
947
948 return CheckConversion(arrow::compute::Cast(third_converted_array, cast_options_2));
949 };
950 } else if (original_type_id == Type::TIME64 && target_type == CDataType_TIMESTAMP) {
951 return [=](const std::shared_ptr<Array>& original_array) {
952 arrow::compute::CastOptions cast_options;
953 cast_options.to_type = arrow::int64();
954
955 auto first_converted_array =
956 CheckConversion(arrow::compute::Cast(original_array, cast_options));
957
958 auto seconds_from_epoch = GetTodayTimeFromEpoch();
959
960 auto second_converted_array = CheckConversion(arrow::compute::Add(
961 first_converted_array,
962 std::make_shared<Int64Scalar>(seconds_from_epoch * 1000000000)));
963
964 arrow::compute::CastOptions cast_options_2;
965 cast_options_2.to_type = arrow::timestamp(TimeUnit::NANO);
966

Callers 2

convertArrayFunction · 0.70
CastArrayFunction · 0.70

Calls 15

CheckConversionFunction · 0.85
CallFunctionFunction · 0.85
CastFunction · 0.85
GetTodayTimeFromEpochFunction · 0.85
ThrowIfNotOKFunction · 0.85
IsComplexTypeFunction · 0.85
ConvertToJsonFunction · 0.85
ConvertCToArrowTypeFunction · 0.85
ValueOrDieMethod · 0.80
StrptimeFunction · 0.50
time64Function · 0.50

Tested by 1

convertArrayFunction · 0.56