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

Set hasSideEffects correctly for GpuCreateMap #5546

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions integration_tests/src/main/python/map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def test_get_map_value_timestamp_keys(data_gen):
'a[timestamp "2022-01-01"]',
'a[null]'))

def test_map_side_effects():
assert_gpu_and_cpu_are_equal_collect(
lambda spark : spark.range(10).selectExpr(
'id',
'if(id == 0, null, map(id, id, id DIV 2, id)) as m'),
conf={'spark.sql.mapKeyDedupPolicy': 'EXCEPTION'})

@pytest.mark.parametrize('key_gen', [StringGen(nullable=False), IntegerGen(nullable=False), basic_struct_gen], ids=idfn)
@pytest.mark.parametrize('value_gen', [StringGen(nullable=True), IntegerGen(nullable=True), basic_struct_gen], ids=idfn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ case class GpuCreateMap(
}
}

override lazy val hasSideEffects: Boolean =
GpuCreateMap.exceptionOnDupKeys || super.hasSideEffects

override def columnarEval(batch: ColumnarBatch): Any = {
withResource(new Array[ColumnVector](children.size)) { columns =>
val numRows = batch.numRows()
Expand Down Expand Up @@ -135,11 +138,14 @@ object GpuCreateMap extends Arm {
SQLConf.get.getConf(SQLConf.LEGACY_CREATE_EMPTY_COLLECTION_USING_STRING_TYPE))
}

def exceptionOnDupKeys: Boolean =
SQLConf.get.getConf(SQLConf.MAP_KEY_DEDUP_POLICY) ==
SQLConf.MapKeyDedupPolicy.EXCEPTION.toString

def createMapFromKeysValuesAsStructs(dataType: MapType,
listsOfKeyValueStructs : ColumnView): GpuColumnVector = {
withResource(listsOfKeyValueStructs.dropListDuplicatesWithKeysValues()) { deduped =>
if (SQLConf.get.getConf(SQLConf.MAP_KEY_DEDUP_POLICY) ==
SQLConf.MapKeyDedupPolicy.EXCEPTION.toString) {
if (exceptionOnDupKeys) {
// Compare child data row count before and after removing duplicates to determine
// if there were duplicates.
withResource(deduped.getChildColumnView(0)) { a =>
Expand Down