Skip to content
Closed
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 @@ -32,6 +32,7 @@ import org.apache.spark.sql.execution._
import org.apache.spark.sql.functions._
import org.apache.spark.sql.hive.test.TestHiveSingleton
import org.apache.spark.sql.types._
import org.apache.spark.sql.types.DayTimeIntervalType._
import org.apache.spark.sql.types.YearMonthIntervalType._
import org.apache.spark.unsafe.types.CalendarInterval

Expand Down Expand Up @@ -522,36 +523,57 @@ class HiveScriptTransformationSuite extends BaseScriptTransformationSuite with T

}

test("SPARK-34879: HiveInspectors supports DayTimeIntervalType") {
test("SPARK-34879, SPARK-35733: HiveInspectors supports all type of DayTimeIntervalType") {
assume(TestUtils.testCommandAvailable("/bin/bash"))
withTempView("v") {
val df = Seq(
(Duration.ofDays(1),
val schema = StructType(Seq(
StructField("a", DayTimeIntervalType(DAY)),
StructField("b", DayTimeIntervalType(DAY, HOUR)),
StructField("c", DayTimeIntervalType(DAY, MINUTE)),
StructField("d", DayTimeIntervalType(DAY, SECOND)),
StructField("e", DayTimeIntervalType(HOUR)),
StructField("f", DayTimeIntervalType(HOUR, MINUTE)),
StructField("g", DayTimeIntervalType(HOUR, SECOND)),
StructField("h", DayTimeIntervalType(MINUTE)),
StructField("i", DayTimeIntervalType(MINUTE, SECOND)),
StructField("j", DayTimeIntervalType(SECOND))
))
val df = spark.createDataFrame(sparkContext.parallelize(Seq(
Row(Duration.ofDays(1),
Duration.ofHours(11),
Duration.ofMinutes(1),
Duration.ofSeconds(100).plusNanos(123456),
Duration.of(Long.MaxValue, ChronoUnit.MICROS)),
(Duration.ofDays(1),
Duration.ofSeconds(100).plusNanos(1123456789),
Duration.ofSeconds(Long.MaxValue / DateTimeConstants.MICROS_PER_SECOND))
).toDF("a", "b", "c")
df.createTempView("v")
Duration.of(Long.MaxValue, ChronoUnit.MICROS),
Duration.ofDays(1),
Duration.ofHours(11),
Duration.ofMinutes(1),
Duration.ofSeconds(100).plusNanos(123456),
Duration.ofSeconds(Long.MaxValue / DateTimeConstants.MICROS_PER_SECOND)
))), schema)

// Hive serde supports DayTimeIntervalType as input and output data type
checkAnswer(
df,
(child: SparkPlan) => createScriptTransformationExec(
script = "cat",
output = Seq(
// TODO(SPARK-35733): Check all day-time interval types in HiveInspectors tests
AttributeReference("a", DayTimeIntervalType())(),
AttributeReference("b", DayTimeIntervalType())(),
AttributeReference("c", DayTimeIntervalType())()),
AttributeReference("a", DayTimeIntervalType(DAY))(),
AttributeReference("b", DayTimeIntervalType(DAY, HOUR))(),
AttributeReference("c", DayTimeIntervalType(DAY, MINUTE))(),
AttributeReference("d", DayTimeIntervalType(DAY, SECOND))(),
AttributeReference("e", DayTimeIntervalType(HOUR))(),
AttributeReference("f", DayTimeIntervalType(HOUR, MINUTE))(),
AttributeReference("g", DayTimeIntervalType(HOUR, SECOND))(),
AttributeReference("h", DayTimeIntervalType(MINUTE))(),
AttributeReference("i", DayTimeIntervalType(MINUTE, SECOND))(),
AttributeReference("j", DayTimeIntervalType(SECOND))()),
child = child,
ioschema = hiveIOSchema),
df.select($"a", $"b", $"c").collect())
df.select($"a", $"b", $"c", $"d", $"e", $"f", $"g", $"h", $"i", $"j").collect())
}
}

test("SPARK-35722: HiveInspectors supports all type of YearMonthIntervalType") {
test("SPARK-34879, SPARK-35722: HiveInspectors supports all type of YearMonthIntervalType") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxGekk Also update here

assume(TestUtils.testCommandAvailable("/bin/bash"))
withTempView("v") {
val schema = StructType(Seq(
Expand Down Expand Up @@ -589,7 +611,6 @@ class HiveScriptTransformationSuite extends BaseScriptTransformationSuite with T
df,
(child: SparkPlan) => createScriptTransformationExec(
script = "cat",
// TODO(SPARK-35733): Check all day-time interval types in HiveInspectors tests
output = Seq(AttributeReference("a", DayTimeIntervalType())()),
child = child,
ioschema = hiveIOSchema),
Expand Down