MCPcopy Create free account
hub / github.com/apache/impala / TEST

Function TEST

be/src/runtime/date-test.cc:55–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55TEST(DateTest, ParseDefault) {
56 // Parse with time tokens rejected.
57 const DateValue v1 = ParseValidateDate("2012-01-20", false, 2012, 1, 20);
58 const DateValue v2 = ParseValidateDate("1990-10-20", false, 1990, 10, 20);
59 const DateValue v3 = ParseValidateDate("1990-10-20", false, 1990, 10, 20);
60 // Parse with time tokens accepted.
61 const DateValue v4 = ParseValidateDate("1990-10-20 23:59:59.999999999", true, 1990, 10,
62 20);
63 const DateValue v5 = ParseValidateDate("1990-10-20 00:01:02.9", true, 1990, 10, 20);
64
65 // Test comparison operators.
66 EXPECT_NE(v1, v2);
67 EXPECT_EQ(v2, v3);
68 EXPECT_LT(v2, v1);
69 EXPECT_LE(v2, v1);
70 EXPECT_GT(v1, v2);
71 EXPECT_GE(v2, v3);
72
73 // Time components are not part of the date value
74 EXPECT_EQ(v3, v4);
75 EXPECT_EQ(v3, v5);
76
77 EXPECT_NE(RawValue::GetHashValue(&v1, ColumnType(TYPE_DATE), 0),
78 RawValue::GetHashValue(&v2, ColumnType(TYPE_DATE), 0));
79 EXPECT_EQ(RawValue::GetHashValue(&v3, ColumnType(TYPE_DATE), 0),
80 RawValue::GetHashValue(&v2, ColumnType(TYPE_DATE), 0));
81
82 // 1-digit months and days are ok in date string.
83 ParseValidateDate("2012-1-20", false, 2012, 1, 20);
84 ParseValidateDate("2012-9-8", false, 2012, 9, 8);
85 // 1-digit hours/minutes/seconds are ok if time components are accepted.
86 ParseValidateDate("2012-09-8 01:1:2.9", true, 2012, 9, 8);
87 ParseValidateDate("2012-9-8 1:01:02", true, 2012, 9, 8);
88 // Different fractional seconds are accepted
89 ParseValidateDate("2012-09-8 01:01:2", true, 2012, 9, 8);
90 ParseValidateDate("2012-09-8 01:01:2.9", true, 2012, 9, 8);
91 ParseValidateDate("2012-09-8 01:01:02.9", true, 2012, 9, 8);
92 ParseValidateDate("2012-09-8 01:01:2.999", true, 2012, 9, 8);
93 ParseValidateDate("2012-09-8 01:01:02.999", true, 2012, 9, 8);
94 ParseValidateDate("2012-09-8 01:01:2.999999999", true, 2012, 9, 8);
95 ParseValidateDate("2012-09-8 01:01:02.999999999", true, 2012, 9, 8);
96
97 // Bad formats: invalid date component.
98 for (const char* s: {"1990-10", "1991-10-32", "1990-10-", "10:11:12 1991-10-10",
99 "02011-01-01", "999-01-01", "2012-01-200", "2011-001-01"}) {
100 EXPECT_FALSE(DateValue::ParseSimpleDateFormat(s, strlen(s), false).IsValid()) << s;
101 }
102 // Bad formats: valid date and time components but time component is rejected.
103 for (const char* s: {"2012-01-20 10:11:12", "2012-1-2 10:11:12"}) {
104 EXPECT_FALSE(DateValue::ParseSimpleDateFormat(s, strlen(s), false).IsValid()) << s;
105 }
106 // Bad formats: valid date component, invalid time component.
107 for (const char* s: {"2012-01-20 10:11:", "2012-1-2 10::12", "2012-01-20 :11:12",
108 "2012-01-20 24:11:12", "2012-01-20 23:60:12"}) {
109 EXPECT_FALSE(DateValue::ParseSimpleDateFormat(s, strlen(s), true).IsValid()) << s;
110 }
111 // Bad formats: missing date component, valid time component.
112 for (const char* s: {"10:11:12", "1:11:12", "10:1:12", "10:1:2.999"}) {

Callers

nothing calls this directly

Calls 15

ParseValidateDateFunction · 0.85
DateTokenClass · 0.85
time_durationClass · 0.85
DateTCClass · 0.85
DateFormatTCClass · 0.85
maxFunction · 0.85
minFunction · 0.85
ToDaysSinceEpochMethod · 0.80
AddDaysMethod · 0.80
AddMonthsMethod · 0.80
AddYearsMethod · 0.80

Tested by

no test coverage detected