|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.seatunnel.connectors.seatunnel.starrocks.serialize; |
| 19 | + |
| 20 | +import org.apache.seatunnel.api.table.type.ArrayType; |
| 21 | +import org.apache.seatunnel.api.table.type.BasicType; |
| 22 | +import org.apache.seatunnel.api.table.type.MapType; |
| 23 | +import org.apache.seatunnel.api.table.type.SeaTunnelDataType; |
| 24 | +import org.apache.seatunnel.api.table.type.SeaTunnelRow; |
| 25 | +import org.apache.seatunnel.api.table.type.SeaTunnelRowType; |
| 26 | + |
| 27 | +import org.junit.jupiter.api.Assertions; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | + |
| 30 | +import java.util.Collections; |
| 31 | + |
| 32 | +public class StarRocksJsonSerializerTest { |
| 33 | + |
| 34 | + @Test |
| 35 | + public void serialize() { |
| 36 | + String[] filedNames = {"id", "name", "array", "map"}; |
| 37 | + SeaTunnelDataType<?>[] filedTypes = { |
| 38 | + BasicType.LONG_TYPE, |
| 39 | + BasicType.STRING_TYPE, |
| 40 | + ArrayType.STRING_ARRAY_TYPE, |
| 41 | + new MapType<>(BasicType.STRING_TYPE, BasicType.STRING_TYPE) |
| 42 | + }; |
| 43 | + |
| 44 | + SeaTunnelRowType seaTunnelRowType = new SeaTunnelRowType(filedNames, filedTypes); |
| 45 | + StarRocksJsonSerializer starRocksJsonSerializer = |
| 46 | + new StarRocksJsonSerializer(seaTunnelRowType, false); |
| 47 | + Object[] fields = { |
| 48 | + 1, "Tom", new String[] {"tag1", "tag2"}, Collections.singletonMap("key1", "value1") |
| 49 | + }; |
| 50 | + SeaTunnelRow seaTunnelRow = new SeaTunnelRow(fields); |
| 51 | + String jsonString = starRocksJsonSerializer.serialize(seaTunnelRow); |
| 52 | + Assertions.assertEquals( |
| 53 | + "{\"id\":1,\"name\":\"Tom\",\"array\":[\"tag1\",\"tag2\"],\"map\":{\"key1\":\"value1\"}}", |
| 54 | + jsonString); |
| 55 | + } |
| 56 | +} |
0 commit comments