From c5be1c9a06019ed9bd92a8939ba5a8e688c2137d Mon Sep 17 00:00:00 2001 From: wwang Date: Tue, 21 Nov 2023 14:52:24 +0800 Subject: [PATCH] fix(TCOMP-2565): support origin type pass for studio dynamic type --- .../sdk/component/runtime/di/record/DiRecordVisitor.java | 6 ++++++ .../component/runtime/di/record/DiRecordVisitorTest.java | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitor.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitor.java index f8bfa43caad55..03391dd99c61d 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitor.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitor.java @@ -22,6 +22,7 @@ import static java.util.stream.Collectors.toMap; import static org.talend.sdk.component.api.record.SchemaProperty.ALLOW_SPECIAL_NAME; import static org.talend.sdk.component.api.record.SchemaProperty.IS_KEY; +import static org.talend.sdk.component.api.record.SchemaProperty.ORIGIN_TYPE; import static org.talend.sdk.component.api.record.SchemaProperty.PATTERN; import static org.talend.sdk.component.api.record.SchemaProperty.SCALE; import static org.talend.sdk.component.api.record.SchemaProperty.SIZE; @@ -268,6 +269,11 @@ private DynamicMetadataWrapper generateMetadata(final Entry entry) { metadata.getDynamicMetadata().setKey(isKey); metadata.getDynamicMetadata().setType(studioType); + final String originType = entry.getProp(ORIGIN_TYPE); + if (originType != null && !originType.isEmpty()) { + metadata.getDynamicMetadata().setDbType(originType); + } + if (length != null) { metadata.getDynamicMetadata().setLength(length); } diff --git a/component-studio/component-runtime-di/src/test/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitorTest.java b/component-studio/component-runtime-di/src/test/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitorTest.java index 49014479090ef..5113bb82fb754 100644 --- a/component-studio/component-runtime-di/src/test/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitorTest.java +++ b/component-studio/component-runtime-di/src/test/java/org/talend/sdk/component/runtime/di/record/DiRecordVisitorTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.talend.sdk.component.api.record.SchemaProperty.ORIGIN_TYPE; import static org.talend.sdk.component.api.record.SchemaProperty.STUDIO_TYPE; import java.io.ObjectInputStream; @@ -27,9 +28,7 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; import java.sql.Timestamp; -import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.List; import org.junit.jupiter.api.Assertions; @@ -99,6 +98,7 @@ void visit() { .withName("dynBigDecimal") .withType(Type.STRING) .withProp(STUDIO_TYPE, StudioTypes.BIGDECIMAL) + .withProp(ORIGIN_TYPE, "DECIMAL") .build(), BIGDEC.toString()) .withDecimal(factory.newEntryBuilder() .withName("dynBigDecimal2") @@ -247,6 +247,8 @@ void visit() { assertTrue(byte[].class.isInstance(dynObject)); assertArrayEquals(String.valueOf(BYTES0).getBytes(), (byte[]) dynObject); + String originType = rowStruct.dynamic.getColumnMetadata(7).getDbType(); + assertEquals("DECIMAL", originType); dynObject = rowStruct.dynamic.getColumnValue("dynBigDecimal"); assertTrue(BigDecimal.class.isInstance(dynObject)); assertEquals(BIGDEC, dynObject);