You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/06/09 10:30:44 UTC

[GitHub] [spark] MaxGekk commented on a change in pull request #32825: [WIP][SPARK-35680][SQL] Support units by the year-month interval type

MaxGekk commented on a change in pull request #32825:
URL: https://github.com/apache/spark/pull/32825#discussion_r648175177



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/types/YearMonthIntervalType.scala
##########
@@ -55,16 +65,28 @@ class YearMonthIntervalType private() extends AtomicType {
 
   private[spark] override def asNullable: YearMonthIntervalType = this
 
-  override def typeName: String = "interval year to month"
+  override val typeName: String = (start, end) match {
+    case (YEAR, MONTH) => "interval year to month"
+    case (YEAR, YEAR) => "interval year"
+    case (MONTH, MONTH) => "interval month"
+    case _ => throw new AnalysisException(
+      s"""Invalid interval units: ($start, $end). Supported units:
+         | (0, 0) - interval year
+         | (0, 1) - interval year to month
+         | (1, 1) - interval month
+         |""".stripMargin)
+  }
 }
 
 /**
- * The companion case object and its class is separated so the companion object also subclasses
- * the YearMonthIntervalType class. Otherwise, the companion object would be of type
- * "YearMonthIntervalType$" in byte code. Defined with a private constructor so the companion object
- * is the only possible instantiation.
+ * Extra factory methods and pattern matchers for the year-month interval type.
  *
  * @since 3.2.0
  */
 @Unstable
-case object YearMonthIntervalType extends YearMonthIntervalType
+object YearMonthIntervalType {

Review comment:
       I didn't understand this. Could you explain me, please. For now, the code works:
   ```scala
     test("aaa") {
       def f(y: YearMonthIntervalType): Int = {
         y.defaultSize
       }
       f(YearMonthIntervalType(0, 1))
     }
   ```
   @cloud-fan or mean a different use case?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org