-
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
Changes from 11 commits
50373a9
cd33b16
f253585
550a90f
282af71
7fc82d6
6b98079
8a684ce
178c212
0a7f4bb
5428c8e
a8c3723
6afb4bf
5ef7bb5
e3354e4
fdf4915
c7e6322
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,test_datagen_random_seed | ||
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=test_datagen_random_seed, 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=test_datagen_random_seed, num_slic | |
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=test_datagen_random_seed): | ||
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=test_datagen_random_seed, 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=test_datagen_random_seed, 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=test_datagen_random_seed, 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=test_datagen_random_seed, 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=test_datagen_random_seed, 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=test_datagen_random_seed, 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=test_datagen_random_seed, 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=test_datagen_random_seed, 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=test_datagen_random_seed, 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): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
from asserts import assert_gpu_and_cpu_are_equal_collect, assert_gpu_fallback_collect | ||
from data_gen import * | ||
from marks import allow_non_gpu, ignore_order | ||
from marks import allow_non_gpu, ignore_order, datagen_overrides | ||
from pyspark.sql.types import * | ||
import pyspark.sql.functions as f | ||
|
||
|
@@ -26,16 +26,17 @@ | |
arrays_with_binary = [ArrayGen(BinaryGen(max_length=5))] | ||
maps_with_binary = [MapGen(IntegerGen(nullable=False), BinaryGen(max_length=5))] | ||
|
||
def four_op_df(spark, gen, length=2048, seed=0): | ||
def four_op_df(spark, gen, length=2048): | ||
return gen_df(spark, StructGen([ | ||
('a', gen), | ||
('b', gen), | ||
('c', gen), | ||
('d', gen)], nullable=False), length=length, seed=seed) | ||
('d', gen)], nullable=False), length=length) | ||
|
||
#sort locally because of https://github.com/NVIDIA/spark-rapids/issues/84 | ||
# After 3.1.0 is the min spark version we can drop this | ||
@ignore_order(local=True) | ||
@datagen_overrides(seed=0) | ||
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. Where is the reason for these? |
||
@pytest.mark.parametrize('data_gen', explode_gens, ids=idfn) | ||
def test_explode_makearray(data_gen): | ||
assert_gpu_and_cpu_are_equal_collect( | ||
|
@@ -44,6 +45,7 @@ def test_explode_makearray(data_gen): | |
#sort locally because of https://github.com/NVIDIA/spark-rapids/issues/84 | ||
# After 3.1.0 is the min spark version we can drop this | ||
@ignore_order(local=True) | ||
@datagen_overrides(seed=0) | ||
@pytest.mark.parametrize('data_gen', explode_gens, ids=idfn) | ||
def test_explode_litarray(data_gen): | ||
array_lit = with_cpu_session( | ||
|
@@ -124,6 +126,7 @@ def test_explode_outer_nested_array_data(data_gen): | |
#sort locally because of https://github.com/NVIDIA/spark-rapids/issues/84 | ||
# After 3.1.0 is the min spark version we can drop this | ||
@ignore_order(local=True) | ||
@datagen_overrides(seed=0) | ||
@pytest.mark.parametrize('data_gen', explode_gens, ids=idfn) | ||
def test_posexplode_makearray(data_gen): | ||
assert_gpu_and_cpu_are_equal_collect( | ||
|
@@ -132,6 +135,7 @@ def test_posexplode_makearray(data_gen): | |
#sort locally because of https://github.com/NVIDIA/spark-rapids/issues/84 | ||
# After 3.1.0 is the min spark version we can drop this | ||
@ignore_order(local=True) | ||
@datagen_overrides(seed=0) | ||
@pytest.mark.parametrize('data_gen', explode_gens, ids=idfn) | ||
def test_posexplode_litarray(data_gen): | ||
array_lit = with_cpu_session( | ||
|
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.
Why no reason here?
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.
oh whoops, let me add that.. not intended
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.
I am re-running CI with these removed. I can't repro these locally.