vvellanki commented on a change in pull request #11054:
URL: https://github.com/apache/arrow/pull/11054#discussion_r741671497
##########
File path: cpp/src/gandiva/precompiled/string_ops_test.cc
##########
@@ -53,6 +53,70 @@ TEST(TestStringOps, TestAscii) {
EXPECT_EQ(ascii_utf8("999", 3), 57);
}
+TEST(TestStringOps, TestChr) {
+ // CHR
+ gandiva::ExecutionContext ctx;
+ uint64_t ctx_ptr = reinterpret_cast<gdv_int64>(&ctx);
+ int32_t out_len = 0;
+
+ auto out = chr_int32(ctx_ptr, 88, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "X");
+
+ out = chr_int32(ctx_ptr, 65, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "A");
+
+ out = chr_int32(ctx_ptr, 49, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "1");
+
+ out = chr_int32(ctx_ptr, 84, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "T");
+
+ out = chr_int32(ctx_ptr, 340, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "T");
+
+ out = chr_int32(ctx_ptr, -5, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "");
+
+ out = chr_int32(ctx_ptr, -340, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "");
+
+ out = chr_int32(ctx_ptr, 256, &out_len);
+ EXPECT_EQ(std::string(out, out_len), "");
Review comment:
This is wrong, it should return the char value of 0
##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -1361,6 +1361,26 @@ gdv_int32 ascii_utf8(const char* data, gdv_int32
data_len) {
return static_cast<gdv_int32>(data[0]);
}
+// Returns the ASCII character having the binary equivalent to A.
+// If A is larger than 256 the result is equivalent to chr(A % 256).
+GANDIVA_EXPORT
+const char* chr_int32(gdv_int64 context, gdv_int32 in, gdv_int32* out_len) {
+ in = in % 256;
+ if (in <= 0) {
Review comment:
What about 0? Why is this returning an empty string for 0? Hive UDF is
not returning an empty string for 0
##########
File path: cpp/src/gandiva/precompiled/string_ops_test.cc
##########
@@ -53,6 +53,37 @@ TEST(TestStringOps, TestAscii) {
EXPECT_EQ(ascii_utf8("999", 3), 57);
}
+TEST(TestStringOps, TestChr) {
+ // CHR
+ gandiva::ExecutionContext ctx;
+ uint64_t ctx_ptr = reinterpret_cast<gdv_int64>(&ctx);
+ int32_t out_len = 0;
+
+ auto out = chr_int32(ctx_ptr, 88, &out_len);
Review comment:
Please add a test for 0 and 255
##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -65,6 +65,9 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
UNARY_SAFE_NULL_NEVER_BOOL_FN(isnull, {}),
UNARY_SAFE_NULL_NEVER_BOOL_FN(isnotnull, {}),
+ NativeFunction("chr", {}, DataTypeVector{int32()}, utf8(),
kResultNullIfNull,
Review comment:
Hive implements this for bigint and double. I dont see the Hive
documentation implementing this for int
##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -1361,6 +1361,26 @@ gdv_int32 ascii_utf8(const char* data, gdv_int32
data_len) {
return static_cast<gdv_int32>(data[0]);
}
+// Returns the ASCII character having the binary equivalent to A.
+// If A is larger than 256 the result is equivalent to chr(A % 256).
+GANDIVA_EXPORT
+const char* chr_int32(gdv_int64 context, gdv_int32 in, gdv_int32* out_len) {
+ in = in % 256;
Review comment:
Please move this after the if-statement
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]