@@ -1083,18 +1083,60 @@ TEST_F(TestDecimal, TestCastDecimalVarCharInvalidInput) {
10831083 // Create a row-batch with some sample data
10841084 int num_records = 5 ;
10851085
1086- // invalid input
1087- auto invalid_in = MakeArrowArrayUtf8 ({" a10.5134" , " -0.0" , " -0.1" , " 10.516" , " -1000" },
1088- {true , false , true , true , true });
1089-
1090- // prepare input record batch
1091- auto in_batch_1 = arrow::RecordBatch::Make (schema, num_records, {invalid_in});
1086+ for (const std::string& invalid :
1087+ std::vector<std::string>{" a10.5134" , " 1." + std::string (100 , ' 5' ) + " x" ,
1088+ " 1." + std::string (100 , ' 5' ) + " e2147483648" }) {
1089+ SCOPED_TRACE (invalid);
1090+ auto invalid_in = MakeArrowArrayUtf8 ({invalid, " -0.0" , " -0.1" , " 10.516" , " -1000" },
1091+ {true , false , true , true , true });
1092+ auto in_batch = arrow::RecordBatch::Make (schema, num_records, {invalid_in});
1093+ arrow::ArrayVector outputs;
1094+ status = projector->Evaluate (*in_batch, pool_, &outputs);
1095+ EXPECT_FALSE (status.ok ()) << status.message ();
1096+ EXPECT_NE (status.message ().find (" not a valid decimal128 number" ), std::string::npos);
1097+ }
1098+ }
10921099
1093- // Evaluate expression
1094- arrow::ArrayVector outputs_1;
1095- status = projector->Evaluate (*in_batch_1, pool_, &outputs_1);
1096- EXPECT_FALSE (status.ok ()) << status.message ();
1097- EXPECT_NE (status.message ().find (" not a valid decimal128 number" ), std::string::npos);
1100+ TEST_F (TestDecimal, TestCastDecimalVarCharLongInputs) {
1101+ struct TestCase {
1102+ std::string input;
1103+ int32_t precision;
1104+ int32_t scale;
1105+ std::string expected;
1106+ };
1107+ for (const auto & test_case : std::vector<TestCase>{
1108+ {" 1." + std::string (50 , ' 5' ), 38 , 37 , " 1." + std::string (36 , ' 5' ) + " 6" },
1109+ {" -1." + std::string (50 , ' 5' ), 38 , 37 , " -1." + std::string (36 , ' 5' ) + " 6" },
1110+ {" 1." + std::string (100 , ' 1' ), 38 , 37 , " 1." + std::string (37 , ' 1' )},
1111+ {" 15." + std::string (50 , ' 5' ) + " e-1" , 38 , 37 ,
1112+ " 1." + std::string (36 , ' 5' ) + " 6" },
1113+ {" 0." + std::string (37 , ' 0' ) + " 5" + std::string (70 , ' 0' ), 38 , 37 ,
1114+ " 0." + std::string (36 , ' 0' ) + " 1" },
1115+ {" 0." + std::string (100 , ' 0' ) + " 5" , 38 , 37 , " 0" },
1116+ {" 9." + std::string (80 , ' 9' ), 4 , 2 , " 10.00" },
1117+ {" -9." + std::string (80 , ' 9' ), 4 , 2 , " -10.00" },
1118+ {" 99." + std::string (80 , ' 9' ), 4 , 2 , " 0.00" },
1119+ {" 0001." + std::string (80 , ' 0' ), 4 , 2 , " 1.00" },
1120+ {" 1." + std::string (100 , ' 0' ) + " e+2" , 6 , 2 , " 100.00" },
1121+ {" 1234" + std::string (100 , ' 0' ) + " e-102" , 4 , 2 , " 12.34" }}) {
1122+ SCOPED_TRACE (test_case.input );
1123+ auto decimal_type = arrow::decimal128 (test_case.precision , test_case.scale );
1124+ auto field_str = field (" in_str" , utf8 ());
1125+ auto schema = arrow::schema ({field_str});
1126+ auto expr = TreeExprBuilder::MakeExpression (" castDECIMAL" , {field_str},
1127+ field (" out" , decimal_type));
1128+ std::shared_ptr<Projector> projector;
1129+ ASSERT_OK (Projector::Make (schema, {expr}, TestConfiguration (), &projector));
1130+
1131+ auto input = MakeArrowArrayUtf8 ({test_case.input , " " }, {true , false });
1132+ auto batch = arrow::RecordBatch::Make (schema, input->length (), {input});
1133+ arrow::ArrayVector outputs;
1134+ ASSERT_OK (projector->Evaluate (*batch, pool_, &outputs));
1135+ auto expected = MakeArrowArrayDecimal (
1136+ decimal_type, MakeDecimalVector ({test_case.expected , " 0" }, test_case.scale ),
1137+ {true , false });
1138+ EXPECT_ARROW_ARRAY_EQUALS (expected, outputs[0 ]);
1139+ }
10981140}
10991141
11001142TEST_F (TestDecimal, TestVarCharDecimalNestedCast) {
0 commit comments