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

Support multiple datatypes in TypeSig.withPsNote() #5277

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1764,8 +1764,7 @@ object GpuOverrides extends Logging {
Seq(ParamCheck(
"pivotColumn",
(TypeSig.commonCudfTypes + TypeSig.NULL + TypeSig.DECIMAL_128)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.all),
ParamCheck("valueColumn",
TypeSig.commonCudfTypes + TypeSig.NULL + TypeSig.DECIMAL_128,
Expand Down Expand Up @@ -1806,17 +1805,15 @@ object GpuOverrides extends Logging {
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL + TypeSig.STRUCT)
.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts
++
ExprChecks.windowOnly(
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL),
TypeSig.orderable,
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts),
(max, conf, p, r) => new AggExprMeta[Max](max, conf, p, r) {
override def tagAggForGpu(): Unit = {
Expand All @@ -1835,17 +1832,15 @@ object GpuOverrides extends Logging {
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL + TypeSig.STRUCT)
.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts
++
ExprChecks.windowOnly(
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL),
TypeSig.orderable,
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts),
(a, conf, p, r) => new AggExprMeta[Min](a, conf, p, r) {
override def tagAggForGpu(): Unit = {
Expand Down Expand Up @@ -2159,8 +2154,7 @@ object GpuOverrides extends Logging {
TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL,
TypeSig.orderable,
TypeSig.ARRAY.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, GpuOverrides.nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, GpuOverrides.nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), GpuOverrides.nanAggPsNote),
TypeSig.ARRAY.nested(TypeSig.orderable)),
(in, conf, p, r) => new UnaryExprMeta[ArrayMin](in, conf, p, r) {
override def tagExprForGpu(): Unit = {
Expand All @@ -2173,8 +2167,7 @@ object GpuOverrides extends Logging {
TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL,
TypeSig.orderable,
TypeSig.ARRAY.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, GpuOverrides.nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, GpuOverrides.nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), GpuOverrides.nanAggPsNote),
TypeSig.ARRAY.nested(TypeSig.orderable)),
(in, conf, p, r) => new UnaryExprMeta[ArrayMax](in, conf, p, r) {
override def tagExprForGpu(): Unit = {
Expand All @@ -2195,10 +2188,10 @@ object GpuOverrides extends Logging {
("array", TypeSig.ARRAY.nested(TypeSig.commonCudfTypes + TypeSig.NULL),
TypeSig.ARRAY.nested(TypeSig.all)),
("key", TypeSig.commonCudfTypes
.withPsNote(TypeEnum.DOUBLE, "NaN literals are not supported. Columnar input" +
s" must not contain NaNs and ${RapidsConf.HAS_NANS} must be false.")
.withPsNote(TypeEnum.FLOAT, "NaN literals are not supported. Columnar input" +
s" must not contain NaNs and ${RapidsConf.HAS_NANS} must be false."),
.withPsNote(
Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT),
"NaN literals are not supported. Columnar input" +
s" must not contain NaNs and ${RapidsConf.HAS_NANS} must be false."),
TypeSig.all)),
(in, conf, p, r) => new BinaryExprMeta[ArrayContains](in, conf, p, r) {
override def tagExprForGpu(): Unit = {
Expand Down Expand Up @@ -2834,9 +2827,9 @@ object GpuOverrides extends Logging {
TypeSig.ARRAY + TypeSig.STRUCT + TypeSig.MAP).nested()
.withPsNote(TypeEnum.STRUCT, "Round-robin partitioning is not supported for nested " +
s"structs if ${SQLConf.SORT_BEFORE_REPARTITION.key} is true")
.withPsNote(TypeEnum.ARRAY, "Round-robin partitioning is not supported if " +
s"${SQLConf.SORT_BEFORE_REPARTITION.key} is true")
.withPsNote(TypeEnum.MAP, "Round-robin partitioning is not supported if " +
.withPsNote(
Seq(TypeEnum.ARRAY, TypeEnum.MAP),
"Round-robin partitioning is not supported if " +
s"${SQLConf.SORT_BEFORE_REPARTITION.key} is true"),
TypeSig.all),
(shuffle, conf, p, r) => new GpuShuffleMeta(shuffle, conf, p, r)),
Expand Down Expand Up @@ -2886,8 +2879,8 @@ object GpuOverrides extends Logging {
(TypeSig.commonCudfTypes + TypeSig.NULL + TypeSig.DECIMAL_128 +
TypeSig.MAP + TypeSig.ARRAY + TypeSig.STRUCT)
.nested()
.withPsNote(TypeEnum.ARRAY, "not allowed for grouping expressions")
.withPsNote(TypeEnum.MAP, "not allowed for grouping expressions")
.withPsNote(Seq(TypeEnum.ARRAY, TypeEnum.MAP),
"not allowed for grouping expressions")
.withPsNote(TypeEnum.STRUCT,
"not allowed for grouping expressions if containing Array or Map as child"),
TypeSig.all),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ final class TypeSig private(
new TypeSig(initialTypes + dataType, maxAllowedDecimalPrecision, childTypes, litOnlyTypes,
notes.+((dataType, note)))

/**
* Add a note about given types that marks them as partially supported.
* @param dataTypes the types this note is for.
* @param note the note itself
* @return the updated TypeSignature.
*/
def withPsNote(dataTypes: Seq[TypeEnum.Value], note: String): TypeSig =
new TypeSig(
dataTypes.foldLeft(initialTypes)(_+_), maxAllowedDecimalPrecision, childTypes,
litOnlyTypes, dataTypes.foldLeft(notes)((notes, dataType) => notes.+((dataType, note))))


private def isSupportedType(dataType: TypeEnum.Value): Boolean =
initialTypes.contains(dataType)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2235,8 +2235,7 @@ object GpuOverrides extends Logging {
Seq(ParamCheck(
"pivotColumn",
(TypeSig.commonCudfTypes + TypeSig.NULL + TypeSig.DECIMAL_128)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.all),
ParamCheck("valueColumn",
TypeSig.commonCudfTypes + TypeSig.NULL + TypeSig.DECIMAL_128,
Expand Down Expand Up @@ -2284,17 +2283,15 @@ object GpuOverrides extends Logging {
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL + TypeSig.STRUCT)
.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts
++
ExprChecks.windowOnly(
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL),
TypeSig.orderable,
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts),
(max, conf, p, r) => new AggExprMeta[Max](max, conf, p, r) {
override def tagAggForGpu(): Unit = {
Expand All @@ -2319,17 +2316,15 @@ object GpuOverrides extends Logging {
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL + TypeSig.STRUCT)
.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts
++
ExprChecks.windowOnly(
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL),
TypeSig.orderable,
Seq(ParamCheck("input",
(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.orderable))).asInstanceOf[ExprChecksImpl].contexts),
(a, conf, p, r) => new AggExprMeta[Min](a, conf, p, r) {
override def tagAggForGpu(): Unit = {
Expand Down Expand Up @@ -2633,26 +2628,11 @@ object GpuOverrides extends Logging {
("index/key", (TypeSig.commonCudfTypes + TypeSig.DECIMAL_128)
.withPsNote(TypeEnum.INT, "Supported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.BOOLEAN, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.BYTE, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.SHORT, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.LONG, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.FLOAT, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.DOUBLE, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.DATE, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.TIMESTAMP, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.STRING, "Unsupported as array index. " +
"Only Literals supported as map keys.")
.withPsNote(TypeEnum.DECIMAL, "Unsupported as array index. " +
"Only Literals supported as map keys."),
.withPsNote(
Seq(TypeEnum.BOOLEAN, TypeEnum.BYTE, TypeEnum.SHORT, TypeEnum.LONG,
TypeEnum.FLOAT, TypeEnum.DOUBLE, TypeEnum.DATE, TypeEnum.TIMESTAMP,
TypeEnum.STRING, TypeEnum.DECIMAL),
"Unsupported as array index. Only Literals supported as map keys."),
TypeSig.all)),
(in, conf, p, r) => new BinaryExprMeta[ElementAt](in, conf, p, r) {
override def tagExprForGpu(): Unit = {
Expand Down Expand Up @@ -2740,8 +2720,7 @@ object GpuOverrides extends Logging {
TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL,
TypeSig.orderable,
TypeSig.ARRAY.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.ARRAY.nested(TypeSig.orderable)),
(in, conf, p, r) => new UnaryExprMeta[ArrayMin](in, conf, p, r) {
override def tagExprForGpu(): Unit = {
Expand All @@ -2757,8 +2736,7 @@ object GpuOverrides extends Logging {
TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL,
TypeSig.orderable,
TypeSig.ARRAY.nested(TypeSig.commonCudfTypes + TypeSig.DECIMAL_128 + TypeSig.NULL)
.withPsNote(TypeEnum.DOUBLE, nanAggPsNote)
.withPsNote(TypeEnum.FLOAT, nanAggPsNote),
.withPsNote(Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT), nanAggPsNote),
TypeSig.ARRAY.nested(TypeSig.orderable)),
(in, conf, p, r) => new UnaryExprMeta[ArrayMax](in, conf, p, r) {
override def tagExprForGpu(): Unit = {
Expand All @@ -2783,10 +2761,10 @@ object GpuOverrides extends Logging {
("array", TypeSig.ARRAY.nested(TypeSig.commonCudfTypes + TypeSig.NULL),
TypeSig.ARRAY.nested(TypeSig.all)),
("key", TypeSig.commonCudfTypes
.withPsNote(TypeEnum.DOUBLE, "NaN literals are not supported. Columnar input" +
s" must not contain NaNs and ${RapidsConf.HAS_NANS} must be false.")
.withPsNote(TypeEnum.FLOAT, "NaN literals are not supported. Columnar input" +
s" must not contain NaNs and ${RapidsConf.HAS_NANS} must be false."),
.withPsNote(
Seq(TypeEnum.DOUBLE, TypeEnum.FLOAT),
"NaN literals are not supported. Columnar input" +
s" must not contain NaNs and ${RapidsConf.HAS_NANS} must be false."),
TypeSig.all)),
(in, conf, p, r) => new BinaryExprMeta[ArrayContains](in, conf, p, r) {
override def tagExprForGpu(): Unit = {
Expand Down Expand Up @@ -3765,9 +3743,9 @@ object GpuOverrides extends Logging {
GpuTypeShims.additionalArithmeticSupportedTypes).nested()
.withPsNote(TypeEnum.STRUCT, "Round-robin partitioning is not supported for nested " +
s"structs if ${SQLConf.SORT_BEFORE_REPARTITION.key} is true")
.withPsNote(TypeEnum.ARRAY, "Round-robin partitioning is not supported if " +
s"${SQLConf.SORT_BEFORE_REPARTITION.key} is true")
.withPsNote(TypeEnum.MAP, "Round-robin partitioning is not supported if " +
.withPsNote(
Seq(TypeEnum.ARRAY, TypeEnum.MAP),
"Round-robin partitioning is not supported if " +
s"${SQLConf.SORT_BEFORE_REPARTITION.key} is true"),
TypeSig.all),
(shuffle, conf, p, r) => new GpuShuffleMeta(shuffle, conf, p, r)),
Expand Down Expand Up @@ -3830,8 +3808,8 @@ object GpuOverrides extends Logging {
(TypeSig.commonCudfTypes + TypeSig.NULL + TypeSig.DECIMAL_128 +
TypeSig.MAP + TypeSig.ARRAY + TypeSig.STRUCT)
.nested()
.withPsNote(TypeEnum.ARRAY, "not allowed for grouping expressions")
.withPsNote(TypeEnum.MAP, "not allowed for grouping expressions")
.withPsNote(Seq(TypeEnum.ARRAY, TypeEnum.MAP),
"not allowed for grouping expressions")
.withPsNote(TypeEnum.STRUCT,
"not allowed for grouping expressions if containing Array or Map as child"),
TypeSig.all),
Expand All @@ -3846,8 +3824,8 @@ object GpuOverrides extends Logging {
.nested()
.withPsNote(TypeEnum.BINARY, "only allowed when aggregate buffers can be " +
"converted between CPU and GPU")
.withPsNote(TypeEnum.ARRAY, "not allowed for grouping expressions")
.withPsNote(TypeEnum.MAP, "not allowed for grouping expressions")
.withPsNote(Seq(TypeEnum.ARRAY, TypeEnum.MAP),
"not allowed for grouping expressions")
.withPsNote(TypeEnum.STRUCT,
"not allowed for grouping expressions if containing Array or Map as child"),
TypeSig.all),
Expand All @@ -3864,8 +3842,8 @@ object GpuOverrides extends Logging {
.nested()
.withPsNote(TypeEnum.BINARY, "only allowed when aggregate buffers can be " +
"converted between CPU and GPU")
.withPsNote(TypeEnum.ARRAY, "not allowed for grouping expressions")
.withPsNote(TypeEnum.MAP, "not allowed for grouping expressions")
.withPsNote(Seq(TypeEnum.ARRAY, TypeEnum.MAP),
"not allowed for grouping expressions")
.withPsNote(TypeEnum.STRUCT,
"not allowed for grouping expressions if containing Array or Map as child"),
TypeSig.all),
Expand Down
11 changes: 11 additions & 0 deletions sql-plugin/src/main/scala/com/nvidia/spark/rapids/TypeChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ final class TypeSig private(
new TypeSig(initialTypes + dataType, maxAllowedDecimalPrecision, childTypes, litOnlyTypes,
notes.+((dataType, note)))

/**
* Add a note about given types that marks them as partially supported.
* @param dataTypes the types this note is for.
* @param note the note itself
* @return the updated TypeSignature.
*/
def withPsNote(dataTypes: Seq[TypeEnum.Value], note: String): TypeSig =
new TypeSig(
dataTypes.foldLeft(initialTypes)(_+_), maxAllowedDecimalPrecision, childTypes,
litOnlyTypes, dataTypes.foldLeft(notes)((notes, dataType) => notes.+((dataType, note))))

private def isSupportedType(dataType: TypeEnum.Value): Boolean =
initialTypes.contains(dataType)

Expand Down