Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(Literal.create(null, DateType), null)
checkEvaluation(Literal.create(null, TimestampType), null)
checkEvaluation(Literal.create(null, CalendarIntervalType), null)
checkEvaluation(Literal.create(null, YearMonthIntervalType), null)
checkEvaluation(Literal.create(null, DayTimeIntervalType), null)
checkEvaluation(Literal.create(null, ArrayType(ByteType, true)), null)
checkEvaluation(Literal.create(null, ArrayType(StringType, true)), null)
checkEvaluation(Literal.create(null, MapType(StringType, IntegerType)), null)
Expand Down Expand Up @@ -77,6 +79,8 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(Literal.default(TimestampType), Instant.ofEpochSecond(0))
}
checkEvaluation(Literal.default(CalendarIntervalType), new CalendarInterval(0, 0, 0L))
checkEvaluation(Literal.default(YearMonthIntervalType), 0)
checkEvaluation(Literal.default(DayTimeIntervalType), 0L)
checkEvaluation(Literal.default(ArrayType(StringType)), Array())
checkEvaluation(Literal.default(MapType(IntegerType, StringType)), Map())
checkEvaluation(Literal.default(StructType(StructField("a", StringType) :: Nil)), Row(""))
Expand Down Expand Up @@ -188,20 +192,21 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
checkArrayLiteral(Array(1, 2, 3))
checkArrayLiteral(Array("a", "b", "c"))
checkArrayLiteral(Array(1.0, 4.0))
checkArrayLiteral(Array(MICROS_PER_DAY, MICROS_PER_HOUR))
checkArrayLiteral(Array(new CalendarInterval(1, 0, 0), new CalendarInterval(0, 1, 0)))
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't add checks for ANSI intervals because there are separate tests for that in the test suite.

val arr = collection.mutable.WrappedArray.make(Array(1.0, 4.0))
checkEvaluation(Literal(arr), toCatalyst(arr))
}

test("seq") {
def checkSeqLiteral[T: TypeTag](a: Seq[T], elementType: DataType): Unit = {
def checkSeqLiteral[T: TypeTag](a: Seq[T]): Unit = {
checkEvaluation(Literal.create(a), toCatalyst(a))
}
checkSeqLiteral(Seq(1, 2, 3), IntegerType)
checkSeqLiteral(Seq("a", "b", "c"), StringType)
checkSeqLiteral(Seq(1.0, 4.0), DoubleType)
checkSeqLiteral(Seq(MICROS_PER_DAY, MICROS_PER_HOUR),
CalendarIntervalType)
Copy link
Member

Choose a reason for hiding this comment

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

Could you mention this removal (replacement) in the PR description, @MaxGekk ?

Copy link
Member Author

@MaxGekk MaxGekk Apr 18, 2021

Choose a reason for hiding this comment

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

@maropu (because you added the test) I removed it because this doesn't check CalendarIntervalType. elementType is not used in checkSeqLiteral(), and this checkSeqLiteral(Seq(MICROS_PER_DAY, MICROS_PER_HOUR), CalendarIntervalType) checks the Long type, actually.

I think of to improve the test by removing elementType at all, and check CalendarIntervalType via CalendarInterval values.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

checkSeqLiteral(Seq(1, 2, 3))
checkSeqLiteral(Seq("a", "b", "c"))
checkSeqLiteral(Seq(1.0, 4.0))
checkSeqLiteral(Seq(new CalendarInterval(1, 0, 0), new CalendarInterval(0, 1, 0)))
checkSeqLiteral(Seq(Period.ZERO, Period.ofMonths(1)))
checkSeqLiteral(Seq(Duration.ZERO, Duration.ofDays(1)))
}

test("map") {
Expand All @@ -210,6 +215,7 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
}
checkMapLiteral(Map("a" -> 1, "b" -> 2, "c" -> 3))
checkMapLiteral(Map("1" -> 1.0, "2" -> 2.0, "3" -> 3.0))
checkMapLiteral(Map(Period.ofMonths(1) -> Duration.ZERO))
assert(Literal.create(Map("a" -> 1)).toString === "map(keys: [a], values: [1])")
}

Expand All @@ -220,6 +226,7 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
checkStructLiteral((1, 3.0, "abcde"))
checkStructLiteral(("de", 1, 2.0f))
checkStructLiteral((1, ("fgh", 3.0)))
checkStructLiteral((Period.ZERO, ("abc", Duration.ofDays(1))))
}

test("unsupported types (map and struct) in Literal.apply") {
Expand Down Expand Up @@ -337,6 +344,8 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
Literal.create(Array(1.toByte, 2.toByte, 3.toByte), BinaryType))
assert(Literal(Array("1", "2", "3")) ==
Literal.create(Array("1", "2", "3"), ArrayType(StringType)))
assert(Literal(Array(Period.ofMonths(1))) ==
Literal.create(Array(Period.ofMonths(1)), ArrayType(YearMonthIntervalType)))
}

test("SPARK-34342: Date/Timestamp toString") {
Expand Down