|
21 | 21 | import org.apache.flink.api.common.typeinfo.TypeInformation; |
22 | 22 | import org.apache.flink.api.connector.sink2.Sink; |
23 | 23 | import org.apache.flink.cdc.common.configuration.Configuration; |
| 24 | +import org.apache.flink.cdc.common.data.LocalZonedTimestampData; |
24 | 25 | import org.apache.flink.cdc.common.data.binary.BinaryStringData; |
25 | 26 | import org.apache.flink.cdc.common.event.CreateTableEvent; |
26 | 27 | import org.apache.flink.cdc.common.event.DataChangeEvent; |
|
42 | 43 | import org.junit.BeforeClass; |
43 | 44 | import org.junit.Test; |
44 | 45 |
|
| 46 | +import java.time.Instant; |
45 | 47 | import java.util.Arrays; |
46 | 48 | import java.util.Collections; |
47 | 49 | import java.util.List; |
@@ -84,7 +86,11 @@ public void initializeDatabaseAndTable() { |
84 | 86 | DorisContainer.DORIS_DATABASE_NAME, |
85 | 87 | DorisContainer.DORIS_TABLE_NAME, |
86 | 88 | "id", |
87 | | - Arrays.asList("id INT NOT NULL", "number DOUBLE", "name VARCHAR(51)")); |
| 89 | + Arrays.asList( |
| 90 | + "id INT NOT NULL", |
| 91 | + "number DOUBLE", |
| 92 | + "name VARCHAR(51)", |
| 93 | + "birthday DATETIMEV2(6)")); |
88 | 94 |
|
89 | 95 | // waiting for table to be created |
90 | 96 | DORIS_CONTAINER.waitForLog( |
@@ -135,41 +141,76 @@ private List<Event> generateEvents(TableId tableId) { |
135 | 141 | .column(new PhysicalColumn("id", DataTypes.INT().notNull(), null)) |
136 | 142 | .column(new PhysicalColumn("number", DataTypes.DOUBLE(), null)) |
137 | 143 | .column(new PhysicalColumn("name", DataTypes.VARCHAR(17), null)) |
| 144 | + .column(new PhysicalColumn("birthday", DataTypes.TIMESTAMP_LTZ(6), null)) |
138 | 145 | .primaryKey("id") |
139 | 146 | .build(); |
140 | 147 | BinaryRecordDataGenerator generator = |
141 | 148 | new BinaryRecordDataGenerator( |
142 | | - RowType.of(DataTypes.INT(), DataTypes.DOUBLE(), DataTypes.VARCHAR(17))); |
| 149 | + RowType.of( |
| 150 | + DataTypes.INT(), |
| 151 | + DataTypes.DOUBLE(), |
| 152 | + DataTypes.VARCHAR(17), |
| 153 | + DataTypes.TIMESTAMP_LTZ(6))); |
143 | 154 |
|
144 | 155 | return Arrays.asList( |
145 | 156 | new CreateTableEvent(tableId, schema), |
146 | 157 | DataChangeEvent.insertEvent( |
147 | 158 | tableId, |
148 | 159 | generator.generate( |
149 | | - new Object[] {17, 3.14, BinaryStringData.fromString("Doris Day")})), |
| 160 | + new Object[] { |
| 161 | + 17, |
| 162 | + 3.14, |
| 163 | + BinaryStringData.fromString("Doris Day"), |
| 164 | + LocalZonedTimestampData.fromInstant( |
| 165 | + Instant.parse("2023-01-01T00:00:00.000Z")) |
| 166 | + })), |
150 | 167 | DataChangeEvent.insertEvent( |
151 | 168 | tableId, |
152 | 169 | generator.generate( |
153 | 170 | new Object[] { |
154 | | - 19, 2.718, BinaryStringData.fromString("Que Sera Sera") |
| 171 | + 19, |
| 172 | + 2.718, |
| 173 | + BinaryStringData.fromString("Que Sera Sera"), |
| 174 | + LocalZonedTimestampData.fromInstant( |
| 175 | + Instant.parse("2023-01-01T00:00:00.000Z")) |
155 | 176 | })), |
156 | 177 | DataChangeEvent.insertEvent( |
157 | 178 | tableId, |
158 | 179 | generator.generate( |
159 | 180 | new Object[] { |
160 | | - 21, 1.732, BinaryStringData.fromString("Disenchanted") |
| 181 | + 21, |
| 182 | + 1.732, |
| 183 | + BinaryStringData.fromString("Disenchanted"), |
| 184 | + LocalZonedTimestampData.fromInstant( |
| 185 | + Instant.parse("2023-01-01T00:00:00.000Z")) |
161 | 186 | })), |
162 | 187 | DataChangeEvent.updateEvent( |
163 | 188 | tableId, |
164 | 189 | generator.generate( |
165 | | - new Object[] {17, 3.14, BinaryStringData.fromString("Doris Day")}), |
| 190 | + new Object[] { |
| 191 | + 17, |
| 192 | + 3.14, |
| 193 | + BinaryStringData.fromString("Doris Day"), |
| 194 | + LocalZonedTimestampData.fromInstant( |
| 195 | + Instant.parse("2023-01-01T00:00:00.000Z")) |
| 196 | + }), |
166 | 197 | generator.generate( |
167 | | - new Object[] {17, 6.28, BinaryStringData.fromString("Doris Day")})), |
| 198 | + new Object[] { |
| 199 | + 17, |
| 200 | + 6.28, |
| 201 | + BinaryStringData.fromString("Doris Day"), |
| 202 | + LocalZonedTimestampData.fromInstant( |
| 203 | + Instant.parse("2023-01-01T00:00:00.000Z")) |
| 204 | + })), |
168 | 205 | DataChangeEvent.deleteEvent( |
169 | 206 | tableId, |
170 | 207 | generator.generate( |
171 | 208 | new Object[] { |
172 | | - 19, 2.718, BinaryStringData.fromString("Que Sera Sera") |
| 209 | + 19, |
| 210 | + 2.718, |
| 211 | + BinaryStringData.fromString("Que Sera Sera"), |
| 212 | + LocalZonedTimestampData.fromInstant( |
| 213 | + Instant.parse("2023-01-01T00:00:00.000Z")) |
173 | 214 | }))); |
174 | 215 | } |
175 | 216 |
|
@@ -201,9 +242,12 @@ private void runValuesToDorisJob(boolean batchMode) throws Exception { |
201 | 242 |
|
202 | 243 | env.execute("Values to Doris Sink"); |
203 | 244 |
|
204 | | - List<String> actual = fetchTableContent(tableId, 3); |
| 245 | + List<String> actual = fetchTableContent(tableId, 4); |
205 | 246 |
|
206 | | - List<String> expected = Arrays.asList("17 | 6.28 | Doris Day", "21 | 1.732 | Disenchanted"); |
| 247 | + List<String> expected = |
| 248 | + Arrays.asList( |
| 249 | + "17 | 6.28 | Doris Day | 2023-01-01 00:00:00", |
| 250 | + "21 | 1.732 | Disenchanted | 2023-01-01 00:00:00"); |
207 | 251 |
|
208 | 252 | assertEqualsInAnyOrder(expected, actual); |
209 | 253 | } |
|
0 commit comments