MaxGekk commented on a change in pull request #32849:
URL: https://github.com/apache/spark/pull/32849#discussion_r649414545
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/types/DayTimeIntervalType.scala
##########
@@ -57,16 +62,61 @@ class DayTimeIntervalType private() extends AtomicType {
private[spark] override def asNullable: DayTimeIntervalType = this
- override def typeName: String = "interval day to second"
+ override val typeName: String = {
+ val startFieldName = fieldToString(startField)
+ val endFieldName = fieldToString(endField)
+ if (startFieldName == endFieldName) {
+ s"interval $startFieldName"
+ } else if (startField < endField) {
+ s"interval $startFieldName to $endFieldName"
+ } else {
+ throw QueryCompilationErrors.invalidDayTimeIntervalType(startFieldName,
endFieldName)
+ }
+ }
}
/**
- * The companion case object and its class is separated so the companion
object also subclasses
- * the DayTimeIntervalType class. Otherwise, the companion object would be of
type
- * "DayTimeIntervalType$" in byte code. Defined with a private constructor so
the companion object
- * is the only possible instantiation.
+ * Extra factory methods and pattern matchers for DayTimeIntervalType.
*
* @since 3.2.0
*/
@Unstable
-case object DayTimeIntervalType extends DayTimeIntervalType
+case object DayTimeIntervalType extends AbstractDataType {
+ val DAY: Byte = 0
+ val HOUR: Byte = 1
+ val MINUTE: Byte = 2
+ val SECOND: Byte = 3
+ val dayTimeFields = Seq(DAY, HOUR, MINUTE, SECOND)
+
+ def fieldToString(field: Byte): String = field match {
+ case DAY => "day"
+ case HOUR => "hour"
+ case MINUTE => "minute"
+ case SECOND => "second"
+ case invalid => throw QueryCompilationErrors.invalidDayTimeField(invalid)
+ }
+
+ val DEFAULT = DayTimeIntervalType(DAY, SECOND)
+
+ def apply(): DayTimeIntervalType = DEFAULT
+
+ override private[sql] def defaultConcreteType: DataType = DEFAULT
+
+ override private[sql] def acceptsType(other: DataType): Boolean = {
+ other.isInstanceOf[DayTimeIntervalType]
+ }
+
+ override private[sql] def simpleString: String =
defaultConcreteType.simpleString
+
+ def dayTimeIntervalTypes(): Seq[DayTimeIntervalType] = Seq(
Review comment:
moved
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]