@@ -21,7 +21,7 @@ import scala.language.implicitConversions
21
21
22
22
import org .apache .spark .SparkFunSuite
23
23
import org .apache .spark .sql .catalyst .util .DateTimeConstants ._
24
- import org .apache .spark .sql .catalyst .util .IntervalUtils .stringToInterval
24
+ import org .apache .spark .sql .catalyst .util .IntervalUtils .{ safeStringToInterval , stringToInterval }
25
25
import org .apache .spark .sql .internal .SQLConf
26
26
import org .apache .spark .sql .types .Decimal
27
27
import org .apache .spark .unsafe .types .{CalendarInterval , UTF8String }
@@ -198,19 +198,15 @@ class IntervalExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
198
198
}
199
199
200
200
test(" multiply" ) {
201
- def check (
202
- interval : String ,
203
- num : Double ,
204
- expected : String ,
205
- checkException : Boolean = false ): Unit = {
201
+ def check (interval : String , num : Double , expected : String ): Unit = {
202
+ val expr = MultiplyInterval (Literal (stringToInterval(interval)), Literal (num))
203
+ val expectedRes = safeStringToInterval(expected)
206
204
Seq (" true" , " false" ).foreach { v =>
207
205
withSQLConf(SQLConf .ANSI_ENABLED .key -> v) {
208
- if (checkException) {
209
- checkExceptionInExpression[ArithmeticException ](
210
- MultiplyInterval (Literal (stringToInterval(interval)), Literal (num)), expected)
206
+ if (expectedRes == null ) {
207
+ checkExceptionInExpression[ArithmeticException ](expr, expected)
211
208
} else {
212
- checkEvaluation(MultiplyInterval (Literal (stringToInterval(interval)), Literal (num)),
213
- if (expected == null ) null else stringToInterval(expected))
209
+ checkEvaluation(expr, expectedRes)
214
210
}
215
211
}
216
212
}
@@ -224,23 +220,19 @@ class IntervalExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
224
220
check(" -100 years -1 millisecond" , 0.5 , " -50 years -500 microseconds" )
225
221
check(" 2 months 4 seconds" , - 0.5 , " -1 months -2 seconds" )
226
222
check(" 1 month 2 microseconds" , 1.5 , " 1 months 15 days 3 microseconds" )
227
- check(" 2 months" , Int .MaxValue , " integer overflow" , checkException = true )
223
+ check(" 2 months" , Int .MaxValue , " integer overflow" )
228
224
}
229
225
230
226
test(" divide" ) {
231
- def check (
232
- interval : String ,
233
- num : Double ,
234
- expected : String ,
235
- checkException : Boolean = false ): Unit = {
227
+ def check (interval : String , num : Double , expected : String ): Unit = {
228
+ val expr = DivideInterval (Literal (stringToInterval(interval)), Literal (num))
229
+ val expectedRes = safeStringToInterval(expected)
236
230
Seq (" true" , " false" ).foreach { v =>
237
231
withSQLConf(SQLConf .ANSI_ENABLED .key -> v) {
238
- if (checkException) {
239
- checkExceptionInExpression[ArithmeticException ](
240
- DivideInterval (Literal (stringToInterval(interval)), Literal (num)), expected)
232
+ if (expectedRes == null ) {
233
+ checkExceptionInExpression[ArithmeticException ](expr, expected)
241
234
} else {
242
- checkEvaluation(DivideInterval (Literal (stringToInterval(interval)), Literal (num)),
243
- if (expected == null ) null else stringToInterval(expected))
235
+ checkEvaluation(expr, expectedRes)
244
236
}
245
237
}
246
238
}
@@ -253,8 +245,8 @@ class IntervalExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
253
245
check(" 2 years -8 seconds" , 0.5 , " 4 years -16 seconds" )
254
246
check(" -1 month 2 microseconds" , - 0.25 , " 4 months -8 microseconds" )
255
247
check(" 1 month 3 microsecond" , 1.5 , " 20 days 2 microseconds" )
256
- check(" 1 second" , 0 , " divide by zero" , checkException = true )
257
- check(s " ${Int .MaxValue } months " , 0.9 , " integer overflow" , checkException = true )
248
+ check(" 1 second" , 0 , " divide by zero" )
249
+ check(s " ${Int .MaxValue } months " , 0.9 , " integer overflow" )
258
250
}
259
251
260
252
test(" make interval" ) {
0 commit comments