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

Fix bug with InSet and Strings #437

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions integration_tests/src/main/python/cmp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ def test_in(data_gen):
assert_gpu_and_cpu_are_equal_collect(
lambda spark : unary_op_df(spark, data_gen).select(f.col('a').isin(scalars)))

# The difference between a set in and a regular in is the number of arguments, with the default
abellina marked this conversation as resolved.
Show resolved Hide resolved
# config setting 10 as the threashold. Anything over 10 is an InSet
abellina marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize('data_gen', eq_gens, ids=idfn)
def test_in_set(data_gen):
# nulls are not supported for in on the GPU yet
scalars = list(gen_scalars(data_gen, 11, force_no_nulls=True))
abellina marked this conversation as resolved.
Show resolved Hide resolved
assert_gpu_and_cpu_are_equal_collect(
lambda spark : unary_op_df(spark, data_gen).select(f.col('a').isin(scalars)))

Original file line number Diff line number Diff line change
Expand Up @@ -1052,14 +1052,14 @@ object GpuOverrides {
if (in.hset.contains(null)) {
willNotWorkOnGpu("nulls are not supported")
}
val literalTypes = in.hset.map(Literal(_).dataType).toSeq
val literalTypes = in.hset.map(LiteralHelper(_).dataType).toSeq
if (!areAllSupportedTypes(literalTypes:_*)) {
val unsupported = literalTypes.filter(!areAllSupportedTypes(_)).mkString(", ")
willNotWorkOnGpu(s"unsupported literal types: $unsupported")
}
}
override def convertToGpu(): GpuExpression =
GpuInSet(childExprs.head.convertToGpu(), in.hset.map(Literal(_)).toSeq)
GpuInSet(childExprs.head.convertToGpu(), in.hset.map(LiteralHelper(_)).toSeq)
}),
expr[LessThan](
"< operator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ import javax.xml.bind.DatatypeConverter
import ai.rapids.cudf.{DType, Scalar}
import org.json4s.JsonAST.{JField, JNull, JString}

import org.apache.spark.sql.catalyst.expressions.Literal
import org.apache.spark.sql.catalyst.util.{DateFormatter, DateTimeUtils, TimestampFormatter}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.rapids.execution.TrampolineUtil
import org.apache.spark.sql.types._
import org.apache.spark.sql.vectorized.ColumnarBatch
import org.apache.spark.unsafe.types.UTF8String

object LiteralHelper {
def apply(v: Any): Literal = v match {
case u: UTF8String => Literal(u, StringType)
case allOthers => Literal(allOthers)
}
}

object GpuScalar {
def scalaTypeToDType(v: Any): DType = {
v match {
Expand Down