|
26 | 26 | import org.apache.flink.cdc.common.event.TableId; |
27 | 27 | import org.apache.flink.cdc.common.schema.Schema; |
28 | 28 | import org.apache.flink.cdc.common.types.BigIntType; |
| 29 | +import org.apache.flink.cdc.common.types.BinaryType; |
29 | 30 | import org.apache.flink.cdc.common.types.BooleanType; |
30 | 31 | import org.apache.flink.cdc.common.types.DataType; |
31 | 32 | import org.apache.flink.cdc.common.types.DataTypes; |
|
37 | 38 | import org.apache.flink.cdc.common.types.SmallIntType; |
38 | 39 | import org.apache.flink.cdc.common.types.TimestampType; |
39 | 40 | import org.apache.flink.cdc.common.types.TinyIntType; |
| 41 | +import org.apache.flink.cdc.common.types.VarBinaryType; |
40 | 42 | import org.apache.flink.cdc.common.types.VarCharType; |
41 | 43 | import org.apache.flink.cdc.common.types.ZonedTimestampType; |
42 | 44 | import org.apache.flink.cdc.runtime.typeutils.BinaryRecordDataGenerator; |
@@ -300,13 +302,36 @@ void testToStarRocksDataTypeAllBasicTypes() { |
300 | 302 | } |
301 | 303 |
|
302 | 304 | @Test |
303 | | - void testToStarRocksDataTypeUnsupported() { |
| 305 | + void testToStarRocksDataTypeBinary() { |
304 | 306 | StarRocksColumn.Builder builder = |
305 | 307 | new StarRocksColumn.Builder().setColumnName("col").setOrdinalPosition(0); |
306 | | - assertThatThrownBy( |
307 | | - () -> StarRocksUtils.toStarRocksDataType(DataTypes.BYTES(), false, builder)) |
308 | | - .isInstanceOf(UnsupportedOperationException.class) |
309 | | - .hasMessageContaining("Unsupported CDC data type"); |
| 308 | + StarRocksUtils.toStarRocksDataType(new BinaryType(17), false, builder); |
| 309 | + StarRocksColumn column = builder.build(); |
| 310 | + assertThat(column.getDataType()).isEqualTo(StarRocksUtils.VARBINARY); |
| 311 | + assertThat(column.getColumnSize()).hasValue(17); |
| 312 | + assertThat(column.isNullable()).isTrue(); |
| 313 | + } |
| 314 | + |
| 315 | + @Test |
| 316 | + void testToStarRocksDataTypeVarBinary() { |
| 317 | + StarRocksColumn.Builder builder = |
| 318 | + new StarRocksColumn.Builder().setColumnName("col").setOrdinalPosition(0); |
| 319 | + StarRocksUtils.toStarRocksDataType(new VarBinaryType(255), false, builder); |
| 320 | + StarRocksColumn column = builder.build(); |
| 321 | + assertThat(column.getDataType()).isEqualTo(StarRocksUtils.VARBINARY); |
| 322 | + assertThat(column.getColumnSize()).hasValue(255); |
| 323 | + assertThat(column.isNullable()).isTrue(); |
| 324 | + } |
| 325 | + |
| 326 | + @Test |
| 327 | + void testToStarRocksDataTypeBytes() { |
| 328 | + StarRocksColumn.Builder builder = |
| 329 | + new StarRocksColumn.Builder().setColumnName("col").setOrdinalPosition(0); |
| 330 | + StarRocksUtils.toStarRocksDataType(DataTypes.BYTES(), false, builder); |
| 331 | + StarRocksColumn column = builder.build(); |
| 332 | + assertThat(column.getDataType()).isEqualTo(StarRocksUtils.VARBINARY); |
| 333 | + assertThat(column.getColumnSize()).hasValue(StarRocksUtils.MAX_VARBINARY_SIZE); |
| 334 | + assertThat(column.isNullable()).isTrue(); |
310 | 335 | } |
311 | 336 |
|
312 | 337 | private void assertStarRocksDataType(DataType cdcType, String expectedStarRocksType) { |
@@ -418,12 +443,37 @@ void testCreateFieldGetterNullable() { |
418 | 443 | } |
419 | 444 |
|
420 | 445 | @Test |
421 | | - void testCreateFieldGetterUnsupportedType() { |
422 | | - assertThatThrownBy( |
423 | | - () -> |
424 | | - StarRocksUtils.createFieldGetter( |
425 | | - DataTypes.BYTES(), 0, ZoneId.of("UTC"))) |
426 | | - .isInstanceOf(UnsupportedOperationException.class) |
427 | | - .hasMessageContaining("Don't support data type"); |
| 446 | + void testCreateFieldGetterBinary() { |
| 447 | + RecordData.FieldGetter getter = |
| 448 | + StarRocksUtils.createFieldGetter(new BinaryType(10), 0, ZoneId.of("UTC")); |
| 449 | + |
| 450 | + BinaryRecordDataGenerator generator = |
| 451 | + new BinaryRecordDataGenerator(new DataType[] {new BinaryType(10)}); |
| 452 | + byte[] expected = new byte[] {1, 2, 3, 4, 5}; |
| 453 | + BinaryRecordData record = generator.generate(new Object[] {expected}); |
| 454 | + assertThat(getter.getFieldOrNull(record)).isEqualTo(expected); |
| 455 | + } |
| 456 | + |
| 457 | + @Test |
| 458 | + void testCreateFieldGetterVarBinary() { |
| 459 | + RecordData.FieldGetter getter = |
| 460 | + StarRocksUtils.createFieldGetter(new VarBinaryType(255), 0, ZoneId.of("UTC")); |
| 461 | + |
| 462 | + BinaryRecordDataGenerator generator = |
| 463 | + new BinaryRecordDataGenerator(new DataType[] {new VarBinaryType(255)}); |
| 464 | + byte[] expected = new byte[] {0x0A, 0x0B, 0x0C}; |
| 465 | + BinaryRecordData record = generator.generate(new Object[] {expected}); |
| 466 | + assertThat(getter.getFieldOrNull(record)).isEqualTo(expected); |
| 467 | + } |
| 468 | + |
| 469 | + @Test |
| 470 | + void testCreateFieldGetterBinaryNullable() { |
| 471 | + RecordData.FieldGetter getter = |
| 472 | + StarRocksUtils.createFieldGetter(DataTypes.BYTES(), 0, ZoneId.of("UTC")); |
| 473 | + |
| 474 | + BinaryRecordDataGenerator generator = |
| 475 | + new BinaryRecordDataGenerator(new DataType[] {DataTypes.BYTES()}); |
| 476 | + BinaryRecordData record = generator.generate(new Object[] {null}); |
| 477 | + assertThat(getter.getFieldOrNull(record)).isNull(); |
428 | 478 | } |
429 | 479 | } |
0 commit comments