From 17857f9b8bdf95eb64735eb986e86bf8fd8bc1a9 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Sun, 19 Jan 2020 15:27:51 +0800 Subject: [PATCH] [SPARK-30551][SQL] Disable comparison for interval type ### What changes were proposed in this pull request? As we are not going to follow ANSI to implement year-month and day-time interval types, it is weird to compare the year-month part to the day-time part for our current implementation of interval type now. Additionally, the current ordering logic comes from PostgreSQL where the implementation of the interval is messy. And we are not aiming PostgreSQL compliance at all. THIS PR will revert https://github.com/apache/spark/pull/26681 and https://github.com/apache/spark/pull/26337 ### Why are the changes needed? make interval type more future-proofing ### Does this PR introduce any user-facing change? there are new in 3.0, so no ### How was this patch tested? existing uts shall work Closes #27262 from yaooqinn/SPARK-30551. Authored-by: Kent Yao Signed-off-by: Wenchen Fan --- .../spark/unsafe/types/CalendarInterval.java | 37 +- .../expressions/codegen/CodeGenerator.scala | 2 - .../sql/catalyst/expressions/ordering.scala | 1 - .../spark/sql/catalyst/util/TypeUtils.scala | 1 - .../spark/sql/types/AbstractDataType.scala | 4 +- .../sql/types/CalendarIntervalType.scala | 3 - .../catalyst/util/IntervalUtilsSuite.scala | 57 +- .../scala/org/apache/spark/sql/Dataset.scala | 6 +- .../spark/sql/RelationalGroupedDataset.scala | 39 +- .../sql/execution/columnar/ColumnStats.scala | 8 +- .../resources/sql-tests/inputs/interval.sql | 42 - .../sql-tests/results/ansi/interval.sql.out | 760 +++++++----------- .../sql-tests/results/interval.sql.out | 760 +++++++----------- .../spark/sql/DataFrameAggregateSuite.scala | 20 - .../execution/columnar/ColumnStatsSuite.scala | 6 +- .../execution/columnar/ColumnTypeSuite.scala | 2 +- 16 files changed, 636 insertions(+), 1112 deletions(-) diff --git a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java index f9f78d575e..bbfccc3ff2 100644 --- a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java +++ b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java @@ -29,7 +29,7 @@ import static org.apache.spark.sql.catalyst.util.DateTimeConstants.*; /** * The internal representation of interval type. */ -public final class CalendarInterval implements Serializable, Comparable { +public final class CalendarInterval implements Serializable { public final int months; public final int days; public final long microseconds; @@ -59,29 +59,6 @@ public final class CalendarInterval implements Serializable, Comparable 0) { - return 1; - } else { - return -1; - } - } else if (daysDiff > 0){ - return 1; - } else { - return -1; - } - } - @Override public String toString() { if (months == 0 && days == 0 && microseconds == 0) { @@ -133,16 +110,4 @@ public final class CalendarInterval implements Serializable, Comparable s"$c1 == $c2" case dt: DataType if dt.isInstanceOf[AtomicType] => s"$c1.equals($c2)" - case CalendarIntervalType => s"$c1.equals($c2)" case array: ArrayType => genComp(array, c1, c2) + " == 0" case struct: StructType => genComp(struct, c1, c2) + " == 0" case udt: UserDefinedType[_] => genEqual(udt.sqlType, c1, c2) @@ -630,7 +629,6 @@ class CodegenContext extends Logging { // use c1 - c2 may overflow case dt: DataType if isPrimitiveType(dt) => s"($c1 > $c2 ? 1 : $c1 < $c2 ? -1 : 0)" case BinaryType => s"org.apache.spark.sql.catalyst.util.TypeUtils.compareBinary($c1, $c2)" - case CalendarIntervalType => s"$c1.compareTo($c2)" case NullType => "0" case array: ArrayType => val elementType = array.elementType diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ordering.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ordering.scala index 8867a03a46..fa2978cddc 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ordering.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ordering.scala @@ -101,7 +101,6 @@ object RowOrdering extends CodeGeneratorWithInterpretedFallback[Seq[SortOrder], def isOrderable(dataType: DataType): Boolean = dataType match { case NullType => true case dt: AtomicType => true - case CalendarIntervalType => true case struct: StructType => struct.fields.forall(f => isOrderable(f.dataType)) case array: ArrayType => isOrderable(array.elementType) case udt: UserDefinedType[_] => isOrderable(udt.sqlType) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala index da084c9edb..9680ea3cd2 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala @@ -71,7 +71,6 @@ object TypeUtils { def getInterpretedOrdering(t: DataType): Ordering[Any] = { t match { case i: AtomicType => i.ordering.asInstanceOf[Ordering[Any]] - case c: CalendarIntervalType => c.ordering.asInstanceOf[Ordering[Any]] case a: ArrayType => a.interpretedOrdering.asInstanceOf[Ordering[Any]] case s: StructType => s.interpretedOrdering.asInstanceOf[Ordering[Any]] case udt: UserDefinedType[_] => getInterpretedOrdering(udt.sqlType) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/AbstractDataType.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/AbstractDataType.scala index 25303475a7..21ac32adca 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/AbstractDataType.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/AbstractDataType.scala @@ -79,8 +79,8 @@ private[sql] class TypeCollection(private val types: Seq[AbstractDataType]) private[sql] object TypeCollection { /** - * Types that include numeric types and interval type, which support numeric type calculations, - * i.e. unary_minus, unary_positive, sum, avg, min, max, add and subtract operations. + * Types that include numeric types and interval type. They are only used in unary_minus, + * unary_positive, add and subtract operations. */ val NumericAndInterval = TypeCollection(NumericType, CalendarIntervalType) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/CalendarIntervalType.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/CalendarIntervalType.scala index 641fb354dd..5889f1ce4e 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/CalendarIntervalType.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/CalendarIntervalType.scala @@ -18,7 +18,6 @@ package org.apache.spark.sql.types import org.apache.spark.annotation.Stable -import org.apache.spark.unsafe.types.CalendarInterval /** * The data type representing calendar intervals. The calendar interval is stored internally in @@ -40,8 +39,6 @@ class CalendarIntervalType private() extends DataType { override def simpleString: String = "interval" - val ordering: Ordering[CalendarInterval] = Ordering[CalendarInterval] - private[spark] override def asNullable: CalendarIntervalType = this } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/IntervalUtilsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/IntervalUtilsSuite.scala index 47b7d402a2..a0b4387331 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/IntervalUtilsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/IntervalUtilsSuite.scala @@ -426,38 +426,33 @@ class IntervalUtilsSuite extends SparkFunSuite with SQLHelper { } test("interval overflow check") { - intercept[ArithmeticException](negateExact(new CalendarInterval(Int.MinValue, 0, 0))) - assert(negate(new CalendarInterval(Int.MinValue, 0, 0)) === - new CalendarInterval(Int.MinValue, 0, 0)) - intercept[ArithmeticException](negateExact(CalendarInterval.MIN_VALUE)) - assert(negate(CalendarInterval.MIN_VALUE) === CalendarInterval.MIN_VALUE) - intercept[ArithmeticException](addExact(CalendarInterval.MAX_VALUE, - new CalendarInterval(0, 0, 1))) - intercept[ArithmeticException](addExact(CalendarInterval.MAX_VALUE, - new CalendarInterval(0, 1, 0))) - intercept[ArithmeticException](addExact(CalendarInterval.MAX_VALUE, - new CalendarInterval(1, 0, 0))) - assert(add(CalendarInterval.MAX_VALUE, new CalendarInterval(0, 0, 1)) === - new CalendarInterval(Int.MaxValue, Int.MaxValue, Long.MinValue)) - assert(add(CalendarInterval.MAX_VALUE, new CalendarInterval(0, 1, 0)) === - new CalendarInterval(Int.MaxValue, Int.MinValue, Long.MaxValue)) - assert(add(CalendarInterval.MAX_VALUE, new CalendarInterval(1, 0, 0)) === - new CalendarInterval(Int.MinValue, Int.MaxValue, Long.MaxValue)) + val maxMonth = new CalendarInterval(Int.MaxValue, 0, 0) + val minMonth = new CalendarInterval(Int.MinValue, 0, 0) + val oneMonth = new CalendarInterval(1, 0, 0) + val maxDay = new CalendarInterval(0, Int.MaxValue, 0) + val minDay = new CalendarInterval(0, Int.MinValue, 0) + val oneDay = new CalendarInterval(0, 1, 0) + val maxMicros = new CalendarInterval(0, 0, Long.MaxValue) + val minMicros = new CalendarInterval(0, 0, Long.MinValue) + val oneMicros = new CalendarInterval(0, 0, 1) + intercept[ArithmeticException](negateExact(minMonth)) + assert(negate(minMonth) === minMonth) - intercept[ArithmeticException](subtractExact(CalendarInterval.MAX_VALUE, - new CalendarInterval(0, 0, -1))) - intercept[ArithmeticException](subtractExact(CalendarInterval.MAX_VALUE, - new CalendarInterval(0, -1, 0))) - intercept[ArithmeticException](subtractExact(CalendarInterval.MAX_VALUE, - new CalendarInterval(-1, 0, 0))) - assert(subtract(CalendarInterval.MAX_VALUE, new CalendarInterval(0, 0, -1)) === - new CalendarInterval(Int.MaxValue, Int.MaxValue, Long.MinValue)) - assert(subtract(CalendarInterval.MAX_VALUE, new CalendarInterval(0, -1, 0)) === - new CalendarInterval(Int.MaxValue, Int.MinValue, Long.MaxValue)) - assert(subtract(CalendarInterval.MAX_VALUE, new CalendarInterval(-1, 0, 0)) === - new CalendarInterval(Int.MinValue, Int.MaxValue, Long.MaxValue)) + intercept[ArithmeticException](addExact(maxMonth, oneMonth)) + intercept[ArithmeticException](addExact(maxDay, oneDay)) + intercept[ArithmeticException](addExact(maxMicros, oneMicros)) + assert(add(maxMonth, oneMonth) === minMonth) + assert(add(maxDay, oneDay) === minDay) + assert(add(maxMicros, oneMicros) === minMicros) - intercept[ArithmeticException](multiplyExact(CalendarInterval.MAX_VALUE, 2)) - intercept[ArithmeticException](divideExact(CalendarInterval.MAX_VALUE, 0.5)) + intercept[ArithmeticException](subtractExact(minDay, oneDay)) + intercept[ArithmeticException](subtractExact(minMonth, oneMonth)) + intercept[ArithmeticException](subtractExact(minMicros, oneMicros)) + assert(subtract(minMonth, oneMonth) === maxMonth) + assert(subtract(minDay, oneDay) === maxDay) + assert(subtract(minMicros, oneMicros) === maxMicros) + + intercept[ArithmeticException](multiplyExact(maxMonth, 2)) + intercept[ArithmeticException](divideExact(maxDay, 0.5)) } } diff --git a/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala b/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala index 0eb1a26c2b..a1c33f92d1 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala @@ -268,9 +268,9 @@ class Dataset[T] private[sql]( } } - private[sql] def numericCalculationSupportedColumns: Seq[Expression] = { - queryExecution.analyzed.output.filter { attr => - TypeCollection.NumericAndInterval.acceptsType(attr.dataType) + private[sql] def numericColumns: Seq[Expression] = { + schema.fields.filter(_.dataType.isInstanceOf[NumericType]).map { n => + queryExecution.analyzed.resolveQuoted(n.name, sparkSession.sessionState.analyzer.resolver).get } } diff --git a/sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala b/sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala index 52bd0ecb1f..b1ba7d4538 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala @@ -33,7 +33,7 @@ import org.apache.spark.sql.catalyst.plans.logical._ import org.apache.spark.sql.catalyst.util.toPrettySQL import org.apache.spark.sql.execution.aggregate.TypedAggregateExpression import org.apache.spark.sql.internal.SQLConf -import org.apache.spark.sql.types.{StructType, TypeCollection} +import org.apache.spark.sql.types.{NumericType, StructType} /** * A set of methods for aggregations on a `DataFrame`, created by [[Dataset#groupBy groupBy]], @@ -88,20 +88,20 @@ class RelationalGroupedDataset protected[sql]( case expr: Expression => Alias(expr, toPrettySQL(expr))() } - private[this] def aggregateNumericOrIntervalColumns( - colNames: String*)(f: Expression => AggregateFunction): DataFrame = { + private[this] def aggregateNumericColumns(colNames: String*)(f: Expression => AggregateFunction) + : DataFrame = { val columnExprs = if (colNames.isEmpty) { - // No columns specified. Use all numeric calculation supported columns. - df.numericCalculationSupportedColumns + // No columns specified. Use all numeric columns. + df.numericColumns } else { - // Make sure all specified columns are numeric calculation supported columns. + // Make sure all specified columns are numeric. colNames.map { colName => val namedExpr = df.resolve(colName) - if (!TypeCollection.NumericAndInterval.acceptsType(namedExpr.dataType)) { + if (!namedExpr.dataType.isInstanceOf[NumericType]) { throw new AnalysisException( - s""""$colName" is not a numeric or calendar interval column. """ + - "Aggregation function can only be applied on a numeric or calendar interval column.") + s""""$colName" is not a numeric column. """ + + "Aggregation function can only be applied on a numeric column.") } namedExpr } @@ -269,8 +269,7 @@ class RelationalGroupedDataset protected[sql]( def count(): DataFrame = toDF(Seq(Alias(Count(Literal(1)).toAggregateExpression(), "count")())) /** - * Compute the average value for each numeric or calender interval columns for each group. This - * is an alias for `avg`. + * Compute the average value for each numeric columns for each group. This is an alias for `avg`. * The resulting `DataFrame` will also contain the grouping columns. * When specified columns are given, only compute the average values for them. * @@ -278,11 +277,11 @@ class RelationalGroupedDataset protected[sql]( */ @scala.annotation.varargs def mean(colNames: String*): DataFrame = { - aggregateNumericOrIntervalColumns(colNames : _*)(Average) + aggregateNumericColumns(colNames : _*)(Average) } /** - * Compute the max value for each numeric calender interval columns for each group. + * Compute the max value for each numeric columns for each group. * The resulting `DataFrame` will also contain the grouping columns. * When specified columns are given, only compute the max values for them. * @@ -290,11 +289,11 @@ class RelationalGroupedDataset protected[sql]( */ @scala.annotation.varargs def max(colNames: String*): DataFrame = { - aggregateNumericOrIntervalColumns(colNames : _*)(Max) + aggregateNumericColumns(colNames : _*)(Max) } /** - * Compute the mean value for each numeric calender interval columns for each group. + * Compute the mean value for each numeric columns for each group. * The resulting `DataFrame` will also contain the grouping columns. * When specified columns are given, only compute the mean values for them. * @@ -302,11 +301,11 @@ class RelationalGroupedDataset protected[sql]( */ @scala.annotation.varargs def avg(colNames: String*): DataFrame = { - aggregateNumericOrIntervalColumns(colNames : _*)(Average) + aggregateNumericColumns(colNames : _*)(Average) } /** - * Compute the min value for each numeric calender interval column for each group. + * Compute the min value for each numeric column for each group. * The resulting `DataFrame` will also contain the grouping columns. * When specified columns are given, only compute the min values for them. * @@ -314,11 +313,11 @@ class RelationalGroupedDataset protected[sql]( */ @scala.annotation.varargs def min(colNames: String*): DataFrame = { - aggregateNumericOrIntervalColumns(colNames : _*)(Min) + aggregateNumericColumns(colNames : _*)(Min) } /** - * Compute the sum for each numeric calender interval columns for each group. + * Compute the sum for each numeric columns for each group. * The resulting `DataFrame` will also contain the grouping columns. * When specified columns are given, only compute the sum for them. * @@ -326,7 +325,7 @@ class RelationalGroupedDataset protected[sql]( */ @scala.annotation.varargs def sum(colNames: String*): DataFrame = { - aggregateNumericOrIntervalColumns(colNames : _*)(Sum) + aggregateNumericColumns(colNames : _*)(Sum) } /** diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnStats.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnStats.scala index c0e61b381f..20ecc57c49 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnStats.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnStats.scala @@ -296,14 +296,8 @@ private[columnar] final class BinaryColumnStats extends ColumnStats { } private[columnar] final class IntervalColumnStats extends ColumnStats { - protected var upper: CalendarInterval = CalendarInterval.MIN_VALUE - protected var lower: CalendarInterval = CalendarInterval.MAX_VALUE - override def gatherStats(row: InternalRow, ordinal: Int): Unit = { if (!row.isNullAt(ordinal)) { - val value = row.getInterval(ordinal) - if (value.compareTo(upper) > 0) upper = value - if (value.compareTo(lower) < 0) lower = value sizeInBytes += CALENDAR_INTERVAL.actualSize(row, ordinal) count += 1 } else { @@ -312,7 +306,7 @@ private[columnar] final class IntervalColumnStats extends ColumnStats { } override def collectedStatistics: Array[Any] = - Array[Any](lower, upper, nullCount, count, sizeInBytes) + Array[Any](null, null, nullCount, count, sizeInBytes) } private[columnar] final class DecimalColumnStats(precision: Int, scale: Int) extends ColumnStats { diff --git a/sql/core/src/test/resources/sql-tests/inputs/interval.sql b/sql/core/src/test/resources/sql-tests/inputs/interval.sql index 9d9fb0d030..5de5656cbe 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/interval.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/interval.sql @@ -1,47 +1,5 @@ -- test for intervals --- greater than or equal -select interval '1 day' > interval '23 hour'; -select interval '-1 day' >= interval '-23 hour'; -select interval '-1 day' > null; -select null > interval '-1 day'; - --- less than or equal -select interval '1 minutes' < interval '1 hour'; -select interval '-1 day' <= interval '-23 hour'; - --- equal -select interval '1 year' = interval '360 days'; -select interval '1 year 2 month' = interval '420 days'; -select interval '1 year' = interval '365 days'; -select interval '1 month' = interval '30 days'; -select interval '1 minutes' = interval '1 hour'; -select interval '1 minutes' = null; -select null = interval '-1 day'; - --- null safe equal -select interval '1 minutes' <=> null; -select null <=> interval '1 minutes'; - --- complex interval representation -select INTERVAL '9 years 1 months -1 weeks -4 days -10 hours -46 minutes' > interval '1 minutes'; - --- ordering -select cast(v as interval) i from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) order by i; - --- unlimited days -select interval '1 month 120 days' > interval '2 month'; -select interval '1 month 30 days' = interval '2 month'; - --- unlimited microseconds -select interval '1 month 29 days 40 hours' > interval '2 month'; - --- max -select max(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v); - --- min -select min(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v); - -- multiply and divide an interval by a number select 3 * (timestamp'2019-10-15 10:11:12.001002' - date'2019-10-15'); select interval 4 month 2 weeks 3 microseconds * 1.5; diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out index 2a19c26389..2893b6a01d 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out @@ -1,487 +1,309 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 119 +-- Number of queries: 97 -- !query 0 -select interval '1 day' > interval '23 hour' +select 3 * (timestamp'2019-10-15 10:11:12.001002' - date'2019-10-15') -- !query 0 schema -struct<(INTERVAL '1 days' > INTERVAL '23 hours'):boolean> +struct -- !query 0 output -true +30 hours 33 minutes 36.003006 seconds -- !query 1 -select interval '-1 day' >= interval '-23 hour' +select interval 4 month 2 weeks 3 microseconds * 1.5 -- !query 1 schema -struct<(INTERVAL '-1 days' >= INTERVAL '-23 hours'):boolean> +struct -- !query 1 output -false +6 months 21 days 0.000005 seconds -- !query 2 -select interval '-1 day' > null +select (timestamp'2019-10-15' - timestamp'2019-10-14') / 1.5 -- !query 2 schema -struct<(INTERVAL '-1 days' > CAST(NULL AS INTERVAL)):boolean> +struct -- !query 2 output -NULL +16 hours -- !query 3 -select null > interval '-1 day' +select interval '2 seconds' / 0 -- !query 3 schema -struct<(CAST(NULL AS INTERVAL) > INTERVAL '-1 days'):boolean> +struct<> -- !query 3 output -NULL +java.lang.ArithmeticException +divide by zero -- !query 4 -select interval '1 minutes' < interval '1 hour' +select interval '2 seconds' / null -- !query 4 schema -struct<(INTERVAL '1 minutes' < INTERVAL '1 hours'):boolean> +struct -- !query 4 output -true +NULL -- !query 5 -select interval '-1 day' <= interval '-23 hour' +select interval '2 seconds' * null -- !query 5 schema -struct<(INTERVAL '-1 days' <= INTERVAL '-23 hours'):boolean> +struct -- !query 5 output -true +NULL -- !query 6 -select interval '1 year' = interval '360 days' +select null * interval '2 seconds' -- !query 6 schema -struct<(INTERVAL '1 years' = INTERVAL '360 days'):boolean> +struct -- !query 6 output -true +NULL -- !query 7 -select interval '1 year 2 month' = interval '420 days' +select -interval '-1 month 1 day -1 second' -- !query 7 schema -struct<(INTERVAL '1 years 2 months' = INTERVAL '420 days'):boolean> +struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 7 output -true +1 months -1 days 1 seconds -- !query 8 -select interval '1 year' = interval '365 days' +select -interval -1 month 1 day -1 second -- !query 8 schema -struct<(INTERVAL '1 years' = INTERVAL '365 days'):boolean> +struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 8 output -false +1 months -1 days 1 seconds -- !query 9 -select interval '1 month' = interval '30 days' +select +interval '-1 month 1 day -1 second' -- !query 9 schema -struct<(INTERVAL '1 months' = INTERVAL '30 days'):boolean> +struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 9 output -true +-1 months 1 days -1 seconds -- !query 10 -select interval '1 minutes' = interval '1 hour' +select +interval -1 month 1 day -1 second -- !query 10 schema -struct<(INTERVAL '1 minutes' = INTERVAL '1 hours'):boolean> +struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 10 output -false +-1 months 1 days -1 seconds -- !query 11 -select interval '1 minutes' = null +select make_interval(1) -- !query 11 schema -struct<(INTERVAL '1 minutes' = CAST(NULL AS INTERVAL)):boolean> +struct -- !query 11 output -NULL +1 years -- !query 12 -select null = interval '-1 day' +select make_interval(1, 2) -- !query 12 schema -struct<(CAST(NULL AS INTERVAL) = INTERVAL '-1 days'):boolean> +struct -- !query 12 output -NULL +1 years 2 months -- !query 13 -select interval '1 minutes' <=> null +select make_interval(1, 2, 3) -- !query 13 schema -struct<(INTERVAL '1 minutes' <=> CAST(NULL AS INTERVAL)):boolean> +struct -- !query 13 output -false +1 years 2 months 21 days -- !query 14 -select null <=> interval '1 minutes' +select make_interval(1, 2, 3, 4) -- !query 14 schema -struct<(CAST(NULL AS INTERVAL) <=> INTERVAL '1 minutes'):boolean> +struct -- !query 14 output -false +1 years 2 months 25 days -- !query 15 -select INTERVAL '9 years 1 months -1 weeks -4 days -10 hours -46 minutes' > interval '1 minutes' +select make_interval(1, 2, 3, 4, 5) -- !query 15 schema -struct<(INTERVAL '9 years 1 months -11 days -10 hours -46 minutes' > INTERVAL '1 minutes'):boolean> +struct -- !query 15 output -true +1 years 2 months 25 days 5 hours -- !query 16 -select cast(v as interval) i from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) order by i +select make_interval(1, 2, 3, 4, 5, 6) -- !query 16 schema -struct +struct -- !query 16 output -1 seconds -3 seconds -4 seconds +1 years 2 months 25 days 5 hours 6 minutes -- !query 17 -select interval '1 month 120 days' > interval '2 month' +select make_interval(1, 2, 3, 4, 5, 6, 7.008009) -- !query 17 schema -struct<(INTERVAL '1 months 120 days' > INTERVAL '2 months'):boolean> +struct -- !query 17 output -true +1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds -- !query 18 -select interval '1 month 30 days' = interval '2 month' +select cast('1 second' as interval) -- !query 18 schema -struct<(INTERVAL '1 months 30 days' = INTERVAL '2 months'):boolean> +struct -- !query 18 output -true +1 seconds -- !query 19 -select interval '1 month 29 days 40 hours' > interval '2 month' +select cast('+1 second' as interval) -- !query 19 schema -struct<(INTERVAL '1 months 29 days 40 hours' > INTERVAL '2 months'):boolean> +struct -- !query 19 output -true +1 seconds -- !query 20 -select max(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) +select cast('-1 second' as interval) -- !query 20 schema -struct +struct -- !query 20 output -4 seconds +-1 seconds -- !query 21 -select min(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) +select cast('+ 1 second' as interval) -- !query 21 schema -struct +struct -- !query 21 output 1 seconds -- !query 22 -select 3 * (timestamp'2019-10-15 10:11:12.001002' - date'2019-10-15') +select cast('- 1 second' as interval) -- !query 22 schema -struct +struct -- !query 22 output -30 hours 33 minutes 36.003006 seconds +-1 seconds -- !query 23 -select interval 4 month 2 weeks 3 microseconds * 1.5 +select cast('- -1 second' as interval) -- !query 23 schema -struct +struct -- !query 23 output -6 months 21 days 0.000005 seconds +NULL -- !query 24 -select (timestamp'2019-10-15' - timestamp'2019-10-14') / 1.5 +select cast('- +1 second' as interval) -- !query 24 schema -struct +struct -- !query 24 output -16 hours +NULL -- !query 25 -select interval '2 seconds' / 0 --- !query 25 schema -struct<> --- !query 25 output -java.lang.ArithmeticException -divide by zero - - --- !query 26 -select interval '2 seconds' / null --- !query 26 schema -struct --- !query 26 output -NULL - - --- !query 27 -select interval '2 seconds' * null --- !query 27 schema -struct --- !query 27 output -NULL - - --- !query 28 -select null * interval '2 seconds' --- !query 28 schema -struct --- !query 28 output -NULL - - --- !query 29 -select -interval '-1 month 1 day -1 second' --- !query 29 schema -struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 29 output -1 months -1 days 1 seconds - - --- !query 30 -select -interval -1 month 1 day -1 second --- !query 30 schema -struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 30 output -1 months -1 days 1 seconds - - --- !query 31 -select +interval '-1 month 1 day -1 second' --- !query 31 schema -struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 31 output --1 months 1 days -1 seconds - - --- !query 32 -select +interval -1 month 1 day -1 second --- !query 32 schema -struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 32 output --1 months 1 days -1 seconds - - --- !query 33 -select make_interval(1) --- !query 33 schema -struct --- !query 33 output -1 years - - --- !query 34 -select make_interval(1, 2) --- !query 34 schema -struct --- !query 34 output -1 years 2 months - - --- !query 35 -select make_interval(1, 2, 3) --- !query 35 schema -struct --- !query 35 output -1 years 2 months 21 days - - --- !query 36 -select make_interval(1, 2, 3, 4) --- !query 36 schema -struct --- !query 36 output -1 years 2 months 25 days - - --- !query 37 -select make_interval(1, 2, 3, 4, 5) --- !query 37 schema -struct --- !query 37 output -1 years 2 months 25 days 5 hours - - --- !query 38 -select make_interval(1, 2, 3, 4, 5, 6) --- !query 38 schema -struct --- !query 38 output -1 years 2 months 25 days 5 hours 6 minutes - - --- !query 39 -select make_interval(1, 2, 3, 4, 5, 6, 7.008009) --- !query 39 schema -struct --- !query 39 output -1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds - - --- !query 40 -select cast('1 second' as interval) --- !query 40 schema -struct --- !query 40 output -1 seconds - - --- !query 41 -select cast('+1 second' as interval) --- !query 41 schema -struct --- !query 41 output -1 seconds - - --- !query 42 -select cast('-1 second' as interval) --- !query 42 schema -struct --- !query 42 output --1 seconds - - --- !query 43 -select cast('+ 1 second' as interval) --- !query 43 schema -struct --- !query 43 output -1 seconds - - --- !query 44 -select cast('- 1 second' as interval) --- !query 44 schema -struct --- !query 44 output --1 seconds - - --- !query 45 -select cast('- -1 second' as interval) --- !query 45 schema -struct --- !query 45 output -NULL - - --- !query 46 -select cast('- +1 second' as interval) --- !query 46 schema -struct --- !query 46 output -NULL - - --- !query 47 select interval 13.123456789 seconds, interval -13.123456789 second --- !query 47 schema +-- !query 25 schema struct --- !query 47 output +-- !query 25 output 13.123456 seconds -13.123456 seconds --- !query 48 +-- !query 26 select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond --- !query 48 schema +-- !query 26 schema struct --- !query 48 output +-- !query 26 output 1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds --- !query 49 +-- !query 27 select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second --- !query 49 schema +-- !query 27 schema struct --- !query 49 output +-- !query 27 output 32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds --- !query 50 +-- !query 28 select interval '0 0:0:0.1' day to second --- !query 50 schema +-- !query 28 schema struct --- !query 50 output +-- !query 28 output 0.1 seconds --- !query 51 +-- !query 29 select interval '10-9' year to month --- !query 51 schema +-- !query 29 schema struct --- !query 51 output +-- !query 29 output 10 years 9 months --- !query 52 +-- !query 30 select interval '20 15' day to hour --- !query 52 schema +-- !query 30 schema struct --- !query 52 output +-- !query 30 output 20 days 15 hours --- !query 53 +-- !query 31 select interval '20 15:40' day to minute --- !query 53 schema +-- !query 31 schema struct --- !query 53 output +-- !query 31 output 20 days 15 hours 40 minutes --- !query 54 +-- !query 32 select interval '20 15:40:32.99899999' day to second --- !query 54 schema +-- !query 32 schema struct --- !query 54 output +-- !query 32 output 20 days 15 hours 40 minutes 32.998999 seconds --- !query 55 +-- !query 33 select interval '15:40' hour to minute --- !query 55 schema +-- !query 33 schema struct --- !query 55 output +-- !query 33 output 15 hours 40 minutes --- !query 56 +-- !query 34 select interval '15:40:32.99899999' hour to second --- !query 56 schema +-- !query 34 schema struct --- !query 56 output +-- !query 34 output 15 hours 40 minutes 32.998999 seconds --- !query 57 +-- !query 35 select interval '40:32.99899999' minute to second --- !query 57 schema +-- !query 35 schema struct --- !query 57 output +-- !query 35 output 40 minutes 32.998999 seconds --- !query 58 +-- !query 36 select interval '40:32' minute to second --- !query 58 schema +-- !query 36 schema struct --- !query 58 output +-- !query 36 output 40 minutes 32 seconds --- !query 59 +-- !query 37 select interval 30 day day --- !query 59 schema +-- !query 37 schema struct<> --- !query 59 output +-- !query 37 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 23) @@ -491,11 +313,11 @@ select interval 30 day day -----------------------^^^ --- !query 60 +-- !query 38 select interval '20 15:40:32.99899999' day to hour --- !query 60 schema +-- !query 38 schema struct<> --- !query 60 output +-- !query 38 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d+) (?\d{1,2})$': 20 15:40:32.99899999(line 1, pos 16) @@ -505,11 +327,11 @@ select interval '20 15:40:32.99899999' day to hour ----------------^^^ --- !query 61 +-- !query 39 select interval '20 15:40:32.99899999' day to minute --- !query 61 schema +-- !query 39 schema struct<> --- !query 61 output +-- !query 39 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d+) (?\d{1,2}):(?\d{1,2})$': 20 15:40:32.99899999(line 1, pos 16) @@ -519,11 +341,11 @@ select interval '20 15:40:32.99899999' day to minute ----------------^^^ --- !query 62 +-- !query 40 select interval '15:40:32.99899999' hour to minute --- !query 62 schema +-- !query 40 schema struct<> --- !query 62 output +-- !query 40 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?\d{1,2})$': 15:40:32.99899999(line 1, pos 16) @@ -533,11 +355,11 @@ select interval '15:40:32.99899999' hour to minute ----------------^^^ --- !query 63 +-- !query 41 select interval '15:40.99899999' hour to second --- !query 63 schema +-- !query 41 schema struct<> --- !query 63 output +-- !query 41 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?\d{1,2}):(?(\d{1,2})(\.(\d{1,9}))?)$': 15:40.99899999(line 1, pos 16) @@ -547,11 +369,11 @@ select interval '15:40.99899999' hour to second ----------------^^^ --- !query 64 +-- !query 42 select interval '15:40' hour to second --- !query 64 schema +-- !query 42 schema struct<> --- !query 64 output +-- !query 42 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?\d{1,2}):(?(\d{1,2})(\.(\d{1,9}))?)$': 15:40(line 1, pos 16) @@ -561,11 +383,11 @@ select interval '15:40' hour to second ----------------^^^ --- !query 65 +-- !query 43 select interval '20 40:32.99899999' minute to second --- !query 65 schema +-- !query 43 schema struct<> --- !query 65 output +-- !query 43 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?(\d{1,2})(\.(\d{1,9}))?)$': 20 40:32.99899999(line 1, pos 16) @@ -575,11 +397,11 @@ select interval '20 40:32.99899999' minute to second ----------------^^^ --- !query 66 +-- !query 44 select interval 10 nanoseconds --- !query 66 schema +-- !query 44 schema struct<> --- !query 66 output +-- !query 44 output org.apache.spark.sql.catalyst.parser.ParseException Error parsing ' 10 nanoseconds' to interval, invalid unit 'nanoseconds'(line 1, pos 16) @@ -589,35 +411,35 @@ select interval 10 nanoseconds ----------------^^^ --- !query 67 +-- !query 45 select map(1, interval 1 day, 2, interval 3 week) --- !query 67 schema +-- !query 45 schema struct> --- !query 67 output +-- !query 45 output {1:1 days,2:21 days} --- !query 68 +-- !query 46 select interval 'interval 3 year 1 hour' --- !query 68 schema +-- !query 46 schema struct --- !query 68 output +-- !query 46 output 3 years 1 hours --- !query 69 +-- !query 47 select interval '3 year 1 hour' --- !query 69 schema +-- !query 47 schema struct --- !query 69 output +-- !query 47 output 3 years 1 hours --- !query 70 +-- !query 48 select interval --- !query 70 schema +-- !query 48 schema struct<> --- !query 70 output +-- !query 48 output org.apache.spark.sql.catalyst.parser.ParseException at least one time unit should be given for interval literal(line 1, pos 7) @@ -627,11 +449,11 @@ select interval -------^^^ --- !query 71 +-- !query 49 select interval 1 fake_unit --- !query 71 schema +-- !query 49 schema struct<> --- !query 71 output +-- !query 49 output org.apache.spark.sql.catalyst.parser.ParseException Error parsing ' 1 fake_unit' to interval, invalid unit 'fake_unit'(line 1, pos 16) @@ -641,11 +463,11 @@ select interval 1 fake_unit ----------------^^^ --- !query 72 +-- !query 50 select interval 1 year to month --- !query 72 schema +-- !query 50 schema struct<> --- !query 72 output +-- !query 50 output org.apache.spark.sql.catalyst.parser.ParseException The value of from-to unit must be a string(line 1, pos 16) @@ -655,11 +477,11 @@ select interval 1 year to month ----------------^^^ --- !query 73 +-- !query 51 select interval '1' year to second --- !query 73 schema +-- !query 51 schema struct<> --- !query 73 output +-- !query 51 output org.apache.spark.sql.catalyst.parser.ParseException Intervals FROM year TO second are not supported.(line 1, pos 16) @@ -669,11 +491,11 @@ select interval '1' year to second ----------------^^^ --- !query 74 +-- !query 52 select interval '10-9' year to month '2-1' year to month --- !query 74 schema +-- !query 52 schema struct<> --- !query 74 output +-- !query 52 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) @@ -683,11 +505,11 @@ select interval '10-9' year to month '2-1' year to month -------------------------------------^^^ --- !query 75 +-- !query 53 select interval '10-9' year to month '12:11:10' hour to second --- !query 75 schema +-- !query 53 schema struct<> --- !query 75 output +-- !query 53 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) @@ -697,11 +519,11 @@ select interval '10-9' year to month '12:11:10' hour to second -------------------------------------^^^ --- !query 76 +-- !query 54 select interval '1 15:11' day to minute '12:11:10' hour to second --- !query 76 schema +-- !query 54 schema struct<> --- !query 76 output +-- !query 54 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 40) @@ -711,11 +533,11 @@ select interval '1 15:11' day to minute '12:11:10' hour to second ----------------------------------------^^^ --- !query 77 +-- !query 55 select interval 1 year '2-1' year to month --- !query 77 schema +-- !query 55 schema struct<> --- !query 77 output +-- !query 55 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) @@ -725,11 +547,11 @@ select interval 1 year '2-1' year to month -----------------------^^^ --- !query 78 +-- !query 56 select interval 1 year '12:11:10' hour to second --- !query 78 schema +-- !query 56 schema struct<> --- !query 78 output +-- !query 56 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) @@ -739,11 +561,11 @@ select interval 1 year '12:11:10' hour to second -----------------------^^^ --- !query 79 +-- !query 57 select interval '10-9' year to month '1' year --- !query 79 schema +-- !query 57 schema struct<> --- !query 79 output +-- !query 57 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) @@ -753,11 +575,11 @@ select interval '10-9' year to month '1' year -------------------------------------^^^ --- !query 80 +-- !query 58 select interval '12:11:10' hour to second '1' year --- !query 80 schema +-- !query 58 schema struct<> --- !query 80 output +-- !query 58 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 42) @@ -767,11 +589,11 @@ select interval '12:11:10' hour to second '1' year ------------------------------------------^^^ --- !query 81 +-- !query 59 select interval (-30) day --- !query 81 schema +-- !query 59 schema struct<> --- !query 81 output +-- !query 59 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 22) @@ -781,11 +603,11 @@ select interval (-30) day ----------------------^^^ --- !query 82 +-- !query 60 select interval (a + 1) day --- !query 82 schema +-- !query 60 schema struct<> --- !query 82 output +-- !query 60 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 24) @@ -795,11 +617,11 @@ select interval (a + 1) day ------------------------^^^ --- !query 83 +-- !query 61 select interval 30 day day day --- !query 83 schema +-- !query 61 schema struct<> --- !query 83 output +-- !query 61 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 23) @@ -809,192 +631,192 @@ select interval 30 day day day -----------------------^^^ --- !query 84 +-- !query 62 select sum(cast(null as interval)) --- !query 84 schema +-- !query 62 schema struct --- !query 84 output +-- !query 62 output NULL --- !query 85 +-- !query 63 select sum(cast(v as interval)) from VALUES ('1 seconds') t(v) where 1=0 --- !query 85 schema +-- !query 63 schema struct --- !query 85 output +-- !query 63 output NULL --- !query 86 +-- !query 64 select sum(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) --- !query 86 schema +-- !query 64 schema struct --- !query 86 output +-- !query 64 output 3 seconds --- !query 87 +-- !query 65 select sum(cast(v as interval)) from VALUES ('-1 seconds'), ('2 seconds'), (null) t(v) --- !query 87 schema +-- !query 65 schema struct --- !query 87 output +-- !query 65 output 1 seconds --- !query 88 +-- !query 66 select sum(cast(v as interval)) from VALUES ('-1 seconds'), ('-2 seconds'), (null) t(v) --- !query 88 schema +-- !query 66 schema struct --- !query 88 output +-- !query 66 output -3 seconds --- !query 89 +-- !query 67 select sum(cast(v as interval)) from VALUES ('-1 weeks'), ('2 seconds'), (null) t(v) --- !query 89 schema +-- !query 67 schema struct --- !query 89 output +-- !query 67 output -7 days 2 seconds --- !query 90 +-- !query 68 select i, sum(cast(v as interval)) from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) group by i --- !query 90 schema +-- !query 68 schema struct --- !query 90 output +-- !query 68 output 1 -2 days 2 2 seconds 3 NULL --- !query 91 +-- !query 69 select sum(cast(v as interval)) as sv from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) having sv is not null --- !query 91 schema +-- !query 69 schema struct --- !query 91 output +-- !query 69 output -2 days 2 seconds --- !query 92 +-- !query 70 SELECT i, sum(cast(v as interval)) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM VALUES(1, '1 seconds'), (1, '2 seconds'), (2, NULL), (2, NULL) t(i,v) --- !query 92 schema +-- !query 70 schema struct --- !query 92 output +-- !query 70 output 1 2 seconds 1 3 seconds 2 NULL 2 NULL --- !query 93 +-- !query 71 select avg(cast(v as interval)) from VALUES (null) t(v) --- !query 93 schema +-- !query 71 schema struct --- !query 93 output +-- !query 71 output NULL --- !query 94 +-- !query 72 select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) where 1=0 --- !query 94 schema +-- !query 72 schema struct --- !query 94 output +-- !query 72 output NULL --- !query 95 +-- !query 73 select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) --- !query 95 schema +-- !query 73 schema struct --- !query 95 output +-- !query 73 output 1.5 seconds --- !query 96 +-- !query 74 select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('2 seconds'), (null) t(v) --- !query 96 schema +-- !query 74 schema struct --- !query 96 output +-- !query 74 output 0.5 seconds --- !query 97 +-- !query 75 select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('-2 seconds'), (null) t(v) --- !query 97 schema +-- !query 75 schema struct --- !query 97 output +-- !query 75 output -1.5 seconds --- !query 98 +-- !query 76 select avg(cast(v as interval)) from VALUES ('-1 weeks'), ('2 seconds'), (null) t(v) --- !query 98 schema +-- !query 76 schema struct --- !query 98 output +-- !query 76 output -3 days -11 hours -59 minutes -59 seconds --- !query 99 +-- !query 77 select i, avg(cast(v as interval)) from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) group by i --- !query 99 schema +-- !query 77 schema struct --- !query 99 output +-- !query 77 output 1 -1 days 2 2 seconds 3 NULL --- !query 100 +-- !query 78 select avg(cast(v as interval)) as sv from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) having sv is not null --- !query 100 schema +-- !query 78 schema struct --- !query 100 output +-- !query 78 output -15 hours -59 minutes -59.333333 seconds --- !query 101 +-- !query 79 SELECT i, avg(cast(v as interval)) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM VALUES (1,'1 seconds'), (1,'2 seconds'), (2,NULL), (2,NULL) t(i,v) --- !query 101 schema +-- !query 79 schema struct --- !query 101 output +-- !query 79 output 1 1.5 seconds 1 2 seconds 2 NULL 2 NULL --- !query 102 +-- !query 80 create temporary view interval_arithmetic as select CAST(dateval AS date), CAST(tsval AS timestamp) from values ('2012-01-01', '2012-01-01') as interval_arithmetic(dateval, tsval) --- !query 102 schema +-- !query 80 schema struct<> --- !query 102 output +-- !query 80 output --- !query 103 +-- !query 81 select dateval, dateval - interval '2-2' year to month, @@ -1004,13 +826,13 @@ select - interval '2-2' year to month + dateval, interval '2-2' year to month + dateval from interval_arithmetic --- !query 103 schema +-- !query 81 schema struct --- !query 103 output +-- !query 81 output 2012-01-01 2009-11-01 2014-03-01 2014-03-01 2009-11-01 2009-11-01 2014-03-01 --- !query 104 +-- !query 82 select tsval, tsval - interval '2-2' year to month, @@ -1020,24 +842,24 @@ select - interval '2-2' year to month + tsval, interval '2-2' year to month + tsval from interval_arithmetic --- !query 104 schema +-- !query 82 schema struct --- !query 104 output +-- !query 82 output 2012-01-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 2014-03-01 00:00:00 2009-11-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 --- !query 105 +-- !query 83 select interval '2-2' year to month + interval '3-3' year to month, interval '2-2' year to month - interval '3-3' year to month from interval_arithmetic --- !query 105 schema +-- !query 83 schema struct<(INTERVAL '2 years 2 months' + INTERVAL '3 years 3 months'):interval,(INTERVAL '2 years 2 months' - INTERVAL '3 years 3 months'):interval> --- !query 105 output +-- !query 83 output 5 years 5 months -1 years -1 months --- !query 106 +-- !query 84 select dateval, dateval - interval '99 11:22:33.123456789' day to second, @@ -1047,13 +869,13 @@ select -interval '99 11:22:33.123456789' day to second + dateval, interval '99 11:22:33.123456789' day to second + dateval from interval_arithmetic --- !query 106 schema +-- !query 84 schema struct --- !query 106 output +-- !query 84 output 2012-01-01 2011-09-23 2012-04-09 2012-04-09 2011-09-23 2011-09-23 2012-04-09 --- !query 107 +-- !query 85 select tsval, tsval - interval '99 11:22:33.123456789' day to second, @@ -1063,103 +885,103 @@ select -interval '99 11:22:33.123456789' day to second + tsval, interval '99 11:22:33.123456789' day to second + tsval from interval_arithmetic --- !query 107 schema +-- !query 85 schema struct --- !query 107 output +-- !query 85 output 2012-01-01 00:00:00 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 2012-04-09 11:22:33.123456 2011-09-23 12:37:26.876544 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 --- !query 108 +-- !query 86 select interval '99 11:22:33.123456789' day to second + interval '10 9:8:7.123456789' day to second, interval '99 11:22:33.123456789' day to second - interval '10 9:8:7.123456789' day to second from interval_arithmetic --- !query 108 schema +-- !query 86 schema struct<(INTERVAL '99 days 11 hours 22 minutes 33.123456 seconds' + INTERVAL '10 days 9 hours 8 minutes 7.123456 seconds'):interval,(INTERVAL '99 days 11 hours 22 minutes 33.123456 seconds' - INTERVAL '10 days 9 hours 8 minutes 7.123456 seconds'):interval> --- !query 108 output +-- !query 86 output 109 days 20 hours 30 minutes 40.246912 seconds 89 days 2 hours 14 minutes 26 seconds --- !query 109 +-- !query 87 select interval '\t interval 1 day' --- !query 109 schema +-- !query 87 schema struct --- !query 109 output +-- !query 87 output 1 days --- !query 110 +-- !query 88 select interval 'interval \t 1\tday' --- !query 110 schema +-- !query 88 schema struct --- !query 110 output +-- !query 88 output 1 days --- !query 111 +-- !query 89 select interval 'interval\t1\tday' --- !query 111 schema +-- !query 89 schema struct --- !query 111 output +-- !query 89 output 1 days --- !query 112 +-- !query 90 select interval '1\t' day --- !query 112 schema +-- !query 90 schema struct --- !query 112 output +-- !query 90 output 1 days --- !query 113 +-- !query 91 select interval '1 ' day --- !query 113 schema +-- !query 91 schema struct --- !query 113 output +-- !query 91 output 1 days --- !query 114 +-- !query 92 select -(a) from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 114 schema +-- !query 92 schema struct<> --- !query 114 output +-- !query 92 output java.lang.ArithmeticException integer overflow --- !query 115 +-- !query 93 select a - b from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 115 schema +-- !query 93 schema struct<> --- !query 115 output +-- !query 93 output java.lang.ArithmeticException integer overflow --- !query 116 +-- !query 94 select b + interval '1 month' from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 116 schema +-- !query 94 schema struct<> --- !query 116 output +-- !query 94 output java.lang.ArithmeticException integer overflow --- !query 117 +-- !query 95 select a * 1.1 from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 117 schema +-- !query 95 schema struct<> --- !query 117 output +-- !query 95 output java.lang.ArithmeticException integer overflow --- !query 118 +-- !query 96 select a / 0.5 from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 118 schema +-- !query 96 schema struct<> --- !query 118 output +-- !query 96 output java.lang.ArithmeticException integer overflow diff --git a/sql/core/src/test/resources/sql-tests/results/interval.sql.out b/sql/core/src/test/resources/sql-tests/results/interval.sql.out index 767e3957ba..633ee6fccc 100644 --- a/sql/core/src/test/resources/sql-tests/results/interval.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/interval.sql.out @@ -1,495 +1,317 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 119 +-- Number of queries: 97 -- !query 0 -select interval '1 day' > interval '23 hour' +select 3 * (timestamp'2019-10-15 10:11:12.001002' - date'2019-10-15') -- !query 0 schema -struct<(INTERVAL '1 days' > INTERVAL '23 hours'):boolean> +struct -- !query 0 output -true +30 hours 33 minutes 36.003006 seconds -- !query 1 -select interval '-1 day' >= interval '-23 hour' +select interval 4 month 2 weeks 3 microseconds * 1.5 -- !query 1 schema -struct<(INTERVAL '-1 days' >= INTERVAL '-23 hours'):boolean> +struct -- !query 1 output -false +6 months 21 days 0.000005 seconds -- !query 2 -select interval '-1 day' > null +select (timestamp'2019-10-15' - timestamp'2019-10-14') / 1.5 -- !query 2 schema -struct<(INTERVAL '-1 days' > CAST(NULL AS INTERVAL)):boolean> +struct -- !query 2 output -NULL +16 hours -- !query 3 -select null > interval '-1 day' +select interval '2 seconds' / 0 -- !query 3 schema -struct<(CAST(NULL AS INTERVAL) > INTERVAL '-1 days'):boolean> +struct<> -- !query 3 output -NULL +java.lang.ArithmeticException +divide by zero -- !query 4 -select interval '1 minutes' < interval '1 hour' +select interval '2 seconds' / null -- !query 4 schema -struct<(INTERVAL '1 minutes' < INTERVAL '1 hours'):boolean> +struct -- !query 4 output -true +NULL -- !query 5 -select interval '-1 day' <= interval '-23 hour' +select interval '2 seconds' * null -- !query 5 schema -struct<(INTERVAL '-1 days' <= INTERVAL '-23 hours'):boolean> +struct -- !query 5 output -true +NULL -- !query 6 -select interval '1 year' = interval '360 days' +select null * interval '2 seconds' -- !query 6 schema -struct<(INTERVAL '1 years' = INTERVAL '360 days'):boolean> +struct -- !query 6 output -true +NULL -- !query 7 -select interval '1 year 2 month' = interval '420 days' +select -interval '-1 month 1 day -1 second' -- !query 7 schema -struct<(INTERVAL '1 years 2 months' = INTERVAL '420 days'):boolean> +struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 7 output -true +1 months -1 days 1 seconds -- !query 8 -select interval '1 year' = interval '365 days' +select -interval -1 month 1 day -1 second -- !query 8 schema -struct<(INTERVAL '1 years' = INTERVAL '365 days'):boolean> +struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 8 output -false +1 months -1 days 1 seconds -- !query 9 -select interval '1 month' = interval '30 days' +select +interval '-1 month 1 day -1 second' -- !query 9 schema -struct<(INTERVAL '1 months' = INTERVAL '30 days'):boolean> +struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 9 output -true +-1 months 1 days -1 seconds -- !query 10 -select interval '1 minutes' = interval '1 hour' +select +interval -1 month 1 day -1 second -- !query 10 schema -struct<(INTERVAL '1 minutes' = INTERVAL '1 hours'):boolean> +struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> -- !query 10 output -false +-1 months 1 days -1 seconds -- !query 11 -select interval '1 minutes' = null +select make_interval(1) -- !query 11 schema -struct<(INTERVAL '1 minutes' = CAST(NULL AS INTERVAL)):boolean> +struct -- !query 11 output -NULL +1 years -- !query 12 -select null = interval '-1 day' +select make_interval(1, 2) -- !query 12 schema -struct<(CAST(NULL AS INTERVAL) = INTERVAL '-1 days'):boolean> +struct -- !query 12 output -NULL +1 years 2 months -- !query 13 -select interval '1 minutes' <=> null +select make_interval(1, 2, 3) -- !query 13 schema -struct<(INTERVAL '1 minutes' <=> CAST(NULL AS INTERVAL)):boolean> +struct -- !query 13 output -false +1 years 2 months 21 days -- !query 14 -select null <=> interval '1 minutes' +select make_interval(1, 2, 3, 4) -- !query 14 schema -struct<(CAST(NULL AS INTERVAL) <=> INTERVAL '1 minutes'):boolean> +struct -- !query 14 output -false +1 years 2 months 25 days -- !query 15 -select INTERVAL '9 years 1 months -1 weeks -4 days -10 hours -46 minutes' > interval '1 minutes' +select make_interval(1, 2, 3, 4, 5) -- !query 15 schema -struct<(INTERVAL '9 years 1 months -11 days -10 hours -46 minutes' > INTERVAL '1 minutes'):boolean> +struct -- !query 15 output -true +1 years 2 months 25 days 5 hours -- !query 16 -select cast(v as interval) i from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) order by i +select make_interval(1, 2, 3, 4, 5, 6) -- !query 16 schema -struct +struct -- !query 16 output -1 seconds -3 seconds -4 seconds +1 years 2 months 25 days 5 hours 6 minutes -- !query 17 -select interval '1 month 120 days' > interval '2 month' +select make_interval(1, 2, 3, 4, 5, 6, 7.008009) -- !query 17 schema -struct<(INTERVAL '1 months 120 days' > INTERVAL '2 months'):boolean> +struct -- !query 17 output -true +1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds -- !query 18 -select interval '1 month 30 days' = interval '2 month' +select cast('1 second' as interval) -- !query 18 schema -struct<(INTERVAL '1 months 30 days' = INTERVAL '2 months'):boolean> +struct -- !query 18 output -true +1 seconds -- !query 19 -select interval '1 month 29 days 40 hours' > interval '2 month' +select cast('+1 second' as interval) -- !query 19 schema -struct<(INTERVAL '1 months 29 days 40 hours' > INTERVAL '2 months'):boolean> +struct -- !query 19 output -true +1 seconds -- !query 20 -select max(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) +select cast('-1 second' as interval) -- !query 20 schema -struct +struct -- !query 20 output -4 seconds +-1 seconds -- !query 21 -select min(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) +select cast('+ 1 second' as interval) -- !query 21 schema -struct +struct -- !query 21 output 1 seconds -- !query 22 -select 3 * (timestamp'2019-10-15 10:11:12.001002' - date'2019-10-15') +select cast('- 1 second' as interval) -- !query 22 schema -struct +struct -- !query 22 output -30 hours 33 minutes 36.003006 seconds +-1 seconds -- !query 23 -select interval 4 month 2 weeks 3 microseconds * 1.5 +select cast('- -1 second' as interval) -- !query 23 schema -struct +struct -- !query 23 output -6 months 21 days 0.000005 seconds +NULL -- !query 24 -select (timestamp'2019-10-15' - timestamp'2019-10-14') / 1.5 +select cast('- +1 second' as interval) -- !query 24 schema -struct +struct -- !query 24 output -16 hours +NULL -- !query 25 -select interval '2 seconds' / 0 --- !query 25 schema -struct<> --- !query 25 output -java.lang.ArithmeticException -divide by zero - - --- !query 26 -select interval '2 seconds' / null --- !query 26 schema -struct --- !query 26 output -NULL - - --- !query 27 -select interval '2 seconds' * null --- !query 27 schema -struct --- !query 27 output -NULL - - --- !query 28 -select null * interval '2 seconds' --- !query 28 schema -struct --- !query 28 output -NULL - - --- !query 29 -select -interval '-1 month 1 day -1 second' --- !query 29 schema -struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 29 output -1 months -1 days 1 seconds - - --- !query 30 -select -interval -1 month 1 day -1 second --- !query 30 schema -struct<(- INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 30 output -1 months -1 days 1 seconds - - --- !query 31 -select +interval '-1 month 1 day -1 second' --- !query 31 schema -struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 31 output --1 months 1 days -1 seconds - - --- !query 32 -select +interval -1 month 1 day -1 second --- !query 32 schema -struct<(+ INTERVAL '-1 months 1 days -1 seconds'):interval> --- !query 32 output --1 months 1 days -1 seconds - - --- !query 33 -select make_interval(1) --- !query 33 schema -struct --- !query 33 output -1 years - - --- !query 34 -select make_interval(1, 2) --- !query 34 schema -struct --- !query 34 output -1 years 2 months - - --- !query 35 -select make_interval(1, 2, 3) --- !query 35 schema -struct --- !query 35 output -1 years 2 months 21 days - - --- !query 36 -select make_interval(1, 2, 3, 4) --- !query 36 schema -struct --- !query 36 output -1 years 2 months 25 days - - --- !query 37 -select make_interval(1, 2, 3, 4, 5) --- !query 37 schema -struct --- !query 37 output -1 years 2 months 25 days 5 hours - - --- !query 38 -select make_interval(1, 2, 3, 4, 5, 6) --- !query 38 schema -struct --- !query 38 output -1 years 2 months 25 days 5 hours 6 minutes - - --- !query 39 -select make_interval(1, 2, 3, 4, 5, 6, 7.008009) --- !query 39 schema -struct --- !query 39 output -1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds - - --- !query 40 -select cast('1 second' as interval) --- !query 40 schema -struct --- !query 40 output -1 seconds - - --- !query 41 -select cast('+1 second' as interval) --- !query 41 schema -struct --- !query 41 output -1 seconds - - --- !query 42 -select cast('-1 second' as interval) --- !query 42 schema -struct --- !query 42 output --1 seconds - - --- !query 43 -select cast('+ 1 second' as interval) --- !query 43 schema -struct --- !query 43 output -1 seconds - - --- !query 44 -select cast('- 1 second' as interval) --- !query 44 schema -struct --- !query 44 output --1 seconds - - --- !query 45 -select cast('- -1 second' as interval) --- !query 45 schema -struct --- !query 45 output -NULL - - --- !query 46 -select cast('- +1 second' as interval) --- !query 46 schema -struct --- !query 46 output -NULL - - --- !query 47 select interval 13.123456789 seconds, interval -13.123456789 second --- !query 47 schema +-- !query 25 schema struct --- !query 47 output +-- !query 25 output 13.123456 seconds -13.123456 seconds --- !query 48 +-- !query 26 select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond --- !query 48 schema +-- !query 26 schema struct --- !query 48 output +-- !query 26 output 1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds --- !query 49 +-- !query 27 select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second --- !query 49 schema +-- !query 27 schema struct --- !query 49 output +-- !query 27 output 32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds --- !query 50 +-- !query 28 select interval '0 0:0:0.1' day to second --- !query 50 schema +-- !query 28 schema struct --- !query 50 output +-- !query 28 output 0.1 seconds --- !query 51 +-- !query 29 select interval '10-9' year to month --- !query 51 schema +-- !query 29 schema struct --- !query 51 output +-- !query 29 output 10 years 9 months --- !query 52 +-- !query 30 select interval '20 15' day to hour --- !query 52 schema +-- !query 30 schema struct --- !query 52 output +-- !query 30 output 20 days 15 hours --- !query 53 +-- !query 31 select interval '20 15:40' day to minute --- !query 53 schema +-- !query 31 schema struct --- !query 53 output +-- !query 31 output 20 days 15 hours 40 minutes --- !query 54 +-- !query 32 select interval '20 15:40:32.99899999' day to second --- !query 54 schema +-- !query 32 schema struct --- !query 54 output +-- !query 32 output 20 days 15 hours 40 minutes 32.998999 seconds --- !query 55 +-- !query 33 select interval '15:40' hour to minute --- !query 55 schema +-- !query 33 schema struct --- !query 55 output +-- !query 33 output 15 hours 40 minutes --- !query 56 +-- !query 34 select interval '15:40:32.99899999' hour to second --- !query 56 schema +-- !query 34 schema struct --- !query 56 output +-- !query 34 output 15 hours 40 minutes 32.998999 seconds --- !query 57 +-- !query 35 select interval '40:32.99899999' minute to second --- !query 57 schema +-- !query 35 schema struct --- !query 57 output +-- !query 35 output 40 minutes 32.998999 seconds --- !query 58 +-- !query 36 select interval '40:32' minute to second --- !query 58 schema +-- !query 36 schema struct --- !query 58 output +-- !query 36 output 40 minutes 32 seconds --- !query 59 +-- !query 37 select interval 30 day day --- !query 59 schema +-- !query 37 schema struct --- !query 59 output +-- !query 37 output 30 days --- !query 60 +-- !query 38 select interval '20 15:40:32.99899999' day to hour --- !query 60 schema +-- !query 38 schema struct<> --- !query 60 output +-- !query 38 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d+) (?\d{1,2})$': 20 15:40:32.99899999(line 1, pos 16) @@ -499,11 +321,11 @@ select interval '20 15:40:32.99899999' day to hour ----------------^^^ --- !query 61 +-- !query 39 select interval '20 15:40:32.99899999' day to minute --- !query 61 schema +-- !query 39 schema struct<> --- !query 61 output +-- !query 39 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d+) (?\d{1,2}):(?\d{1,2})$': 20 15:40:32.99899999(line 1, pos 16) @@ -513,11 +335,11 @@ select interval '20 15:40:32.99899999' day to minute ----------------^^^ --- !query 62 +-- !query 40 select interval '15:40:32.99899999' hour to minute --- !query 62 schema +-- !query 40 schema struct<> --- !query 62 output +-- !query 40 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?\d{1,2})$': 15:40:32.99899999(line 1, pos 16) @@ -527,11 +349,11 @@ select interval '15:40:32.99899999' hour to minute ----------------^^^ --- !query 63 +-- !query 41 select interval '15:40.99899999' hour to second --- !query 63 schema +-- !query 41 schema struct<> --- !query 63 output +-- !query 41 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?\d{1,2}):(?(\d{1,2})(\.(\d{1,9}))?)$': 15:40.99899999(line 1, pos 16) @@ -541,11 +363,11 @@ select interval '15:40.99899999' hour to second ----------------^^^ --- !query 64 +-- !query 42 select interval '15:40' hour to second --- !query 64 schema +-- !query 42 schema struct<> --- !query 64 output +-- !query 42 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?\d{1,2}):(?(\d{1,2})(\.(\d{1,9}))?)$': 15:40(line 1, pos 16) @@ -555,11 +377,11 @@ select interval '15:40' hour to second ----------------^^^ --- !query 65 +-- !query 43 select interval '20 40:32.99899999' minute to second --- !query 65 schema +-- !query 43 schema struct<> --- !query 65 output +-- !query 43 output org.apache.spark.sql.catalyst.parser.ParseException requirement failed: Interval string must match day-time format of '^(?[+|-])?(?\d{1,2}):(?(\d{1,2})(\.(\d{1,9}))?)$': 20 40:32.99899999(line 1, pos 16) @@ -569,11 +391,11 @@ select interval '20 40:32.99899999' minute to second ----------------^^^ --- !query 66 +-- !query 44 select interval 10 nanoseconds --- !query 66 schema +-- !query 44 schema struct<> --- !query 66 output +-- !query 44 output org.apache.spark.sql.catalyst.parser.ParseException Error parsing ' 10 nanoseconds' to interval, invalid unit 'nanoseconds'(line 1, pos 16) @@ -583,35 +405,35 @@ select interval 10 nanoseconds ----------------^^^ --- !query 67 +-- !query 45 select map(1, interval 1 day, 2, interval 3 week) --- !query 67 schema +-- !query 45 schema struct> --- !query 67 output +-- !query 45 output {1:1 days,2:21 days} --- !query 68 +-- !query 46 select interval 'interval 3 year 1 hour' --- !query 68 schema +-- !query 46 schema struct --- !query 68 output +-- !query 46 output 3 years 1 hours --- !query 69 +-- !query 47 select interval '3 year 1 hour' --- !query 69 schema +-- !query 47 schema struct --- !query 69 output +-- !query 47 output 3 years 1 hours --- !query 70 +-- !query 48 select interval --- !query 70 schema +-- !query 48 schema struct<> --- !query 70 output +-- !query 48 output org.apache.spark.sql.catalyst.parser.ParseException at least one time unit should be given for interval literal(line 1, pos 7) @@ -621,11 +443,11 @@ select interval -------^^^ --- !query 71 +-- !query 49 select interval 1 fake_unit --- !query 71 schema +-- !query 49 schema struct<> --- !query 71 output +-- !query 49 output org.apache.spark.sql.catalyst.parser.ParseException Error parsing ' 1 fake_unit' to interval, invalid unit 'fake_unit'(line 1, pos 16) @@ -635,11 +457,11 @@ select interval 1 fake_unit ----------------^^^ --- !query 72 +-- !query 50 select interval 1 year to month --- !query 72 schema +-- !query 50 schema struct<> --- !query 72 output +-- !query 50 output org.apache.spark.sql.catalyst.parser.ParseException The value of from-to unit must be a string(line 1, pos 16) @@ -649,11 +471,11 @@ select interval 1 year to month ----------------^^^ --- !query 73 +-- !query 51 select interval '1' year to second --- !query 73 schema +-- !query 51 schema struct<> --- !query 73 output +-- !query 51 output org.apache.spark.sql.catalyst.parser.ParseException Intervals FROM year TO second are not supported.(line 1, pos 16) @@ -663,11 +485,11 @@ select interval '1' year to second ----------------^^^ --- !query 74 +-- !query 52 select interval '10-9' year to month '2-1' year to month --- !query 74 schema +-- !query 52 schema struct<> --- !query 74 output +-- !query 52 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) @@ -677,11 +499,11 @@ select interval '10-9' year to month '2-1' year to month -------------------------------------^^^ --- !query 75 +-- !query 53 select interval '10-9' year to month '12:11:10' hour to second --- !query 75 schema +-- !query 53 schema struct<> --- !query 75 output +-- !query 53 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) @@ -691,11 +513,11 @@ select interval '10-9' year to month '12:11:10' hour to second -------------------------------------^^^ --- !query 76 +-- !query 54 select interval '1 15:11' day to minute '12:11:10' hour to second --- !query 76 schema +-- !query 54 schema struct<> --- !query 76 output +-- !query 54 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 40) @@ -705,11 +527,11 @@ select interval '1 15:11' day to minute '12:11:10' hour to second ----------------------------------------^^^ --- !query 77 +-- !query 55 select interval 1 year '2-1' year to month --- !query 77 schema +-- !query 55 schema struct<> --- !query 77 output +-- !query 55 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) @@ -719,11 +541,11 @@ select interval 1 year '2-1' year to month -----------------------^^^ --- !query 78 +-- !query 56 select interval 1 year '12:11:10' hour to second --- !query 78 schema +-- !query 56 schema struct<> --- !query 78 output +-- !query 56 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) @@ -733,11 +555,11 @@ select interval 1 year '12:11:10' hour to second -----------------------^^^ --- !query 79 +-- !query 57 select interval '10-9' year to month '1' year --- !query 79 schema +-- !query 57 schema struct<> --- !query 79 output +-- !query 57 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) @@ -747,11 +569,11 @@ select interval '10-9' year to month '1' year -------------------------------------^^^ --- !query 80 +-- !query 58 select interval '12:11:10' hour to second '1' year --- !query 80 schema +-- !query 58 schema struct<> --- !query 80 output +-- !query 58 output org.apache.spark.sql.catalyst.parser.ParseException Can only have a single from-to unit in the interval literal syntax(line 1, pos 42) @@ -761,29 +583,29 @@ select interval '12:11:10' hour to second '1' year ------------------------------------------^^^ --- !query 81 +-- !query 59 select interval (-30) day --- !query 81 schema +-- !query 59 schema struct<> --- !query 81 output +-- !query 59 output org.apache.spark.sql.AnalysisException Undefined function: 'interval'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 7 --- !query 82 +-- !query 60 select interval (a + 1) day --- !query 82 schema +-- !query 60 schema struct<> --- !query 82 output +-- !query 60 output org.apache.spark.sql.AnalysisException Undefined function: 'interval'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 7 --- !query 83 +-- !query 61 select interval 30 day day day --- !query 83 schema +-- !query 61 schema struct<> --- !query 83 output +-- !query 61 output org.apache.spark.sql.catalyst.parser.ParseException extraneous input 'day' expecting (line 1, pos 27) @@ -793,192 +615,192 @@ select interval 30 day day day ---------------------------^^^ --- !query 84 +-- !query 62 select sum(cast(null as interval)) --- !query 84 schema +-- !query 62 schema struct --- !query 84 output +-- !query 62 output NULL --- !query 85 +-- !query 63 select sum(cast(v as interval)) from VALUES ('1 seconds') t(v) where 1=0 --- !query 85 schema +-- !query 63 schema struct --- !query 85 output +-- !query 63 output NULL --- !query 86 +-- !query 64 select sum(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) --- !query 86 schema +-- !query 64 schema struct --- !query 86 output +-- !query 64 output 3 seconds --- !query 87 +-- !query 65 select sum(cast(v as interval)) from VALUES ('-1 seconds'), ('2 seconds'), (null) t(v) --- !query 87 schema +-- !query 65 schema struct --- !query 87 output +-- !query 65 output 1 seconds --- !query 88 +-- !query 66 select sum(cast(v as interval)) from VALUES ('-1 seconds'), ('-2 seconds'), (null) t(v) --- !query 88 schema +-- !query 66 schema struct --- !query 88 output +-- !query 66 output -3 seconds --- !query 89 +-- !query 67 select sum(cast(v as interval)) from VALUES ('-1 weeks'), ('2 seconds'), (null) t(v) --- !query 89 schema +-- !query 67 schema struct --- !query 89 output +-- !query 67 output -7 days 2 seconds --- !query 90 +-- !query 68 select i, sum(cast(v as interval)) from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) group by i --- !query 90 schema +-- !query 68 schema struct --- !query 90 output +-- !query 68 output 1 -2 days 2 2 seconds 3 NULL --- !query 91 +-- !query 69 select sum(cast(v as interval)) as sv from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) having sv is not null --- !query 91 schema +-- !query 69 schema struct --- !query 91 output +-- !query 69 output -2 days 2 seconds --- !query 92 +-- !query 70 SELECT i, sum(cast(v as interval)) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM VALUES(1, '1 seconds'), (1, '2 seconds'), (2, NULL), (2, NULL) t(i,v) --- !query 92 schema +-- !query 70 schema struct --- !query 92 output +-- !query 70 output 1 2 seconds 1 3 seconds 2 NULL 2 NULL --- !query 93 +-- !query 71 select avg(cast(v as interval)) from VALUES (null) t(v) --- !query 93 schema +-- !query 71 schema struct --- !query 93 output +-- !query 71 output NULL --- !query 94 +-- !query 72 select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) where 1=0 --- !query 94 schema +-- !query 72 schema struct --- !query 94 output +-- !query 72 output NULL --- !query 95 +-- !query 73 select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) --- !query 95 schema +-- !query 73 schema struct --- !query 95 output +-- !query 73 output 1.5 seconds --- !query 96 +-- !query 74 select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('2 seconds'), (null) t(v) --- !query 96 schema +-- !query 74 schema struct --- !query 96 output +-- !query 74 output 0.5 seconds --- !query 97 +-- !query 75 select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('-2 seconds'), (null) t(v) --- !query 97 schema +-- !query 75 schema struct --- !query 97 output +-- !query 75 output -1.5 seconds --- !query 98 +-- !query 76 select avg(cast(v as interval)) from VALUES ('-1 weeks'), ('2 seconds'), (null) t(v) --- !query 98 schema +-- !query 76 schema struct --- !query 98 output +-- !query 76 output -3 days -11 hours -59 minutes -59 seconds --- !query 99 +-- !query 77 select i, avg(cast(v as interval)) from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) group by i --- !query 99 schema +-- !query 77 schema struct --- !query 99 output +-- !query 77 output 1 -1 days 2 2 seconds 3 NULL --- !query 100 +-- !query 78 select avg(cast(v as interval)) as sv from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) having sv is not null --- !query 100 schema +-- !query 78 schema struct --- !query 100 output +-- !query 78 output -15 hours -59 minutes -59.333333 seconds --- !query 101 +-- !query 79 SELECT i, avg(cast(v as interval)) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM VALUES (1,'1 seconds'), (1,'2 seconds'), (2,NULL), (2,NULL) t(i,v) --- !query 101 schema +-- !query 79 schema struct --- !query 101 output +-- !query 79 output 1 1.5 seconds 1 2 seconds 2 NULL 2 NULL --- !query 102 +-- !query 80 create temporary view interval_arithmetic as select CAST(dateval AS date), CAST(tsval AS timestamp) from values ('2012-01-01', '2012-01-01') as interval_arithmetic(dateval, tsval) --- !query 102 schema +-- !query 80 schema struct<> --- !query 102 output +-- !query 80 output --- !query 103 +-- !query 81 select dateval, dateval - interval '2-2' year to month, @@ -988,13 +810,13 @@ select - interval '2-2' year to month + dateval, interval '2-2' year to month + dateval from interval_arithmetic --- !query 103 schema +-- !query 81 schema struct --- !query 103 output +-- !query 81 output 2012-01-01 2009-11-01 2014-03-01 2014-03-01 2009-11-01 2009-11-01 2014-03-01 --- !query 104 +-- !query 82 select tsval, tsval - interval '2-2' year to month, @@ -1004,24 +826,24 @@ select - interval '2-2' year to month + tsval, interval '2-2' year to month + tsval from interval_arithmetic --- !query 104 schema +-- !query 82 schema struct --- !query 104 output +-- !query 82 output 2012-01-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 2014-03-01 00:00:00 2009-11-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 --- !query 105 +-- !query 83 select interval '2-2' year to month + interval '3-3' year to month, interval '2-2' year to month - interval '3-3' year to month from interval_arithmetic --- !query 105 schema +-- !query 83 schema struct<(INTERVAL '2 years 2 months' + INTERVAL '3 years 3 months'):interval,(INTERVAL '2 years 2 months' - INTERVAL '3 years 3 months'):interval> --- !query 105 output +-- !query 83 output 5 years 5 months -1 years -1 months --- !query 106 +-- !query 84 select dateval, dateval - interval '99 11:22:33.123456789' day to second, @@ -1031,13 +853,13 @@ select -interval '99 11:22:33.123456789' day to second + dateval, interval '99 11:22:33.123456789' day to second + dateval from interval_arithmetic --- !query 106 schema +-- !query 84 schema struct --- !query 106 output +-- !query 84 output 2012-01-01 2011-09-23 2012-04-09 2012-04-09 2011-09-23 2011-09-23 2012-04-09 --- !query 107 +-- !query 85 select tsval, tsval - interval '99 11:22:33.123456789' day to second, @@ -1047,100 +869,100 @@ select -interval '99 11:22:33.123456789' day to second + tsval, interval '99 11:22:33.123456789' day to second + tsval from interval_arithmetic --- !query 107 schema +-- !query 85 schema struct --- !query 107 output +-- !query 85 output 2012-01-01 00:00:00 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 2012-04-09 11:22:33.123456 2011-09-23 12:37:26.876544 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 --- !query 108 +-- !query 86 select interval '99 11:22:33.123456789' day to second + interval '10 9:8:7.123456789' day to second, interval '99 11:22:33.123456789' day to second - interval '10 9:8:7.123456789' day to second from interval_arithmetic --- !query 108 schema +-- !query 86 schema struct<(INTERVAL '99 days 11 hours 22 minutes 33.123456 seconds' + INTERVAL '10 days 9 hours 8 minutes 7.123456 seconds'):interval,(INTERVAL '99 days 11 hours 22 minutes 33.123456 seconds' - INTERVAL '10 days 9 hours 8 minutes 7.123456 seconds'):interval> --- !query 108 output +-- !query 86 output 109 days 20 hours 30 minutes 40.246912 seconds 89 days 2 hours 14 minutes 26 seconds --- !query 109 +-- !query 87 select interval '\t interval 1 day' --- !query 109 schema +-- !query 87 schema struct --- !query 109 output +-- !query 87 output 1 days --- !query 110 +-- !query 88 select interval 'interval \t 1\tday' --- !query 110 schema +-- !query 88 schema struct --- !query 110 output +-- !query 88 output 1 days --- !query 111 +-- !query 89 select interval 'interval\t1\tday' --- !query 111 schema +-- !query 89 schema struct --- !query 111 output +-- !query 89 output 1 days --- !query 112 +-- !query 90 select interval '1\t' day --- !query 112 schema +-- !query 90 schema struct --- !query 112 output +-- !query 90 output 1 days --- !query 113 +-- !query 91 select interval '1 ' day --- !query 113 schema +-- !query 91 schema struct --- !query 113 output +-- !query 91 output 1 days --- !query 114 +-- !query 92 select -(a) from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 114 schema +-- !query 92 schema struct<(- a):interval> --- !query 114 output +-- !query 92 output -178956970 years -8 months --- !query 115 +-- !query 93 select a - b from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 115 schema +-- !query 93 schema struct<(a - b):interval> --- !query 115 output +-- !query 93 output 1 months --- !query 116 +-- !query 94 select b + interval '1 month' from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 116 schema +-- !query 94 schema struct<(b + INTERVAL '1 months'):interval> --- !query 116 output +-- !query 94 output -178956970 years -8 months --- !query 117 +-- !query 95 select a * 1.1 from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 117 schema +-- !query 95 schema struct<> --- !query 117 output +-- !query 95 output java.lang.ArithmeticException integer overflow --- !query 118 +-- !query 96 select a / 0.5 from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) --- !query 118 schema +-- !query 96 schema struct<> --- !query 118 output +-- !query 96 output java.lang.ArithmeticException integer overflow diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala index 8ce87742a7..dc1767a685 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala @@ -971,24 +971,4 @@ class DataFrameAggregateSuite extends QueryTest Row(3, new CalendarInterval(0, 3, 0)) :: Nil) assert(find(df3.queryExecution.executedPlan)(_.isInstanceOf[HashAggregateExec]).isDefined) } - - test("Dataset agg functions support calendar intervals") { - val df1 = Seq((1, "1 day"), (2, "2 day"), (3, "3 day"), (3, null)).toDF("a", "b") - val df2 = df1.select($"a", $"b" cast CalendarIntervalType).groupBy($"a" % 2) - checkAnswer(df2.sum("b"), - Row(0, new CalendarInterval(0, 2, 0)) :: - Row(1, new CalendarInterval(0, 4, 0)) :: Nil) - checkAnswer(df2.avg("b"), - Row(0, new CalendarInterval(0, 2, 0)) :: - Row(1, new CalendarInterval(0, 2, 0)) :: Nil) - checkAnswer(df2.mean("b"), - Row(0, new CalendarInterval(0, 2, 0)) :: - Row(1, new CalendarInterval(0, 2, 0)) :: Nil) - checkAnswer(df2.max("b"), - Row(0, new CalendarInterval(0, 2, 0)) :: - Row(1, new CalendarInterval(0, 3, 0)) :: Nil) - checkAnswer(df2.min("b"), - Row(0, new CalendarInterval(0, 2, 0)) :: - Row(1, new CalendarInterval(0, 1, 0)) :: Nil) - } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnStatsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnStatsSuite.scala index eb76316f48..847e0ec4f3 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnStatsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnStatsSuite.scala @@ -31,7 +31,7 @@ class ColumnStatsSuite extends SparkFunSuite { testColumnStats(classOf[DoubleColumnStats], DOUBLE, Array(Double.MaxValue, Double.MinValue, 0)) testColumnStats(classOf[StringColumnStats], STRING, Array(null, null, 0)) testDecimalColumnStats(Array(null, null, 0)) - testIntervalColumnStats(Array(CalendarInterval.MAX_VALUE, CalendarInterval.MIN_VALUE, 0)) + testIntervalColumnStats(Array(null, null, 0)) def testColumnStats[T <: AtomicType, U <: ColumnStats]( columnStatsClass: Class[U], @@ -126,12 +126,8 @@ class ColumnStatsSuite extends SparkFunSuite { val rows = Seq.fill(10)(makeRandomRow(columnType)) ++ Seq.fill(10)(makeNullRow(1)) rows.foreach(columnStats.gatherStats(_, 0)) - val values = rows.take(10).map(_.get(0, columnType.dataType)) - val ordering = CalendarIntervalType.ordering.asInstanceOf[Ordering[Any]] val stats = columnStats.collectedStatistics - assertResult(values.min(ordering), "Wrong lower bound")(stats(0)) - assertResult(values.max(ordering), "Wrong upper bound")(stats(1)) assertResult(10, "Wrong null count")(stats(2)) assertResult(20, "Wrong row count")(stats(3)) assertResult(stats(4), "Wrong size in bytes") { diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala index 56d5bfbb96..b25aa6e308 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/ColumnTypeSuite.scala @@ -78,7 +78,7 @@ class ColumnTypeSuite extends SparkFunSuite with Logging { checkActualSize(ARRAY_TYPE, Array[Any](1), 4 + 8 + 8 + 8) checkActualSize(MAP_TYPE, Map(1 -> "a"), 4 + (8 + 8 + 8 + 8) + (8 + 8 + 8 + 8)) checkActualSize(STRUCT_TYPE, Row("hello"), 28) - checkActualSize(CALENDAR_INTERVAL, CalendarInterval.MAX_VALUE, 4 + 4 + 8) + checkActualSize(CALENDAR_INTERVAL, new CalendarInterval(0, 0, 0), 4 + 4 + 8) } testNativeColumnType(BOOLEAN)