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 test case for ANSI pmod and ANSI Remainder #5279

Merged
merged 3 commits into from
Apr 20, 2022
Merged
Changes from all commits
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
35 changes: 35 additions & 0 deletions integration_tests/src/main/python/arithmetic_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,41 @@ def test_pmod(data_gen):
'pmod(b, cast(null as {}))'.format(string_type),
'pmod(a, b)'))

# test pmod(Long.MinValue, -1) = 0 and Long.MinValue % -1 = 0, should not throw
def test_mod_pmod_long_min_value():
assert_gpu_and_cpu_are_equal_collect(
lambda spark : spark.createDataFrame([(-9223372036854775808,)], ["a"]).selectExpr(
'pmod(a, -1L)',
'a % -1L'),
ansi_enabled_conf)

@pytest.mark.parametrize('data_gen', _arith_data_gens_no_neg_scale, ids=idfn)
@pytest.mark.parametrize('overflow_exp', [
'pmod(a, cast(0 as {}))',
'pmod(cast(-12 as {}), cast(0 as {}))',
'a % (cast(0 as {}))',
'cast(-12 as {}) % cast(0 as {})'], ids=idfn)
def test_mod_pmod_by_zero(data_gen, overflow_exp):
string_type = to_cast_string(data_gen.data_type)
assert_gpu_and_cpu_error(
lambda spark : unary_op_df(spark, data_gen).selectExpr(
overflow_exp.format(string_type, string_type)).collect(),
ansi_enabled_conf,
# 311 throws "java.lang.ArithmeticException"
# 320+ throws "org.apache.spark.SparkArithmeticException"
"ArithmeticException")

@pytest.mark.parametrize('data_gen', _arith_data_gens_no_neg_scale, ids=idfn)
def test_mod_pmod_by_zero_not_ansi(data_gen):
string_type = to_cast_string(data_gen.data_type)
assert_gpu_and_cpu_are_equal_collect(
lambda spark : unary_op_df(spark, data_gen).selectExpr(
'pmod(a, cast(0 as {}))'.format(string_type),
'pmod(cast(-12 as {}), cast(0 as {}))'.format(string_type, string_type),
'a % (cast(0 as {}))'.format(string_type),
'cast(-12 as {}) % cast(0 as {})'.format(string_type, string_type)),
{'spark.sql.ansi.enabled': 'false'})

@pytest.mark.parametrize('data_gen', double_gens, ids=idfn)
def test_signum(data_gen):
assert_gpu_and_cpu_are_equal_collect(
Expand Down