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

Function repeat_utf8_int32

cpp/src/gandiva/precompiled/string_ops.cc:854–892  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

852}
853
854FORCE_INLINE
855const char* repeat_utf8_int32(gdv_int64 context, const char* in, gdv_int32 in_len,
856 gdv_int32 repeat_number, gdv_int32* out_len) {
857 // if the repeat number is zero, then return empty string
858 if (repeat_number == 0 || in_len <= 0) {
859 *out_len = 0;
860 return "";
861 }
862 // if the repeat number is a negative number, an error is set on context
863 if (repeat_number < 0) {
864 char err_msg[96];
865 snprintf(err_msg, sizeof(err_msg), "REPEAT: Repeat number can't be negative, got %d",
866 repeat_number);
867 gdv_fn_context_set_error_msg(context, err_msg);
868 *out_len = 0;
869 return "";
870 }
871 if (ARROW_PREDICT_FALSE(
872 arrow::internal::MultiplyWithOverflow(repeat_number, in_len, out_len))) {
873 char err_msg[128];
874 snprintf(err_msg, sizeof(err_msg),
875 "REPEAT: Would overflow maximum output size "
876 "(repeat count %d * input length %d)",
877 repeat_number, in_len);
878 gdv_fn_context_set_error_msg(context, err_msg);
879 *out_len = 0;
880 return "";
881 }
882 char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, *out_len));
883 if (ret == nullptr) {
884 gdv_fn_context_set_error_msg(context, "Could not allocate memory for output string");
885 *out_len = 0;
886 return "";
887 }
888 for (int i = 0; i < repeat_number; ++i) {
889 memcpy(ret + (i * in_len), in, in_len);
890 }
891 return ret;
892}
893
894FORCE_INLINE
895const char* concat_utf8_utf8(gdv_int64 context, const char* left, gdv_int32 left_len,

Callers 1

TESTFunction · 0.85

Calls 3

MultiplyWithOverflowFunction · 0.85

Tested by 1

TESTFunction · 0.68