@@ -62,6 +62,33 @@ private Literal timestampLiteral(String date) {
62
62
return (Literal ) exp ;
63
63
}
64
64
65
+ private String buildDate () {
66
+ StringBuilder sb = new StringBuilder ();
67
+ int length = randomIntBetween (4 , 9 );
68
+
69
+ if (randomBoolean ()) {
70
+ sb .append ('-' );
71
+ } else {
72
+ if (length > 4 ) {
73
+ sb .append ('-' );
74
+ }
75
+ }
76
+
77
+ for (int i = 1 ; i <= length ; i ++) {
78
+ sb .append (i );
79
+ }
80
+ sb .append ("-05-10" );
81
+ return sb .toString ();
82
+ }
83
+
84
+ private String buildSecsAndFractional () {
85
+ if (randomBoolean ()) {
86
+ return ":55" + randomFrom ("" , ".1" , ".12" , ".123" , ".1234" , ".12345" , ".123456" ,
87
+ ".1234567" , ".12345678" , ".123456789" );
88
+ }
89
+ return "" ;
90
+ }
91
+
65
92
private Literal guidLiteral (String guid ) {
66
93
Expression exp = parser .createExpression (buildExpression ("guid" , "'%s'" , guid ));
67
94
assertThat (exp , instanceOf (Expression .class ));
@@ -185,7 +212,7 @@ public void testFunctionWithFunctionWithArgAndParams() {
185
212
}
186
213
187
214
public void testDateLiteral () {
188
- Literal l = dateLiteral ("2012-01-01" );
215
+ Literal l = dateLiteral (buildDate () );
189
216
assertThat (l .dataType (), is (DATE ));
190
217
}
191
218
@@ -197,7 +224,7 @@ public void testDateLiteralValidation() {
197
224
}
198
225
199
226
public void testTimeLiteral () {
200
- Literal l = timeLiteral ("12:23:56" );
227
+ Literal l = timeLiteral ("12:23" + buildSecsAndFractional () );
201
228
assertThat (l .dataType (), is (TIME ));
202
229
}
203
230
@@ -209,14 +236,27 @@ public void testTimeLiteralValidation() {
209
236
}
210
237
211
238
public void testTimestampLiteral () {
212
- Literal l = timestampLiteral ("2012-01-01 10:01:02.3456" );
239
+ Literal l = timestampLiteral (buildDate () + " 10:20" + buildSecsAndFractional ());
240
+ assertThat (l .dataType (), is (DATETIME ));
241
+ l = timestampLiteral (buildDate () + "T11:22" + buildSecsAndFractional ());
213
242
assertThat (l .dataType (), is (DATETIME ));
214
243
}
215
244
216
245
public void testTimestampLiteralValidation () {
217
- ParsingException ex = expectThrows (ParsingException .class , () -> timestampLiteral ("2012-01-01T10:01:02.3456" ));
246
+ String date = buildDate ();
247
+ ParsingException ex = expectThrows (ParsingException .class , () -> timestampLiteral (date + "_AB 10:01:02.3456" ));
248
+ assertEquals (
249
+ "line 1:2: Invalid timestamp received; Text '" + date + "_AB 10:01:02.3456' could not be parsed at index " +
250
+ date .length (),
251
+ ex .getMessage ());
252
+ ex = expectThrows (ParsingException .class , () -> timestampLiteral ("20120101_AB 10:01:02.3456" ));
253
+ assertEquals (
254
+ "line 1:2: Invalid timestamp received; Text '20120101_AB 10:01:02.3456' could not be parsed at index 0" ,
255
+ ex .getMessage ());
256
+
257
+ ex = expectThrows (ParsingException .class , () -> timestampLiteral (date ));
218
258
assertEquals (
219
- "line 1:2: Invalid timestamp received; Text '2012-01-01T10:01:02.3456 ' could not be parsed at index 10" ,
259
+ "line 1:2: Invalid timestamp received; Text '" + date + " ' could not be parsed at index " + date . length () ,
220
260
ex .getMessage ());
221
261
}
222
262
0 commit comments