Skip to content

Commit

Permalink
add integration tests for duplicate key exception cases
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Dec 1, 2021
1 parent 85d841d commit f1f2a94
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion integration_tests/src/main/python/map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,36 @@ def test_map_expr_multiple_pairs():
'map("key1", b, "key2", a) as m1',
'map(a, b, b, a) as m2'))

def test_map_expr_dupe_keys_last_win():
def test_map_expr_expr_keys_dupe_last_win():
data_gen = [('a', StringGen(nullable=False)), ('b', StringGen(nullable=False))]
assert_gpu_and_cpu_are_equal_collect(
lambda spark : gen_df(spark, data_gen).selectExpr(
'map(a, b, a, b) as m2'),
conf={'spark.sql.mapKeyDedupPolicy':'LAST_WIN'})

def test_map_expr_expr_keys_dupe_exception():
data_gen = [('a', StringGen(nullable=False)), ('b', StringGen(nullable=False))]
assert_gpu_and_cpu_error(
lambda spark : gen_df(spark, data_gen).selectExpr(
'map(a, b, a, b) as m2').collect(),
conf={'spark.sql.mapKeyDedupPolicy':'EXCEPTION'},
error_message = "Duplicate map key")

def test_map_expr_literal_keys_dupe_last_win():
data_gen = [('a', StringGen(nullable=False)), ('b', StringGen(nullable=False))]
assert_gpu_and_cpu_are_equal_collect(
lambda spark : gen_df(spark, data_gen).selectExpr(
'map("key1", b, "key1", a) as m1'),
conf={'spark.sql.mapKeyDedupPolicy':'LAST_WIN'})

def test_map_expr_literal_keys_dupe_exception():
data_gen = [('a', StringGen(nullable=False)), ('b', StringGen(nullable=False))]
assert_gpu_and_cpu_error(
lambda spark : gen_df(spark, data_gen).selectExpr(
'map("key1", b, "key1", a) as m1').collect(),
conf={'spark.sql.mapKeyDedupPolicy':'EXCEPTION'},
error_message = "Duplicate map key")

def test_map_expr_multi_non_literal_keys():
data_gen = [('a', StringGen(nullable=False)), ('b', StringGen(nullable=False))]
assert_gpu_and_cpu_are_equal_collect(
Expand Down

0 comments on commit f1f2a94

Please sign in to comment.