Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rand function for seed in int64 type #78

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add unit test cases
PHILO-HE committed Jan 18, 2022
commit d7335b918f38308e6799015c5fa40fced0ab028f
2 changes: 1 addition & 1 deletion cpp/src/gandiva/function_registry_math_ops.cc
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ std::vector<NativeFunction> GetMathOpsFunctionRegistry() {
NativeFunction("random", {"rand"}, DataTypeVector{int32()}, float64(),
kResultNullNever, "gdv_fn_random_with_seed",
NativeFunction::kNeedsFunctionHolder),
NativeFunction("random", {"rand64"}, DataTypeVector{int64()}, float64(),
NativeFunction("random", {"rand"}, DataTypeVector{int64()}, float64(),
kResultNullNever, "gdv_fn_random_with_seed64",
NativeFunction::kNeedsFunctionHolder)};

21 changes: 21 additions & 0 deletions cpp/src/gandiva/random_generator_holder_test.cc
Original file line number Diff line number Diff line change
@@ -85,6 +85,27 @@ TEST_F(TestRandGenHolder, WithValidSeeds) {
EXPECT_NE(random_1(), random_2());
}

TEST_F(TestRandGenHolder, WithValidSeedsInLongType) {
std::shared_ptr<RandomGeneratorHolder> rand_gen_holder_1;
std::shared_ptr<RandomGeneratorHolder> rand_gen_holder_2;
std::shared_ptr<RandomGeneratorHolder> rand_gen_holder_3;
FunctionNode rand_func_1 = BuildRandWithSeedFunc(100L, false);
FunctionNode rand_func_2 = BuildRandWithSeedFunc(1000L, false);
FunctionNode rand_func_3 = BuildRandWithSeedFunc(100000L, false);
auto status = RandomGeneratorHolder::Make(rand_func_1, &rand_gen_holder_1);
EXPECT_EQ(status.ok(), true) << status.message();
status = RandomGeneratorHolder::Make(rand_func_2, &rand_gen_holder_2);
EXPECT_EQ(status.ok(), true) << status.message();
status = RandomGeneratorHolder::Make(rand_func_3, &rand_gen_holder_3);
EXPECT_EQ(status.ok(), true) << status.message();

auto& random_1 = *rand_gen_holder_1;
auto& random_2 = *rand_gen_holder_2;
auto& random_3 = *rand_gen_holder_3;
EXPECT_NE(random_2(), random_3());
EXPECT_NE(random_1(), random_2());
}

TEST_F(TestRandGenHolder, WithInValidSeed) {
std::shared_ptr<RandomGeneratorHolder> rand_gen_holder_1;
std::shared_ptr<RandomGeneratorHolder> rand_gen_holder_2;