Skip to content

Commit

Permalink
Remove timestamp limits for parquet tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gera Shegalov <[email protected]>
  • Loading branch information
gerashegalov committed Aug 4, 2023
1 parent 11b0159 commit 1eba8f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
4 changes: 2 additions & 2 deletions integration_tests/src/main/python/delta_lake_write_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from data_gen import *
from conftest import is_databricks_runtime
from marks import *
from parquet_write_test import limited_timestamp, parquet_part_write_gens, parquet_write_gens_list, writer_confs
from parquet_write_test import parquet_part_write_gens, parquet_write_gens_list, writer_confs
from pyspark.sql.types import *
from spark_session import is_before_spark_320, is_before_spark_330, is_databricks122_or_later, with_cpu_session

Expand Down Expand Up @@ -769,7 +769,7 @@ def test_delta_write_optimized_supported_types(spark_tmp_path):
"spark.databricks.delta.properties.defaults.autoOptimize.optimizeWrite": "true"
})
simple_gens = [ byte_gen, short_gen, int_gen, long_gen, float_gen, double_gen,
string_gen, boolean_gen, date_gen, limited_timestamp() ]
string_gen, boolean_gen, date_gen, TimestampGen() ]
genlist = simple_gens + \
[ StructGen([("child" + str(i), gen) for i, gen in enumerate(simple_gens)]) ] + \
[ StructGen([("x", StructGen([("y", int_gen)]))]) ]
Expand Down
52 changes: 12 additions & 40 deletions integration_tests/src/main/python/parquet_write_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,12 @@
writer_confs={'spark.sql.legacy.parquet.datetimeRebaseModeInWrite': 'CORRECTED',
'spark.sql.legacy.parquet.int96RebaseModeInWrite': 'CORRECTED'}


def limited_timestamp(nullable=True):
return TimestampGen(start=datetime(1677, 9, 22, tzinfo=timezone.utc), end=datetime(2262, 4, 11, tzinfo=timezone.utc),
nullable=nullable)

# TODO - we are limiting the INT96 values, see https://github.com/rapidsai/cudf/issues/8070
def limited_int96():
return TimestampGen(start=datetime(1677, 9, 22, tzinfo=timezone.utc), end=datetime(2262, 4, 11, tzinfo=timezone.utc))

parquet_basic_gen =[byte_gen, short_gen, int_gen, long_gen, float_gen, double_gen,
string_gen, boolean_gen, date_gen,
# we are limiting TimestampGen to avoid overflowing the INT96 value
# see https://github.com/rapidsai/cudf/issues/8070
limited_timestamp(), binary_gen]
string_gen, boolean_gen, date_gen, TimestampGen(), binary_gen]

parquet_basic_map_gens = [MapGen(f(nullable=False), f()) for f in [
BooleanGen, ByteGen, ShortGen, IntegerGen, LongGen, FloatGen, DoubleGen, DateGen,
limited_timestamp]] + [simple_string_to_string_map_gen,
TimestampGen]] + [simple_string_to_string_map_gen,
MapGen(DecimalGen(20, 2, nullable=False), decimal_gen_128bit),
# python is not happy with binary values being keys of a map
MapGen(StringGen("a{1,5}", nullable=False), binary_gen)]
Expand Down Expand Up @@ -110,13 +98,13 @@ def test_write_round_trip(spark_tmp_path, parquet_gens):
all_nulls_map_gen = SetValuesGen(MapType(StringType(), StringType()), [None])
all_empty_map_gen = SetValuesGen(MapType(StringType(), StringType()), [{}])

par_write_odd_empty_strings_gens_sample = [all_nulls_string_gen,
empty_or_null_string_gen,
par_write_odd_empty_strings_gens_sample = [all_nulls_string_gen,
empty_or_null_string_gen,
all_empty_string_gen,
all_nulls_array_gen,
all_empty_array_gen,
all_array_empty_string_gen,
mixed_empty_nulls_array_gen,
mixed_empty_nulls_array_gen,
mixed_empty_nulls_map_gen,
all_nulls_map_gen,
all_empty_map_gen]
Expand All @@ -131,9 +119,9 @@ def test_write_round_trip_corner(spark_tmp_path, par_gen):
data_path)

