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 DayTimeIntervalType/YearMonthIntervalType support #3460

Merged
merged 6 commits into from
Sep 15, 2021
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 @@ -16,9 +16,11 @@

package com.nvidia.spark.rapids.shims.spark320;

import com.nvidia.spark.rapids.{SparkShims, SparkShimVersion}
import com.nvidia.spark.rapids.{SparkShims, SparkShimVersion, TypeSig}
import org.scalatest.FunSuite

import org.apache.spark.sql.types.{DayTimeIntervalType, YearMonthIntervalType}

class Spark320ShimsSuite extends FunSuite {
val sparkShims: SparkShims = new SparkShimServiceProvider().buildShim
test("spark shims version") {
Expand All @@ -29,4 +31,11 @@ class Spark320ShimsSuite extends FunSuite {
assert(sparkShims.getRapidsShuffleManagerClass ===
classOf[com.nvidia.spark.rapids.spark320.RapidsShuffleManager].getCanonicalName)
}
}

test("TypeSig320") {
val check = TypeSig.DAYTIME + TypeSig.YEARMONTH
assert(check.isSupportedByPlugin(DayTimeIntervalType(), false) == true)
assert(check.isSupportedByPlugin(YearMonthIntervalType(), false) == true)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.nvidia.spark.rapids.shims.v2

import com.nvidia.spark.rapids.{TypeEnum, TypeSig}

import org.apache.spark.sql.types.DataType

/** TypeSig Support for [3.0.1, 3.2.0) */
object TypeSigUtil extends com.nvidia.spark.rapids.TypeSigUtil {

/**
* Check if this type of Spark-specific is supported by the plugin or not.
*
* @param check the Supported Types
* @param dataType the data type to be checked
* @param allowDecimal whether decimal support is enabled or not
* @return true if it is allowed else false.
*/
override def isSupported(
check: TypeEnum.ValueSet,
dataType: DataType,
allowDecimal: Boolean): Boolean = false

/**
* Get all supported types for the spark-specific
*
* @return the all supported typ
*/
override def getAllSupportedTypes(): TypeEnum.ValueSet =
TypeEnum.values - TypeEnum.DAYTIME - TypeEnum.YEARMONTH

/**
* Return the reason why this type is not supported.\
*
* @param check the Supported Types
* @param dataType the data type to be checked
* @param allowDecimal whether decimal support is enabled or not
* @param notSupportedReason the reason for not supporting
* @return the reason
*/
override def reasonNotSupported(
check: TypeEnum.ValueSet,
dataType: DataType,
allowDecimal: Boolean, notSupportedReason: Seq[String]): Seq[String] = notSupportedReason

/**
* Map DataType to TypeEnum
*
* @param dataType the data type to be mapped
* @return the TypeEnum
*/
override def mapDataTypeToTypeEnum(dataType: DataType): TypeEnum.Value = TypeEnum.UDT

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.nvidia.spark.rapids.shims.v2

import com.nvidia.spark.rapids.{TypeEnum, TypeSig}

import org.apache.spark.sql.types.{DataType, DayTimeIntervalType, YearMonthIntervalType}

/**
* Add DayTimeIntervalType and YearMonthIntervalType support
*/
object TypeSigUtil extends com.nvidia.spark.rapids.TypeSigUtil {

override def isSupported(
check: TypeEnum.ValueSet,
dataType: DataType,
allowDecimal: Boolean): Boolean = {
dataType match {
case _: DayTimeIntervalType => check.contains(TypeEnum.DAYTIME)
case _: YearMonthIntervalType => check.contains(TypeEnum.YEARMONTH)
case _ => false
}
}

override def getAllSupportedTypes(): TypeEnum.ValueSet = TypeEnum.values

override def reasonNotSupported(
check: TypeEnum.ValueSet,
dataType: DataType,
allowDecimal: Boolean,
notSupportedReason: Seq[String]): Seq[String] = {
dataType match {
case _: DayTimeIntervalType =>
if (check.contains(TypeEnum.DAYTIME)) Seq.empty else notSupportedReason
case _: YearMonthIntervalType =>
if (check.contains(TypeEnum.YEARMONTH)) Seq.empty else notSupportedReason
case _ => notSupportedReason
}
}

override def mapDataTypeToTypeEnum(dataType: DataType): TypeEnum.Value = {
dataType match {
case _: DayTimeIntervalType => TypeEnum.DAYTIME
case _: YearMonthIntervalType => TypeEnum.YEARMONTH
case _ => TypeEnum.UDT // default to UDT
}
}

}
Loading