Skip to content
Closed
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 @@ -126,8 +126,8 @@ class OrcDeserializer(
case IntegerType | _: YearMonthIntervalType => (ordinal, value) =>
updater.setInt(ordinal, value.asInstanceOf[IntWritable].get)

case LongType | _: DayTimeIntervalType | _: TimestampNTZType => (ordinal, value) =>
updater.setLong(ordinal, value.asInstanceOf[LongWritable].get)
case LongType | _: DayTimeIntervalType | _: TimestampNTZType | _: TimeType =>
(ordinal, value) => updater.setLong(ordinal, value.asInstanceOf[LongWritable].get)

case FloatType => (ordinal, value) =>
updater.setFloat(ordinal, value.asInstanceOf[FloatWritable].get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ class OrcFileFormat
override def supportDataType(dataType: DataType): Boolean = dataType match {
case _: VariantType => false

case _: TimeType => false
case _: AtomicType => true

case st: StructType => st.forall { f => supportDataType(f.dataType) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class OrcSerializer(dataSchema: StructType) {
}


case LongType | _: DayTimeIntervalType | _: TimestampNTZType =>
case LongType | _: DayTimeIntervalType | _: TimestampNTZType | _: TimeType =>
if (reuseObj) {
val result = new LongWritable()
(getter, ordinal) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ object OrcUtils extends Logging {
s"array<${getOrcSchemaString(a.elementType)}>"
case m: MapType =>
s"map<${getOrcSchemaString(m.keyType)},${getOrcSchemaString(m.valueType)}>"
case _: DayTimeIntervalType | _: TimestampNTZType => LongType.catalogString
case _: DayTimeIntervalType | _: TimestampNTZType | _: TimeType => LongType.catalogString
case _: YearMonthIntervalType => IntegerType.catalogString
case _ => dt.catalogString
}
Expand All @@ -302,6 +302,10 @@ object OrcUtils extends Logging {
val typeDesc = new TypeDescription(TypeDescription.Category.LONG)
typeDesc.setAttribute(CATALYST_TYPE_ATTRIBUTE_NAME, n.typeName)
Some(typeDesc)
case tm: TimeType =>
val typeDesc = new TypeDescription(TypeDescription.Category.LONG)
typeDesc.setAttribute(CATALYST_TYPE_ATTRIBUTE_NAME, tm.typeName)
Some(typeDesc)
case t: TimestampType =>
val typeDesc = new TypeDescription(TypeDescription.Category.TIMESTAMP)
typeDesc.setAttribute(CATALYST_TYPE_ATTRIBUTE_NAME, t.typeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ class FileBasedDataSourceSuite extends QueryTest
}

test("SPARK-51590: unsupported the TIME data types in data sources") {
val datasources = Seq("orc", "text")
val datasources = Seq("text")
Seq(true, false).foreach { useV1 =>
val useV1List = if (useV1) {
datasources.mkString(",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,54 @@ abstract class OrcQuerySuite extends OrcQueryTest with SharedSparkSession {
}
}
}

test("TIME type support for ORC format") {
withTempPath { dir =>
val path = dir.getCanonicalPath
val df = spark.sql("""
SELECT
id,
TIME'09:30:00' as morning,
TIME'14:45:30.123456' as afternoon,
TIME'23:59:59.999999' as end_of_day,
TIME'00:00:00' as midnight,
CASE WHEN id % 2 = 0 THEN TIME'12:30:00' ELSE NULL END as nullable_time
FROM VALUES (1), (2), (3) AS t(id)
""")

df.write.mode("overwrite").orc(path)
val result = spark.read.orc(path)

Seq("morning", "afternoon", "end_of_day", "midnight", "nullable_time").foreach { col =>
assert(result.schema(col).dataType == TimeType(6))
}
checkAnswer(result, df)
}
}

test("TIME type with different precisions in ORC") {
withTempPath { dir =>
val path = dir.getCanonicalPath
val df = spark.sql("""
SELECT
CAST(TIME'12:34:56' AS TIME(0)) as time_p0,
CAST(TIME'12:34:56.1' AS TIME(1)) as time_p1,
CAST(TIME'12:34:56.12' AS TIME(2)) as time_p2,
CAST(TIME'12:34:56.123' AS TIME(3)) as time_p3,
CAST(TIME'12:34:56.1234' AS TIME(4)) as time_p4,
CAST(TIME'12:34:56.12345' AS TIME(5)) as time_p5,
CAST(TIME'12:34:56.123456' AS TIME(6)) as time_p6
""")

df.write.mode("overwrite").orc(path)
val result = spark.read.orc(path)

(0 to 6).foreach { p =>
assert(result.schema(s"time_p$p").dataType == TimeType(p))
}
checkAnswer(result, df)
}
}
}

class OrcV1QuerySuite extends OrcQuerySuite {
Expand Down