@@ -453,6 +453,77 @@ TEST(TestGdvFnStubs, TestCastVARCHARFromDouble) {
453453 EXPECT_FALSE (ctx.has_error ());
454454}
455455
456+ TEST (TestGdvFnStubs, TestSubstringIndex) {
457+ gandiva::ExecutionContext ctx;
458+ uint64_t ctx_ptr = reinterpret_cast <gdv_int64>(&ctx);
459+ gdv_int32 out_len = 0 ;
460+
461+ const char * out_str =
462+ gdv_fn_substring_index (ctx_ptr, " Abc.DE.fGh" , 10 , " ." , 1 , 2 , &out_len);
463+ EXPECT_EQ (std::string (out_str, out_len), " Abc.DE" );
464+ EXPECT_FALSE (ctx.has_error ());
465+
466+ out_str = gdv_fn_substring_index (ctx_ptr, " Abc.DE.fGh" , 10 , " ." , 1 , -2 , &out_len);
467+ EXPECT_EQ (std::string (out_str, out_len), " fGh" );
468+ EXPECT_FALSE (ctx.has_error ());
469+
470+ out_str = gdv_fn_substring_index (ctx_ptr, " S;DCGS;JO!L" , 11 , " ;" , 1 , 1 , &out_len);
471+ EXPECT_EQ (std::string (out_str, out_len), " S" );
472+ EXPECT_FALSE (ctx.has_error ());
473+
474+ out_str = gdv_fn_substring_index (ctx_ptr, " S;DCGS;JO!L" , 11 , " ;" , 1 , -1 , &out_len);
475+ EXPECT_EQ (std::string (out_str, out_len), " DCGS;JO!L" );
476+ EXPECT_FALSE (ctx.has_error ());
477+
478+ out_str = gdv_fn_substring_index (ctx_ptr, " www.mysql.com" , 13 , " Q" , 1 , 1 , &out_len);
479+ EXPECT_EQ (std::string (out_str, out_len), " www.mysql.com" );
480+ EXPECT_FALSE (ctx.has_error ());
481+
482+ out_str = gdv_fn_substring_index (ctx_ptr, " www||mysql||com" , 15 , " ||" , 2 , 2 , &out_len);
483+ EXPECT_EQ (std::string (out_str, out_len), " www||mysql" );
484+ EXPECT_FALSE (ctx.has_error ());
485+
486+ out_str = gdv_fn_substring_index (ctx_ptr, " " , 0 , " ." , 1 , 1 , &out_len);
487+ EXPECT_EQ (std::string (out_str, out_len).size (), 0 );
488+ EXPECT_FALSE (ctx.has_error ());
489+
490+ out_str = gdv_fn_substring_index (ctx_ptr, " www||mysql||com" , 15 , " " , 0 , 1 , &out_len);
491+ EXPECT_EQ (std::string (out_str, out_len).size (), 0 );
492+ EXPECT_FALSE (ctx.has_error ());
493+
494+ out_str = gdv_fn_substring_index (ctx_ptr, " www||mysql||com" , 15 , " ||" , 2 , 0 , &out_len);
495+ EXPECT_EQ (std::string (out_str, out_len).size (), 0 );
496+ EXPECT_FALSE (ctx.has_error ());
497+
498+ out_str = gdv_fn_substring_index (ctx_ptr, " www||mysql||com" , 15 , " ||" , 2 , -2 , &out_len);
499+ EXPECT_EQ (std::string (out_str, out_len), " com" );
500+ EXPECT_FALSE (ctx.has_error ());
501+
502+ out_str = gdv_fn_substring_index (ctx_ptr, " MÜNCHEN" , 8 , " Ü" , 2 , 1 , &out_len);
503+ EXPECT_EQ (std::string (out_str, out_len), " M" );
504+ EXPECT_FALSE (ctx.has_error ());
505+
506+ out_str = gdv_fn_substring_index (ctx_ptr, " MÜNCHEN" , 8 , " Ü" , 2 , -1 , &out_len);
507+ EXPECT_EQ (std::string (out_str, out_len), " NCHEN" );
508+ EXPECT_FALSE (ctx.has_error ());
509+
510+ out_str = gdv_fn_substring_index (ctx_ptr, " citroën" , 8 , " ë" , 2 , -1 , &out_len);
511+ EXPECT_EQ (std::string (out_str, out_len), " n" );
512+ EXPECT_FALSE (ctx.has_error ());
513+
514+ out_str = gdv_fn_substring_index (ctx_ptr, " citroën" , 8 , " ë" , 2 , 1 , &out_len);
515+ EXPECT_EQ (std::string (out_str, out_len), " citro" );
516+ EXPECT_FALSE (ctx.has_error ());
517+
518+ out_str = gdv_fn_substring_index (ctx_ptr, " 路学\\ L" , 8 , " \\ " , 1 , 1 , &out_len);
519+ EXPECT_EQ (std::string (out_str, out_len), " 路学" );
520+ EXPECT_FALSE (ctx.has_error ());
521+
522+ out_str = gdv_fn_substring_index (ctx_ptr, " 路学\\ L" , 8 , " \\ " , 1 , -1 , &out_len);
523+ EXPECT_EQ (std::string (out_str, out_len), " L" );
524+ EXPECT_FALSE (ctx.has_error ());
525+ }
526+
456527TEST (TestGdvFnStubs, TestUpper) {
457528 gandiva::ExecutionContext ctx;
458529 uint64_t ctx_ptr = reinterpret_cast <gdv_int64>(&ctx);
0 commit comments