@pytest.mark.parametrize('parquet_gens', [[
limited_timestamp(),
ArrayGen(limited_timestamp(), max_length=10),
MapGen(limited_timestamp(nullable=False), limited_timestamp())]], ids=idfn)
TimestampGen(),
ArrayGen(TimestampGen(), max_length=10),
MapGen(TimestampGen(nullable=False), TimestampGen())]], ids=idfn)
@pytest.mark.parametrize('ts_type', parquet_ts_write_options)
def test_timestamp_write_round_trip(spark_tmp_path, parquet_gens, ts_type):
gen_list = [('_c' + str(i), gen) for i, gen in enumerate(parquet_gens)]
Expand All @@ -149,9 +137,7 @@ def test_timestamp_write_round_trip(spark_tmp_path, parquet_gens, ts_type):
@pytest.mark.parametrize('ts_rebase', ['CORRECTED'])
@ignore_order
def test_write_ts_millis(spark_tmp_path, ts_type, ts_rebase):
# we are limiting TimestampGen to avoid overflowing the INT96 value
# see https://github.com/rapidsai/cudf/issues/8070
gen = TimestampGen(start=datetime(1677, 9, 22, tzinfo=timezone.utc), end=datetime(2262, 4, 11, tzinfo=timezone.utc))
gen = TimestampGen()
data_path = spark_tmp_path + '/PARQUET_DATA'
assert_gpu_and_cpu_writes_are_equal_collect(
lambda spark, path: unary_op_df(spark, gen).write.parquet(path),
Expand All @@ -167,9 +153,7 @@ def test_write_ts_millis(spark_tmp_path, ts_type, ts_rebase):
# Some file systems have issues with UTF8 strings so to help the test pass even there
StringGen('(\\w| ){0,50}'),
boolean_gen, date_gen,
# we are limiting TimestampGen to avoid overflowing the INT96 value
# see https://github.com/rapidsai/cudf/issues/8070
TimestampGen(start=datetime(1677, 9, 22, tzinfo=timezone.utc), end=datetime(2262, 4, 11, tzinfo=timezone.utc))]
TimestampGen()]

# There are race conditions around when individual files are read in for partitioned data
@ignore_order
Expand All @@ -185,17 +169,6 @@ def test_part_write_round_trip(spark_tmp_path, parquet_gen):
data_path,
conf=writer_confs)

@pytest.mark.parametrize('data_gen', [TimestampGen(end=datetime(1677, 9, 22, tzinfo=timezone.utc)),
TimestampGen(start=datetime(2262, 4, 11, tzinfo=timezone.utc))], ids=idfn)
def test_fix_for_int96_overflow(spark_tmp_path, data_gen):
data_path = spark_tmp_path + '/PARQUET_DATA'
confs = copy_and_update(writer_confs, {'spark.sql.parquet.outputTimestampType': 'INT96'})
assert_gpu_and_cpu_writes_are_equal_collect(
lambda spark, path: unary_op_df(spark, data_gen).coalesce(1).write.parquet(path),
lambda spark, path: spark.read.parquet(path),
data_path,
conf = confs)


@pytest.mark.skipif(is_spark_340_or_later() or is_databricks122_or_later(), reason="`WriteFilesExec` is only supported in Spark 340+")
@pytest.mark.parametrize('data_gen', [TimestampGen()], ids=idfn)
Expand Down Expand Up @@ -293,9 +266,8 @@ def writeParquetUpgradeCatchException(spark, df, data_path, spark_tmp_table_fact
df.coalesce(1).write.format("parquet").mode('overwrite').option("path", data_path).saveAsTable(spark_tmp_table_factory.get())
assert e_info.match(r".*SparkUpgradeException.*")

# TODO - we are limiting the INT96 values, see https://github.com/rapidsai/cudf/issues/8070
@pytest.mark.parametrize('ts_write_data_gen',
[('INT96', TimestampGen(start=datetime(1677, 9, 22, tzinfo=timezone.utc), end=datetime(1899, 12, 31, tzinfo=timezone.utc))),
[('INT96', TimestampGen()),
('TIMESTAMP_MICROS', TimestampGen(start=datetime(1, 1, 1, tzinfo=timezone.utc), end=datetime(1899, 12, 31, tzinfo=timezone.utc))),
('TIMESTAMP_MILLIS', TimestampGen(start=datetime(1, 1, 1, tzinfo=timezone.utc), end=datetime(1899, 12, 31, tzinfo=timezone.utc)))])
@pytest.mark.parametrize('rebase', ["CORRECTED","EXCEPTION"])
Expand Down Expand Up @@ -490,7 +462,7 @@ def generate_map_with_empty_validity(spark, path):
lambda spark, path: spark.read.parquet(path),
data_path)

@pytest.mark.parametrize('ts_write_data_gen', [('INT96', limited_int96()),
@pytest.mark.parametrize('ts_write_data_gen', [('INT96', TimestampGen()),
('TIMESTAMP_MICROS', TimestampGen(start=datetime(1, 1, 1, tzinfo=timezone.utc), end=datetime(1582, 1, 1, tzinfo=timezone.utc))),
('TIMESTAMP_MILLIS', TimestampGen(start=datetime(1, 1, 1, tzinfo=timezone.utc), end=datetime(1582, 1, 1, tzinfo=timezone.utc)))])
@pytest.mark.parametrize('date_time_rebase_write', ["CORRECTED"])
Expand Down

0 comments on commit 1eba8f9

Please sign in to comment.