-
Notifications
You must be signed in to change notification settings - Fork 240
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 a random seed specific to datagen cases #9441
Merged
abellina
merged 17 commits into
NVIDIA:branch-23.12
from
abellina:add_test_seed_for_datagen
Nov 15, 2023
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
50373a9
Add a random seed specific to datagen cases
abellina cd33b16
Add seed to the test name
abellina f253585
Fix extra global that was pending from a prior pr
abellina 550a90f
Add test marker datagen_overrides, with seed as a supported argument:…
abellina 282af71
Fix typo
abellina 7fc82d6
Remove hard coding seed in collection_ops_test
abellina 6b98079
Upmerge 23.12
abellina 8a684ce
Pass seed to step_gen start otherwise we get errors that _gen_func is…
abellina 178c212
Merge branch 'branch-23.12' of https://github.com/NVIDIA/spark-rapids…
abellina 0a7f4bb
Add datagen_overrides for tests that failed
abellina 5428c8e
add more overrides
abellina a8c3723
Upmerge
abellina 6afb4bf
add override for test_datetime_roundtrip_with_legacy_rebase
abellina 5ef7bb5
Add override for test_cast_string_ts_valid_format
abellina e3354e4
Remove overrides without reason to try and repro in CI
abellina fdf4915
Add another override, this time for ast_test
abellina c7e6322
Add override for test_floor_scale_zero
abellina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
from spark_session import is_tz_utc, is_before_spark_340, with_cpu_session | ||
import sre_yield | ||
import struct | ||
from conftest import skip_unless_precommit_tests | ||
from conftest import skip_unless_precommit_tests,get_datagen_seed | ||
import time | ||
import os | ||
from functools import lru_cache | ||
|
@@ -756,14 +756,19 @@ def skip_if_not_utc(): | |
# Note: Current(2023/06/06) maxmium IT data size is 7282688 bytes, so LRU cache with maxsize 128 | ||
# will lead to 7282688 * 128 = 932 MB additional memory usage in edge case, which is acceptable. | ||
@lru_cache(maxsize=128, typed=True) | ||
def gen_df_help(data_gen, length, seed): | ||
rand = random.Random(seed) | ||
def gen_df_help(data_gen, length, seed_value): | ||
rand = random.Random(seed_value) | ||
data_gen.start(rand) | ||
data = [data_gen.gen() for index in range(0, length)] | ||
return data | ||
|
||
def gen_df(spark, data_gen, length=2048, seed=0, num_slices=None): | ||
def gen_df(spark, data_gen, length=2048, seed=None, num_slices=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want a follow on issue to remove seed for gen_df and force us to go through the annotation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"""Generate a spark dataframe from the given data generators.""" | ||
if seed is None: | ||
seed_value = get_datagen_seed() | ||
else: | ||
seed_value = seed | ||
|
||
if isinstance(data_gen, list): | ||
src = StructGen(data_gen, nullable=False) | ||
else: | ||
|
@@ -775,7 +780,7 @@ def gen_df(spark, data_gen, length=2048, seed=0, num_slices=None): | |
if src.contains_ts(): | ||
skip_if_not_utc() | ||
|
||
data = gen_df_help(src, length, seed) | ||
data = gen_df_help(src, length, seed_value) | ||
|
||
# We use `numSlices` to create an RDD with the specific number of partitions, | ||
# which is then turned into a dataframe. If not specified, it is `None` (default spark value) | ||
|
@@ -816,39 +821,44 @@ def _mark_as_lit(data, data_type): | |
# lit does not take a data type so we might have to cast it | ||
return f.lit(data).cast(data_type) | ||
|
||
def _gen_scalars_common(data_gen, count, seed=0): | ||
def _gen_scalars_common(data_gen, count, seed=None): | ||
if isinstance(data_gen, list): | ||
src = StructGen(data_gen, nullable=False) | ||
else: | ||
src = data_gen | ||
|
||
if seed is None: | ||
seed_value = get_datagen_seed() | ||
else: | ||
seed_value = seed | ||
|
||
# Before we get too far we need to verify that we can run with timestamps | ||
if src.contains_ts(): | ||
skip_if_not_utc() | ||
|
||
rand = random.Random(seed) | ||
rand = random.Random(seed_value) | ||
src.start(rand) | ||
return src | ||
|
||
def gen_scalars(data_gen, count, seed=0, force_no_nulls=False): | ||
def gen_scalars(data_gen, count, seed=None, force_no_nulls=False): | ||
"""Generate scalar values.""" | ||
if force_no_nulls: | ||
assert(not isinstance(data_gen, NullGen)) | ||
src = _gen_scalars_common(data_gen, count, seed=seed) | ||
data_type = src.data_type | ||
return (_mark_as_lit(src.gen(force_no_nulls=force_no_nulls), data_type) for i in range(0, count)) | ||
|
||
def gen_scalar(data_gen, seed=0, force_no_nulls=False): | ||
def gen_scalar(data_gen, seed=None, force_no_nulls=False): | ||
"""Generate a single scalar value.""" | ||
v = list(gen_scalars(data_gen, 1, seed=seed, force_no_nulls=force_no_nulls)) | ||
return v[0] | ||
|
||
def gen_scalar_values(data_gen, count, seed=0, force_no_nulls=False): | ||
def gen_scalar_values(data_gen, count, seed=None, force_no_nulls=False): | ||
"""Generate scalar values.""" | ||
src = _gen_scalars_common(data_gen, count, seed=seed) | ||
return (src.gen(force_no_nulls=force_no_nulls) for i in range(0, count)) | ||
|
||
def gen_scalar_value(data_gen, seed=0, force_no_nulls=False): | ||
def gen_scalar_value(data_gen, seed=None, force_no_nulls=False): | ||
"""Generate a single scalar value.""" | ||
v = list(gen_scalar_values(data_gen, 1, seed=seed, force_no_nulls=force_no_nulls)) | ||
return v[0] | ||
|
@@ -890,18 +900,18 @@ def tmp(something): | |
return meta + idfn(something) | ||
return tmp | ||
|
||
def three_col_df(spark, a_gen, b_gen, c_gen, length=2048, seed=0, num_slices=None): | ||
def three_col_df(spark, a_gen, b_gen, c_gen, length=2048, seed=None, num_slices=None): | ||
gen = StructGen([('a', a_gen),('b', b_gen),('c', c_gen)], nullable=False) | ||
return gen_df(spark, gen, length=length, seed=seed, num_slices=num_slices) | ||
|
||
def two_col_df(spark, a_gen, b_gen, length=2048, seed=0, num_slices=None): | ||
def two_col_df(spark, a_gen, b_gen, length=2048, seed=None, num_slices=None): | ||
gen = StructGen([('a', a_gen),('b', b_gen)], nullable=False) | ||
return gen_df(spark, gen, length=length, seed=seed, num_slices=num_slices) | ||
|
||
def binary_op_df(spark, gen, length=2048, seed=0, num_slices=None): | ||
def binary_op_df(spark, gen, length=2048, seed=None, num_slices=None): | ||
return two_col_df(spark, gen, gen, length=length, seed=seed, num_slices=num_slices) | ||
|
||
def unary_op_df(spark, gen, length=2048, seed=0, num_slices=None): | ||
def unary_op_df(spark, gen, length=2048, seed=None, num_slices=None): | ||
return gen_df(spark, StructGen([('a', gen)], nullable=False), | ||
length=length, seed=seed, num_slices=num_slices) | ||
|
||
|
@@ -974,7 +984,7 @@ def _convert_to_sql(spark_type, data): | |
else: | ||
return 'CAST({} as {})'.format(d, to_cast_string(spark_type)) | ||
|
||
def gen_scalars_for_sql(data_gen, count, seed=0, force_no_nulls=False): | ||
def gen_scalars_for_sql(data_gen, count, seed=None, force_no_nulls=False): | ||
"""Generate scalar values, but strings that can be used in selectExpr or SQL""" | ||
src = _gen_scalars_common(data_gen, count, seed=seed) | ||
if isinstance(data_gen, NullGen): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the global not needed any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something I owed @gerashegalov from a long time ago #7925 (comment).
Since we don't need to change the variable, it's not needed.