@@ -19,7 +19,6 @@ package org.apache.spark.sql.catalyst.csv
19
19
20
20
import java .math .BigDecimal
21
21
import java .text .{DecimalFormat , DecimalFormatSymbols }
22
- import java .time .ZoneOffset
23
22
import java .util .{Locale , TimeZone }
24
23
25
24
import org .apache .commons .lang3 .time .FastDateFormat
@@ -44,7 +43,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
44
43
45
44
stringValues.zip(decimalValues).foreach { case (strVal, decimalVal) =>
46
45
val decimalValue = new BigDecimal (decimalVal.toString)
47
- val options = new CSVOptions (Map .empty[String , String ], false , " GMT " )
46
+ val options = new CSVOptions (Map .empty[String , String ], false , " UTC " )
48
47
val parser = new UnivocityParser (StructType (Seq .empty), options)
49
48
assert(parser.makeConverter(" _1" , decimalType).apply(strVal) ===
50
49
Decimal (decimalValue, decimalType.precision, decimalType.scale))
@@ -58,22 +57,22 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
58
57
// Nullable field with nullValue option.
59
58
types.foreach { t =>
60
59
// Tests that a custom nullValue.
61
- val nullValueOptions = new CSVOptions (Map (" nullValue" -> " -" ), false , " GMT " )
60
+ val nullValueOptions = new CSVOptions (Map (" nullValue" -> " -" ), false , " UTC " )
62
61
var parser = new UnivocityParser (StructType (Seq .empty), nullValueOptions)
63
62
val converter = parser.makeConverter(" _1" , t, nullable = true )
64
63
assertNull(converter.apply(" -" ))
65
64
assertNull(converter.apply(null ))
66
65
67
66
// Tests that the default nullValue is empty string.
68
- val options = new CSVOptions (Map .empty[String , String ], false , " GMT " )
67
+ val options = new CSVOptions (Map .empty[String , String ], false , " UTC " )
69
68
parser = new UnivocityParser (StructType (Seq .empty), options)
70
69
assertNull(parser.makeConverter(" _1" , t, nullable = true ).apply(" " ))
71
70
}
72
71
73
72
// Not nullable field with nullValue option.
74
73
types.foreach { t =>
75
74
// Casts a null to not nullable field should throw an exception.
76
- val options = new CSVOptions (Map (" nullValue" -> " -" ), false , " GMT " )
75
+ val options = new CSVOptions (Map (" nullValue" -> " -" ), false , " UTC " )
77
76
val parser = new UnivocityParser (StructType (Seq .empty), options)
78
77
val converter = parser.makeConverter(" _1" , t, nullable = false )
79
78
var message = intercept[RuntimeException ] {
@@ -89,15 +88,15 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
89
88
// If nullValue is different with empty string, then, empty string should not be casted into
90
89
// null.
91
90
Seq (true , false ).foreach { b =>
92
- val options = new CSVOptions (Map (" nullValue" -> " null" ), false , " GMT " )
91
+ val options = new CSVOptions (Map (" nullValue" -> " null" ), false , " UTC " )
93
92
val parser = new UnivocityParser (StructType (Seq .empty), options)
94
93
val converter = parser.makeConverter(" _1" , StringType , nullable = b)
95
94
assert(converter.apply(" " ) == UTF8String .fromString(" " ))
96
95
}
97
96
}
98
97
99
98
test(" Throws exception for empty string with non null type" ) {
100
- val options = new CSVOptions (Map .empty[String , String ], false , " GMT " )
99
+ val options = new CSVOptions (Map .empty[String , String ], false , " UTC " )
101
100
val parser = new UnivocityParser (StructType (Seq .empty), options)
102
101
val exception = intercept[RuntimeException ]{
103
102
parser.makeConverter(" _1" , IntegerType , nullable = false ).apply(" " )
@@ -106,7 +105,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
106
105
}
107
106
108
107
test(" Types are cast correctly" ) {
109
- val options = new CSVOptions (Map .empty[String , String ], false , " GMT " )
108
+ val options = new CSVOptions (Map .empty[String , String ], false , " UTC " )
110
109
var parser = new UnivocityParser (StructType (Seq .empty), options)
111
110
assert(parser.makeConverter(" _1" , ByteType ).apply(" 10" ) == 10 )
112
111
assert(parser.makeConverter(" _1" , ShortType ).apply(" 10" ) == 10 )
@@ -117,7 +116,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
117
116
assert(parser.makeConverter(" _1" , BooleanType ).apply(" true" ) == true )
118
117
119
118
var timestampsOptions =
120
- new CSVOptions (Map (" timestampFormat" -> " dd/MM/yyyy HH:mm" ), false , " GMT " )
119
+ new CSVOptions (Map (" timestampFormat" -> " dd/MM/yyyy HH:mm" ), false , " UTC " )
121
120
parser = new UnivocityParser (StructType (Seq .empty), timestampsOptions)
122
121
val customTimestamp = " 31/01/2015 00:00"
123
122
var format = FastDateFormat .getInstance(
@@ -130,7 +129,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
130
129
assert(castedTimestamp == expectedTime * 1000L )
131
130
132
131
val customDate = " 31/01/2015"
133
- val dateOptions = new CSVOptions (Map (" dateFormat" -> " dd/MM/yyyy" ), false , " GMT " )
132
+ val dateOptions = new CSVOptions (Map (" dateFormat" -> " dd/MM/yyyy" ), false , " UTC " )
134
133
parser = new UnivocityParser (StructType (Seq .empty), dateOptions)
135
134
format = FastDateFormat .getInstance(
136
135
dateOptions.dateFormat,
@@ -139,7 +138,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
139
138
val expectedDate = format.parse(customDate).getTime
140
139
val castedDate = parser.makeConverter(" _1" , DateType , nullable = true )
141
140
.apply(customDate)
142
- assert(castedDate == DateTimeUtils .millisToDays(expectedDate, ZoneOffset . UTC ))
141
+ assert(castedDate == DateTimeUtils .millisToDays(expectedDate, UTC ))
143
142
144
143
val timestamp = " 2015-01-01 00:00:00"
145
144
timestampsOptions = new CSVOptions (Map (
@@ -154,7 +153,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
154
153
}
155
154
156
155
test(" Throws exception for casting an invalid string to Float and Double Types" ) {
157
- val options = new CSVOptions (Map .empty[String , String ], false , " GMT " )
156
+ val options = new CSVOptions (Map .empty[String , String ], false , " UTC " )
158
157
val parser = new UnivocityParser (StructType (Seq .empty), options)
159
158
val types = Seq (DoubleType , FloatType )
160
159
val input = Seq (" 10u000" , " abc" , " 1 2/3" )
@@ -169,7 +168,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
169
168
}
170
169
171
170
test(" Float NaN values are parsed correctly" ) {
172
- val options = new CSVOptions (Map (" nanValue" -> " nn" ), false , " GMT " )
171
+ val options = new CSVOptions (Map (" nanValue" -> " nn" ), false , " UTC " )
173
172
val parser = new UnivocityParser (StructType (Seq .empty), options)
174
173
val floatVal : Float = parser.makeConverter(
175
174
" _1" , FloatType , nullable = true ).apply(" nn" ).asInstanceOf [Float ]
@@ -180,7 +179,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
180
179
}
181
180
182
181
test(" Double NaN values are parsed correctly" ) {
183
- val options = new CSVOptions (Map (" nanValue" -> " -" ), false , " GMT " )
182
+ val options = new CSVOptions (Map (" nanValue" -> " -" ), false , " UTC " )
184
183
val parser = new UnivocityParser (StructType (Seq .empty), options)
185
184
val doubleVal : Double = parser.makeConverter(
186
185
" _1" , DoubleType , nullable = true ).apply(" -" ).asInstanceOf [Double ]
@@ -189,14 +188,14 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
189
188
}
190
189
191
190
test(" Float infinite values can be parsed" ) {
192
- val negativeInfOptions = new CSVOptions (Map (" negativeInf" -> " max" ), false , " GMT " )
191
+ val negativeInfOptions = new CSVOptions (Map (" negativeInf" -> " max" ), false , " UTC " )
193
192
var parser = new UnivocityParser (StructType (Seq .empty), negativeInfOptions)
194
193
val floatVal1 = parser.makeConverter(
195
194
" _1" , FloatType , nullable = true ).apply(" max" ).asInstanceOf [Float ]
196
195
197
196
assert(floatVal1 == Float .NegativeInfinity )
198
197
199
- val positiveInfOptions = new CSVOptions (Map (" positiveInf" -> " max" ), false , " GMT " )
198
+ val positiveInfOptions = new CSVOptions (Map (" positiveInf" -> " max" ), false , " UTC " )
200
199
parser = new UnivocityParser (StructType (Seq .empty), positiveInfOptions)
201
200
val floatVal2 = parser.makeConverter(
202
201
" _1" , FloatType , nullable = true ).apply(" max" ).asInstanceOf [Float ]
@@ -205,14 +204,14 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
205
204
}
206
205
207
206
test(" Double infinite values can be parsed" ) {
208
- val negativeInfOptions = new CSVOptions (Map (" negativeInf" -> " max" ), false , " GMT " )
207
+ val negativeInfOptions = new CSVOptions (Map (" negativeInf" -> " max" ), false , " UTC " )
209
208
var parser = new UnivocityParser (StructType (Seq .empty), negativeInfOptions)
210
209
val doubleVal1 = parser.makeConverter(
211
210
" _1" , DoubleType , nullable = true ).apply(" max" ).asInstanceOf [Double ]
212
211
213
212
assert(doubleVal1 == Double .NegativeInfinity )
214
213
215
- val positiveInfOptions = new CSVOptions (Map (" positiveInf" -> " max" ), false , " GMT " )
214
+ val positiveInfOptions = new CSVOptions (Map (" positiveInf" -> " max" ), false , " UTC " )
216
215
parser = new UnivocityParser (StructType (Seq .empty), positiveInfOptions)
217
216
val doubleVal2 = parser.makeConverter(
218
217
" _1" , DoubleType , nullable = true ).apply(" max" ).asInstanceOf [Double ]
@@ -228,7 +227,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
228
227
val df = new DecimalFormat (" " , new DecimalFormatSymbols (Locale .forLanguageTag(langTag)))
229
228
val input = df.format(expected.toBigDecimal)
230
229
231
- val options = new CSVOptions (Map (" locale" -> langTag), false , " GMT " )
230
+ val options = new CSVOptions (Map (" locale" -> langTag), false , " UTC " )
232
231
val parser = new UnivocityParser (new StructType ().add(" d" , decimalType), options)
233
232
234
233
assert(parser.makeConverter(" _1" , decimalType).apply(input) === expected)
@@ -263,7 +262,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
263
262
val input = " name\t 42"
264
263
val expected = UTF8String .fromString(input)
265
264
266
- val options = new CSVOptions (Map .empty[String , String ], false , " GMT " )
265
+ val options = new CSVOptions (Map .empty[String , String ], false , " UTC " )
267
266
val parser = new UnivocityParser (StructType (Seq .empty), options)
268
267
269
268
val convertedValue = parser.makeConverter(" _1" , StringBasedUDT , nullable = false ).apply(input)
@@ -280,7 +279,7 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
280
279
filters : Seq [Filter ],
281
280
expected : Option [InternalRow ]): Unit = {
282
281
Seq (false , true ).foreach { columnPruning =>
283
- val options = new CSVOptions (Map .empty[String , String ], columnPruning, " GMT " )
282
+ val options = new CSVOptions (Map .empty[String , String ], columnPruning, " UTC " )
284
283
val parser = new UnivocityParser (dataSchema, requiredSchema, options, filters)
285
284
val actual = parser.parse(input)
286
285
assert(actual === expected)
@@ -355,8 +354,8 @@ class UnivocityParserSuite extends SparkFunSuite with SQLHelper {
355
354
val options = new CSVOptions (Map .empty[String , String ], false , " UTC" )
356
355
check(new UnivocityParser (StructType (Seq .empty), options))
357
356
358
- val optionsWithPattern =
359
- new CSVOptions ( Map (" timestampFormat" -> " invalid" , " dateFormat" -> " invalid" ), false , " UTC" )
357
+ val optionsWithPattern = new CSVOptions (
358
+ Map (" timestampFormat" -> " invalid" , " dateFormat" -> " invalid" ), false , " UTC" )
360
359
check(new UnivocityParser (StructType (Seq .empty), optionsWithPattern))
361
360
}
362
361
}
0 commit comments