|
19 | 19 |
|
20 | 20 | import org.apache.seatunnel.api.table.type.ArrayType;
|
21 | 21 | import org.apache.seatunnel.api.table.type.BasicType;
|
| 22 | +import org.apache.seatunnel.api.table.type.LocalTimeType; |
22 | 23 | import org.apache.seatunnel.api.table.type.MapType;
|
23 | 24 | import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
|
24 | 25 | import org.apache.seatunnel.api.table.type.SeaTunnelRow;
|
|
27 | 28 | import org.junit.jupiter.api.Assertions;
|
28 | 29 | import org.junit.jupiter.api.Test;
|
29 | 30 |
|
| 31 | +import java.time.LocalDateTime; |
| 32 | +import java.time.format.DateTimeFormatter; |
| 33 | +import java.time.format.DateTimeFormatterBuilder; |
| 34 | +import java.time.temporal.ChronoField; |
30 | 35 | import java.util.Collections;
|
31 | 36 |
|
32 | 37 | public class StarRocksJsonSerializerTest {
|
33 | 38 |
|
| 39 | + private DateTimeFormatter dateTimeFormatter = |
| 40 | + new DateTimeFormatterBuilder() |
| 41 | + .appendPattern("yyyy-MM-dd HH:mm:ss") |
| 42 | + .optionalStart() |
| 43 | + .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) |
| 44 | + .toFormatter(); |
| 45 | + |
34 | 46 | @Test
|
35 | 47 | public void serialize() {
|
36 |
| - String[] filedNames = {"id", "name", "array", "map"}; |
37 |
| - SeaTunnelDataType<?>[] filedTypes = { |
| 48 | + String[] fieldNames = {"id", "name", "array", "map", "timestamp"}; |
| 49 | + SeaTunnelDataType<?>[] fieldTypes = { |
38 | 50 | BasicType.LONG_TYPE,
|
39 | 51 | BasicType.STRING_TYPE,
|
40 | 52 | ArrayType.STRING_ARRAY_TYPE,
|
41 |
| - new MapType<>(BasicType.STRING_TYPE, BasicType.STRING_TYPE) |
| 53 | + new MapType<>(BasicType.STRING_TYPE, BasicType.STRING_TYPE), |
| 54 | + LocalTimeType.LOCAL_DATE_TIME_TYPE |
42 | 55 | };
|
43 | 56 |
|
44 |
| - SeaTunnelRowType seaTunnelRowType = new SeaTunnelRowType(filedNames, filedTypes); |
| 57 | + SeaTunnelRowType seaTunnelRowType = new SeaTunnelRowType(fieldNames, fieldTypes); |
45 | 58 | StarRocksJsonSerializer starRocksJsonSerializer =
|
46 | 59 | new StarRocksJsonSerializer(seaTunnelRowType, false);
|
47 | 60 | Object[] fields = {
|
48 |
| - 1, "Tom", new String[] {"tag1", "tag2"}, Collections.singletonMap("key1", "value1") |
| 61 | + 1, |
| 62 | + "Tom", |
| 63 | + new String[] {"tag1", "tag2"}, |
| 64 | + Collections.singletonMap("key1", "value1"), |
| 65 | + LocalDateTime.parse("2024-01-25 07:55:45.123", dateTimeFormatter) |
49 | 66 | };
|
50 | 67 | SeaTunnelRow seaTunnelRow = new SeaTunnelRow(fields);
|
51 | 68 | String jsonString = starRocksJsonSerializer.serialize(seaTunnelRow);
|
52 | 69 | Assertions.assertEquals(
|
53 |
| - "{\"id\":1,\"name\":\"Tom\",\"array\":[\"tag1\",\"tag2\"],\"map\":{\"key1\":\"value1\"}}", |
| 70 | + "{\"id\":1,\"name\":\"Tom\",\"array\":[\"tag1\",\"tag2\"],\"map\":{\"key1\":\"value1\"},\"timestamp\":\"2024-01-25 07:55:45.123\"}", |
54 | 71 | jsonString);
|
55 | 72 | }
|
56 | 73 | }
|
0 commit comments