@@ -26,6 +26,7 @@ import za.co.absa.standardization.types.{CommonTypeDefaults, TypeDefaults}
2626import za .co .absa .standardization .udf .UDFLibrary
2727import za .co .absa .standardization .{LoggerTestBase , Standardization , StandardizationErrorMessage }
2828import za .co .absa .spark .commons .implicits .DataFrameImplicits .DataFrameEnhancements
29+ import za .co .absa .standardization .schema .MetadataKeys
2930
3031class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBase with LoggerTestBase {
3132 import spark .implicits ._
@@ -53,7 +54,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
5354 )
5455 val desiredSchema = StructType (Seq (
5556 StructField (fieldName, DateType , nullable = false ,
56- new MetadataBuilder ().putString(" pattern " , " epoch" ).build)
57+ new MetadataBuilder ().putString(MetadataKeys . Pattern , " epoch" ).build)
5758 ))
5859 val exp = Seq (
5960 DateRow (Date .valueOf(" 1970-01-01" )),
@@ -75,18 +76,28 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
7576 val seq = Seq (
7677 0L ,
7778 86400000 ,
79+ - 1 ,
7880 978307199999L ,
79- 1563288103123L
81+ 1563288103123L ,
82+ - 2
8083 )
8184 val desiredSchema = StructType (Seq (
8285 StructField (fieldName, DateType , nullable = false ,
83- new MetadataBuilder ().putString(" pattern" , " epochmilli" ).build)
86+ new MetadataBuilder ()
87+ .putString(MetadataKeys .Pattern , " epochmilli" )
88+ .putString(MetadataKeys .PlusInfinitySymbol , " -1" )
89+ .putString(MetadataKeys .PlusInfinityValue , " 1563278222094" )
90+ .putString(MetadataKeys .MinusInfinitySymbol , " -2" )
91+ .putString(MetadataKeys .MinusInfinityValue , " 0" )
92+ .build)
8493 ))
8594 val exp = Seq (
8695 DateRow (Date .valueOf(" 1970-01-01" )),
8796 DateRow (Date .valueOf(" 1970-01-02" )),
97+ DateRow (Date .valueOf(" 2019-07-16" )),
8898 DateRow (Date .valueOf(" 2000-12-31" )),
89- DateRow (Date .valueOf(" 2019-07-16" ))
99+ DateRow (Date .valueOf(" 2019-07-16" )),
100+ DateRow (Date .valueOf(" 1970-01-01" ))
90101 )
91102
92103 val src = seq.toDF(fieldName)
@@ -106,7 +117,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
106117 )
107118 val desiredSchema = StructType (Seq (
108119 StructField (fieldName, DateType , nullable = false ,
109- new MetadataBuilder ().putString(" pattern " , " epochmicro" ).build)
120+ new MetadataBuilder ().putString(MetadataKeys . Pattern , " epochmicro" ).build)
110121 ))
111122 val exp = Seq (
112123 DateRow (Date .valueOf(" 1970-01-01" )),
@@ -132,7 +143,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
132143 )
133144 val desiredSchema = StructType (Seq (
134145 StructField (fieldName, DateType , nullable = false ,
135- new MetadataBuilder ().putString(" pattern " , " epochnano" ).build)
146+ new MetadataBuilder ().putString(MetadataKeys . Pattern , " epochnano" ).build)
136147 ))
137148 val exp = Seq (
138149 DateRow (Date .valueOf(" 1970-01-01" )),
@@ -150,25 +161,31 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
150161 }
151162
152163 test(" simple date pattern" ) {
153- val seq = Seq (
164+ val seq : Seq [ String ] = Seq (
154165 " 1970/01/01" ,
155166 " 1970/02/01" ,
156167 " 2000/31/12" ,
157168 " 2019/16/07" ,
158169 " 1970-02-02" ,
159- " crash"
170+ " crash" ,
171+ " Alfa"
160172 )
161173 val desiredSchema = StructType (Seq (
162174 StructField (fieldName, DateType , nullable = false ,
163- new MetadataBuilder ().putString(" pattern" , " yyyy/dd/MM" ).build)
175+ new MetadataBuilder ()
176+ .putString(MetadataKeys .Pattern , " yyyy/dd/MM" )
177+ .putString(MetadataKeys .PlusInfinitySymbol , " Alfa" )
178+ .putString(MetadataKeys .PlusInfinityValue , " 1970/02/01" )
179+ .build)
164180 ))
165- val exp = Seq (
181+ val exp : Seq [ DateRow ] = Seq (
166182 DateRow (Date .valueOf(" 1970-01-01" )),
167183 DateRow (Date .valueOf(" 1970-01-02" )),
168184 DateRow (Date .valueOf(" 2000-12-31" )),
169185 DateRow (Date .valueOf(" 2019-07-16" )),
170186 DateRow (Date .valueOf(" 1970-01-01" ), Seq (StandardizationErrorMessage .stdCastErr(fieldName, " 1970-02-02" , " string" , " date" , Some (" yyyy/dd/MM" )))),
171- DateRow (Date .valueOf(" 1970-01-01" ), Seq (StandardizationErrorMessage .stdCastErr(fieldName, " crash" , " string" , " date" , Some (" yyyy/dd/MM" ))))
187+ DateRow (Date .valueOf(" 1970-01-01" ), Seq (StandardizationErrorMessage .stdCastErr(fieldName, " crash" , " string" , " date" , Some (" yyyy/dd/MM" )))),
188+ DateRow (Date .valueOf(" 1970-01-02" ))
172189 )
173190
174191 val src = seq.toDF(fieldName)
@@ -190,7 +207,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
190207 )
191208 val desiredSchema = StructType (Seq (
192209 StructField (fieldName, DateType , nullable = false ,
193- new MetadataBuilder ().putString(" pattern " , " HH-mm-ss dd.MM.yyyy ZZZ" ).build)
210+ new MetadataBuilder ().putString(MetadataKeys . Pattern , " HH-mm-ss dd.MM.yyyy ZZZ" ).build)
194211 ))
195212 val exp = Seq (
196213 DateRow (Date .valueOf(" 1970-01-01" )),
@@ -221,7 +238,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
221238 )
222239 val desiredSchema = StructType (Seq (
223240 StructField (fieldName, DateType , nullable = false ,
224- new MetadataBuilder ().putString(" pattern " , " HH:mm:ss(SSSnnnnnn) dd+MM+yyyy XXX" ).build)
241+ new MetadataBuilder ().putString(MetadataKeys . Pattern , " HH:mm:ss(SSSnnnnnn) dd+MM+yyyy XXX" ).build)
225242 ))
226243 val exp = Seq (
227244 DateRow (Date .valueOf(" 1970-01-01" )),
@@ -252,7 +269,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
252269 val desiredSchema = StructType (Seq (
253270 StructField (fieldName, DateType , nullable = false ,
254271 new MetadataBuilder ()
255- .putString(" pattern " , " yyyy/dd/MM" )
272+ .putString(MetadataKeys . Pattern , " yyyy/dd/MM" )
256273 .putString(" timezone" , " EST" )
257274 .build)
258275 ))
@@ -286,7 +303,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
286303 val desiredSchema = StructType (Seq (
287304 StructField (fieldName, DateType , nullable = false ,
288305 new MetadataBuilder ()
289- .putString(" pattern " , " yyyy/dd/MM" )
306+ .putString(MetadataKeys . Pattern , " yyyy/dd/MM" )
290307 .putString(" timezone" , " Africa/Johannesburg" )
291308 .build)
292309 ))
@@ -319,7 +336,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
319336 )
320337 val desiredSchema = StructType (Seq (
321338 StructField (fieldName, DateType , nullable = false ,
322- new MetadataBuilder ().putString(" pattern " , " MMMM d 'of' yyyy" ).build)
339+ new MetadataBuilder ().putString(MetadataKeys . Pattern , " MMMM d 'of' yyyy" ).build)
323340 ))
324341 val exp = Seq (
325342 DateRow (Date .valueOf(" 1970-01-01" )),
@@ -351,7 +368,7 @@ class StandardizationInterpreter_DateSuite extends AnyFunSuite with SparkTestBas
351368 )
352369 val desiredSchema = StructType (Seq (
353370 StructField (fieldName, DateType , nullable = false ,
354- new MetadataBuilder ().putString(" pattern " , " yyyy/MM/dd 'insignificant' iiiiii" ).build)
371+ new MetadataBuilder ().putString(MetadataKeys . Pattern , " yyyy/MM/dd 'insignificant' iiiiii" ).build)
355372 ))
356373 val exp = Seq (
357374 DateRow (Date .valueOf(" 1970-01-01" )),
0 commit comments