|
| 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.doris.util; |
| 19 | + |
| 20 | +import org.apache.seatunnel.api.table.catalog.Column; |
| 21 | +import org.apache.seatunnel.api.table.converter.BasicTypeDefine; |
| 22 | +import org.apache.seatunnel.api.table.converter.TypeConverter; |
| 23 | +import org.apache.seatunnel.api.table.type.BasicType; |
| 24 | +import org.apache.seatunnel.api.table.type.SeaTunnelDataType; |
| 25 | +import org.apache.seatunnel.connectors.doris.datatype.DorisTypeConverterFactory; |
| 26 | + |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 30 | +import static org.mockito.Mockito.mock; |
| 31 | +import static org.mockito.Mockito.when; |
| 32 | + |
| 33 | +public class DorisCatalogUtilTest { |
| 34 | + |
| 35 | + @Test |
| 36 | + void returnsReconvertedTypeWhenSinkTypeNotNull() { |
| 37 | + Column column = mock(Column.class); |
| 38 | + when(column.getName()).thenReturn("col1"); |
| 39 | + when(column.getSinkType()).thenReturn("VARCHAR"); |
| 40 | + |
| 41 | + String result = DorisCatalogUtil.columnToDorisType(column, mock(TypeConverter.class)); |
| 42 | + |
| 43 | + assertEquals("`col1` VARCHAR NOT NULL ", result); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + void returnsReconvertedTypeWhenSinkTypeIsNull() { |
| 48 | + Column column = mock(Column.class); |
| 49 | + when(column.getSinkType()).thenReturn(null); |
| 50 | + when(column.getDataType()).thenReturn((SeaTunnelDataType) BasicType.INT_TYPE); |
| 51 | + when(column.getName()).thenReturn("col1"); |
| 52 | + TypeConverter<BasicTypeDefine> typeConverter = |
| 53 | + DorisTypeConverterFactory.getTypeConverter("Doris version Doris-2.0.0"); |
| 54 | + String result = DorisCatalogUtil.columnToDorisType(column, typeConverter); |
| 55 | + |
| 56 | + assertEquals("`col1` INT NOT NULL ", result); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void returnsReconvertedTypeWhenTypesNotNull() { |
| 61 | + Column column = mock(Column.class); |
| 62 | + when(column.getSinkType()).thenReturn("VARCHAR"); |
| 63 | + when(column.getDataType()).thenReturn((SeaTunnelDataType) BasicType.INT_TYPE); |
| 64 | + when(column.getName()).thenReturn("col1"); |
| 65 | + when(column.isNullable()).thenReturn(false); |
| 66 | + TypeConverter<BasicTypeDefine> typeConverter = |
| 67 | + DorisTypeConverterFactory.getTypeConverter("Doris version Doris-2.0.0"); |
| 68 | + String result = DorisCatalogUtil.columnToDorisType(column, typeConverter); |
| 69 | + |
| 70 | + assertEquals("`col1` VARCHAR NOT NULL ", result); |
| 71 | + } |
| 72 | +} |
0 commit comments