diff --git a/cpp/src/arrow/util/value_parsing.h b/cpp/src/arrow/util/value_parsing.h index 00295d1b51f3..47c9fe6d4f0d 100644 --- a/cpp/src/arrow/util/value_parsing.h +++ b/cpp/src/arrow/util/value_parsing.h @@ -157,6 +157,9 @@ inline uint8_t ParseDecimalDigit(char c) { return static_cast(c - '0'); #define PARSE_UNSIGNED_ITERATION(C_TYPE) \ if (length > 0) { \ + if (*s == '.') { \ + break; \ + } \ uint8_t digit = ParseDecimalDigit(*s++); \ result = static_cast(result * 10U); \ length--; \ @@ -175,6 +178,9 @@ inline uint8_t ParseDecimalDigit(char c) { return static_cast(c - '0'); /* Overflow */ \ return false; \ } \ + if (*s == '.') { \ + break; \ + } \ uint8_t digit = ParseDecimalDigit(*s++); \ result = static_cast(result * 10U); \ C_TYPE new_result = static_cast(result + digit); \ diff --git a/cpp/src/gandiva/gdv_function_stubs_test.cc b/cpp/src/gandiva/gdv_function_stubs_test.cc index 8f44ce279829..db7a9bb4f081 100644 --- a/cpp/src/gandiva/gdv_function_stubs_test.cc +++ b/cpp/src/gandiva/gdv_function_stubs_test.cc @@ -47,10 +47,11 @@ TEST(TestGdvFnStubs, TestCastINT) { ::testing::HasSubstr("Failed to cast the string -2147483649 to int32")); ctx.Reset(); - gdv_fn_castINT_utf8(ctx_ptr, "12.34", 5); - EXPECT_THAT(ctx.get_error(), - ::testing::HasSubstr("Failed to cast the string 12.34 to int32")); - ctx.Reset(); + // gdv_fn_castINT_utf8(ctx_ptr, "12.34", 5); + // EXPECT_THAT(ctx.get_error(), + // ::testing::HasSubstr("Failed to cast the string 12.34 to int32")); + // ctx.Reset(); + EXPECT_EQ(gdv_fn_castINT_utf8(ctx_ptr, "12.34", 5), 12); gdv_fn_castINT_utf8(ctx_ptr, "abc", 3); EXPECT_THAT(ctx.get_error(), @@ -97,10 +98,11 @@ TEST(TestGdvFnStubs, TestCastBIGINT) { ::testing::HasSubstr("Failed to cast the string -9223372036854775809 to int64")); ctx.Reset(); - gdv_fn_castBIGINT_utf8(ctx_ptr, "12.34", 5); - EXPECT_THAT(ctx.get_error(), - ::testing::HasSubstr("Failed to cast the string 12.34 to int64")); - ctx.Reset(); + // gdv_fn_castBIGINT_utf8(ctx_ptr, "12.34", 5); + // EXPECT_THAT(ctx.get_error(), + // ::testing::HasSubstr("Failed to cast the string 12.34 to int64")); + // ctx.Reset(); + EXPECT_EQ(gdv_fn_castINT_utf8(ctx_ptr, "12.34", 5), 12); gdv_fn_castBIGINT_utf8(ctx_ptr, "abc", 3); EXPECT_THAT(ctx.get_error(),