|
1 | 1 | package scalar |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strconv" |
4 | 5 | "testing" |
5 | 6 | "time" |
6 | 7 |
|
@@ -69,26 +70,74 @@ func TestTimestampDoubleSet(t *testing.T) { |
69 | 70 | } |
70 | 71 |
|
71 | 72 | func TestAppendToBuilderTimestamp(t *testing.T) { |
72 | | - units := []arrow.TimeUnit{arrow.Second, arrow.Millisecond, arrow.Microsecond, arrow.Nanosecond} |
73 | | - expected := []string{"1999-01-08 04:05:06Z", "1999-01-08 04:05:06.123Z", "1999-01-08 04:05:06.123456Z", "1999-01-08 04:05:06.123456789Z"} |
74 | | - for i, unit := range units { |
75 | | - timestamp := Timestamp{ |
76 | | - Type: &arrow.TimestampType{ |
77 | | - Unit: unit, |
78 | | - TimeZone: "UTC", |
79 | | - }, |
80 | | - } |
81 | | - err := timestamp.Set("1999-01-08 04:05:06.123456789") |
82 | | - if err != nil { |
83 | | - t.Fatal(err) |
84 | | - } |
| 73 | + for idx, tc := range []struct { |
| 74 | + Unit arrow.TimeUnit |
| 75 | + Input string |
| 76 | + Expected string |
| 77 | + }{ |
| 78 | + // Input format: arrowStringFormat |
| 79 | + { |
| 80 | + Unit: arrow.Second, |
| 81 | + Input: "1999-01-08 04:05:06.123456789", |
| 82 | + Expected: "1999-01-08 04:05:06Z", |
| 83 | + }, |
| 84 | + { |
| 85 | + Unit: arrow.Millisecond, |
| 86 | + Input: "1999-01-08 04:05:06.123456789", |
| 87 | + Expected: "1999-01-08 04:05:06.123Z", |
| 88 | + }, |
| 89 | + { |
| 90 | + Unit: arrow.Microsecond, |
| 91 | + Input: "1999-01-08 04:05:06.123456789", |
| 92 | + Expected: "1999-01-08 04:05:06.123456Z", |
| 93 | + }, |
| 94 | + { |
| 95 | + Unit: arrow.Nanosecond, |
| 96 | + Input: "1999-01-08 04:05:06.123456789", |
| 97 | + Expected: "1999-01-08 04:05:06.123456789Z", |
| 98 | + }, |
| 99 | + // Input format: arrowStringFormatNew |
| 100 | + { |
| 101 | + Unit: arrow.Second, |
| 102 | + Input: "1999-01-08 04:05:06.123456789Z", |
| 103 | + Expected: "1999-01-08 04:05:06Z", |
| 104 | + }, |
| 105 | + { |
| 106 | + Unit: arrow.Millisecond, |
| 107 | + Input: "1999-01-08 04:05:06.123456789Z", |
| 108 | + Expected: "1999-01-08 04:05:06.123Z", |
| 109 | + }, |
| 110 | + { |
| 111 | + Unit: arrow.Microsecond, |
| 112 | + Input: "1999-01-08 04:05:06.123456789Z", |
| 113 | + Expected: "1999-01-08 04:05:06.123456Z", |
| 114 | + }, |
| 115 | + { |
| 116 | + Unit: arrow.Nanosecond, |
| 117 | + Input: "1999-01-08 04:05:06.123456789Z", |
| 118 | + Expected: "1999-01-08 04:05:06.123456789Z", |
| 119 | + }, |
| 120 | + } { |
| 121 | + tc := tc |
| 122 | + t.Run(strconv.FormatInt(int64(idx), 10), func(t *testing.T) { |
| 123 | + timestamp := Timestamp{ |
| 124 | + Type: &arrow.TimestampType{ |
| 125 | + Unit: tc.Unit, |
| 126 | + TimeZone: "UTC", |
| 127 | + }, |
| 128 | + } |
| 129 | + err := timestamp.Set(tc.Input) |
| 130 | + if err != nil { |
| 131 | + t.Fatal(err) |
| 132 | + } |
85 | 133 |
|
86 | | - bldr := array.NewTimestampBuilder(memory.DefaultAllocator, timestamp.Type) |
87 | | - AppendToBuilder(bldr, ×tamp) |
| 134 | + bldr := array.NewTimestampBuilder(memory.DefaultAllocator, timestamp.Type) |
| 135 | + AppendToBuilder(bldr, ×tamp) |
88 | 136 |
|
89 | | - arr := bldr.NewArray().(*array.Timestamp) |
90 | | - actual := arr.ValueStr(0) |
| 137 | + arr := bldr.NewArray().(*array.Timestamp) |
| 138 | + actual := arr.ValueStr(0) |
91 | 139 |
|
92 | | - require.Equal(t, expected[i], actual) |
| 140 | + require.Equal(t, tc.Expected, actual) |
| 141 | + }) |
93 | 142 | } |
94 | 143 | } |
0 commit comments