projjal commented on a change in pull request #9750:
URL: https://github.com/apache/arrow/pull/9750#discussion_r616336819
##########
File path: cpp/src/gandiva/gdv_function_stubs_test.cc
##########
@@ -290,4 +290,121 @@ TEST(TestGdvFnStubs, TestCastVARCHARFromDouble) {
EXPECT_FALSE(ctx.has_error());
}
+TEST(TestGdvFnStubs, TestToCharFromInt32) {
+ gandiva::ExecutionContext ctx;
+ uint64_t ctx_ptr = reinterpret_cast<int64_t>(&ctx);
+ int32_t out_len = 0;
+
+ const char* out_str = gdv_fn_to_char_int32_int64(ctx_ptr, -46, 100, "##",
&out_len);
+ EXPECT_EQ(std::string(out_str, out_len), "-46");
+ EXPECT_FALSE(ctx.has_error());
+
+ out_str = gdv_fn_to_char_int32_int64(ctx_ptr, 2147483647, 100, "##########",
&out_len);
+ EXPECT_EQ(std::string(out_str, out_len), "2147483647");
+ EXPECT_FALSE(ctx.has_error());
+
+ out_str =
+ gdv_fn_to_char_int32_int64(ctx_ptr, -2147483647 - 1, 100, "##########",
&out_len);
+ EXPECT_EQ(std::string(out_str, out_len), "-2147483648");
+ EXPECT_FALSE(ctx.has_error());
+
+ out_str = gdv_fn_to_char_int32_int64(ctx_ptr, 0, 100, "#", &out_len);
+ EXPECT_EQ(std::string(out_str, out_len), "0");
+ EXPECT_FALSE(ctx.has_error());
+
+ // test with required length less than actual buffer length
+ out_str = gdv_fn_to_char_int32_int64(ctx_ptr, 34567, 3, "###", &out_len);
+ EXPECT_EQ(std::string(out_str, out_len), "345");
+ EXPECT_FALSE(ctx.has_error());
+
+ out_str = gdv_fn_to_char_int32_int64(ctx_ptr, 347, 0, "#", &out_len);
+ EXPECT_EQ(std::string(out_str, out_len), "");
+ EXPECT_FALSE(ctx.has_error());
+
+ out_str = gdv_fn_to_char_int32_int64(ctx_ptr, 347, -1, "%1", &out_len);
+ EXPECT_THAT(ctx.get_error(), ::testing::HasSubstr("Buffer length can not be
negative"));
+ ctx.Reset();
+}
+
+TEST(TestGdvFnStubs, TestToCharFromInt64) {
+ gandiva::ExecutionContext ctx;
+ uint64_t ctx_ptr = reinterpret_cast<int64_t>(&ctx);
+ int32_t out_len = 0;
+
+ const char* out_str =
+ gdv_fn_to_char_int64_int64(ctx_ptr, 9223372036854775807LL, 100, "%1",
&out_len);
Review comment:
what does %1 do?
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -300,6 +302,50 @@ char* gdv_fn_dec_to_string(int64_t context, int64_t
x_high, uint64_t x_low,
return val;
\
}
+#define GDV_FN_TO_CHAR(IN_TYPE, ARROW_TYPE)
\
+ /* Converts expression to a string using the format specified in format */
\
+ GANDIVA_EXPORT
\
+ const char* gdv_fn_to_char_##IN_TYPE##_int64(int64_t context, gdv_##IN_TYPE
value, \
+ int64_t len, const char*
pattern, int32_t * out_len) { \
Review comment:
You are not using pattern at all in your code. Doesn't look like it
should be working.
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -300,6 +302,50 @@ char* gdv_fn_dec_to_string(int64_t context, int64_t
x_high, uint64_t x_low,
return val;
\
}
+#define GDV_FN_TO_CHAR(IN_TYPE, ARROW_TYPE)
\
+ /* Converts expression to a string using the format specified in format */
\
Review comment:
Can you write a more detailed comment explaining the format?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]